views:

45

answers:

2

Hello,

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?

+5  A: 

Try this

$(".class1,.class2")

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

Nikita Rybak
Works great, thanks!
Erin Drummond
As a note, it isn't an `OR` or anything, just creates a union of elements matched.
alex
+1  A: 
$(".class1,.class2").each(function(idx, el) {... });

put a comma within the same selector string.

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

lukemh