Alex Rivera | Logout

jQuery hasClass() - check for more than one class

Asked 2010-02-06T22:15:34.533
191

With:

if(element.hasClass("class"))

I can check for one class, but is there an easy way to check whether "element" has any of many classes?

I am using:

if(element.hasClass("class") || element.hasClass("class") ... )

Which isn't too bad, but I am thinking of something like:

if(element.hasClass("class", "class2")

Which unfortunately doesn't work.

Is there something like that?

Edit
Report

1 Answer

-1

This worked for me:

$('.class1[class~="class2"]').append('something');
answered 2013-07-29T12:38:47.070

Your Answer