Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我有,
<ul> <li class="foo"> abc </li> <li class="foo bar"> def </li> </ul>
如果我做$('.foo').css('font-size','x-large');
$('.foo').css('font-size','x-large');
这将使用大字体更改两个 li 元素。我怎样才能选择只有“foo”而不是“bar”的类?
谢谢!
我想您可以使用以下属性选择器:
$('li[class=foo]');
这是一个可以玩的JSFiddle 。)
这应该有效:
$('.foo:first').css('font-size','x-large');