如何选择具有唯一一个类名称的元素? [英] How to select elements with exact one class name?
本文介绍了如何选择具有唯一一个类名称的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有
<ul>
<li class="foo">
abc
</li>
<li class="foo bar">
def
</li>
</ul>
如果我$('.foo').css('font-size','x-large');
这将使用大字体更改两个li元素.我该如何选择仅包含"foo"而不包含"bar"的类?
this will change both li elements with the large font. How could I select the class with "foo" only but not "bar"?
谢谢!
推荐答案
我想您可以使用以下属性选择器:
You can use the following attribute selector, I suppose:
$('li[class=foo]');
这是一个 JSFiddle . )
这篇关于如何选择具有唯一一个类名称的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文