如何选择具有唯一一个类名称的元素?
问题描述:
所以我有
<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 . )