eastboundr
eastboundr

Reputation: 1877

How to select elements with exact one class name?

so I have,

<ul>

<li class="foo">
abc
</li>

<li class="foo bar">
def
</li>

</ul>

If I do $('.foo').css('font-size','x-large');

this will change both li elements with the large font. How could I select the class with "foo" only but not "bar"?

Thanks!

Upvotes: 1

Views: 2115

Answers (2)

Paul Dessert
Paul Dessert

Reputation: 6389

This should work:

$('.foo:first').css('font-size','x-large');

Upvotes: 0

raina77ow
raina77ow

Reputation: 106483

You can use the following attribute selector, I suppose:

$('li[class=foo]');

Here's a JSFiddle to play with. )

Upvotes: 5

Related Questions