tags:

views:

426

answers:

1

Hi,

With if(element.hasClass("class")) {//do stuff} i can check for one class. Is there an eays way to check wether "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? Thanks.

+11  A: 

How about:

element.is('.class1, .class2')
Matchu
No, because that would look for elements that have both classes. I think Marcel is looking for elements with one or more of a number of classes.
Giles Van Gruisen
Ahhh, right. Editing time!
Matchu
Edited to be an OR system :)
Matchu
Nice, nice :) .
BalusC
Works for meeeee: http://jsbin.com/uqoku/edit
Matchu
Worked for me too...
Felix Kling
Just now noticed that I have 4 id="hello" elements there. Fixed version in order to make validators happy: http://jsbin.com/uqoku/2/edit
Matchu
@Marcel: provide an SSCCE. http://sscce.org
BalusC
I'm guessing that, since Marcel accepted the answer, the issue has been resolved.
Matchu
yes thx alot Matchu ;)
Marcel