Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Question about jQuery .hasClass() Reply To: Question about jQuery .hasClass()

#151659
TheDoc
Member

Really difficult to say without fully knowing what the code is trying to accomplish.

For starters, I’d be storing $(this) as a variable just inside the click function like this:

var button = $(this);

…and then going:

button.hasClass('whatever')

Depending on what you’re trying to do you might want to look into using a switch: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch