Alex Rivera | Logout

jQuery CSS 'or' selector

Asked 2010-08-10T02:29:49.190
28

I am trying to select elements of a (certain class || another class) with the same selector. How can I go about doing that?

Currently, I have:

$(".class1 .class2").each(function(idx, el) {... });

however, that only selects elements that match both classes, not one or the other.

How can I select elements that match one or both of the classes, with the same selector?

Edit
Report

1 Answer

46

Try this

$(".class1,.class2")

http://api.jquery.com/multiple-selector/

answered 2010-08-10T02:31:46.610

Your Answer