jQuery匹配多个类 [英] jQuery matching multiple classes
问题描述
我第一次遇到这种不正常的情况
For the first time, I got in this kind of unusual situtation
我必须选择一个应用了2个以上类的div,并以随机顺序进行
I have to select a div on which more than 2 classes are applied, that to in random order
例如:
假设我有一个< div>在其上应用以下3个类 内容文本,右对齐和粗体字体.我需要选择该div,但问题是类在不同页面上的应用顺序不同
Assume that I have a <div> on which following 3 classes are applied content-text, right-align and bold-font. I need to select this div, but problem is that classes are applied in different order on different pages
<div class="content-text right-align bold-font">...</div>
<div class="right-align content-text bold-font">...</div>
<div class="content-text bold-font right-align ">...</div>
...
无论如何应用类,如何选择该特定的div?
How can I select this particular div, no matter how classes are applied?
谢谢
推荐答案
这将正常工作. CSS选择器通常并不关心类的顺序,而只关心所应用的类. jQuery也是如此:
This will work fine. CSS selectors in general don't care about the order of classes, just the ones that are applied. This also goes for jQuery:
$('div.content-text.right-align.bold-font');
这篇关于jQuery匹配多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!