Preston
Preston

Reputation: 1346

jQuery hasClass not behaving

Why is this always returning false when it shouldn't be? How do I get it to behave?

var originalDiv = $(clickedButton).parent();    
alert($(originalDiv).hasClass('.question_box_expanded'));

Upvotes: 0

Views: 61

Answers (1)

alex
alex

Reputation: 490263

Remove the . before your class name. That's used for selectors only.

In order to debug this yourself, set a break point on that line. Then, step into the jQuery calls and look at what is happening. Somewhere along the way, it'd become obvious that the . was causing the issue.

Upvotes: 4

Related Questions