This project is archived and is in readonly mode.

#1104 ✓invalid
Tyrone

Incorrect evaluation of return value for Element.hasClass

Reported by Tyrone | November 30th, 2010 @ 10:10 AM

While in the process of developing an application which relies heavily on the Mootools Javascript library, I came across some strangeness. It appeared that the the Element.hasClass() function was returning a value other than a bool.

Example:

has_class = item.hasClass(this.options.selected_item);
if(has_class){ ... }
else { ... }

What happens is the item.hasClass() returns false, however it evaluates to true inside the if statement. Very weird.

A quick work-around was to just test for the class

hasClass = String.from(item.get('class')).test(this.options.selected_class, 'i');
if(has_class){ ... }
else { ... }

This evaluates the return value correctly.

Note: when attempting to verify this problem in jsfiddle, it seems that the first example works perfectly as:

has_class = item.hasClass('some_class');
if(has_class){ ... }
else { ... }

But, when using the class that I wrote, it fails. So it may be something to do with the class I wrote, and my lack of experience with mootools :)

Succeeds: http://www.jsfiddle.net/tyronetudehope/M5HTM/
Fails: http://www.jsfiddle.net/tyronetudehope/Q5Xad/3/

Thanks,
T.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages