如何在 jQuery 中选择具有多个类的元素?

I want to select all the elements that have the two classes a and b.

<element class="a b">

So, only the elements that have both classes.

When I use $(".a, .b") it gives me the union, but I want the intersection.

转载于:https://stackoverflow.com/questions/1041344/how-can-i-select-an-element-with-multiple-classes-in-jquery

csdnceshi76
斗士狗 I think you mean that of the two sets "women" and "French-speakers", the union would be all the women in the world and all the French-speakers in the world, a set that includes both women who don't speak French and French-speaking men. The intersection is, as you wrote, only those women who speak French.
大约 4 年之前 回复
csdnceshi65
larry*wei union and intersection are basic set theory concepts. So for instance a union would be all French speakers (includes both men and women), whereas an intersection would be all women who speak French (excludes everyone who does not speak French, and excludes all people who are not women). Unions and intersections can be made with any number of characteristics defining each set. en.wikipedia.org/wiki/Union_(set_theory) en.wikipedia.org/wiki/Intersection_(set_theory)
4 年多之前 回复
weixin_41568110
七度&光 It would be nice if you could define what union and intersection means for us newbs :)
4 年多之前 回复

11个回答

You do not need jQuery for this

In Vanilla you can do :

document.querySelectorAll('.a.b')
共11条数据 首页 2
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问