简体   繁体   中英

jQuery CSS 'or' selector

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?

Try this

$(".class1,.class2")

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

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

put a comma within the same selector string.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM