Reputation: 7030
I have this html and I want to apply class to first button of the DIV.
<div class="button-container">
<button class="save" />
<button class="reset" />
</div>
I want to add class to the first button.
I want to use jQuery for this solution.
Upvotes: 1
Views: 14283
Reputation: 41858
You could look at this: http://docs.jquery.com/Selectors/firstChild
$('div button:first-child').addClass(...)
Upvotes: 5
Reputation: 501
div.button-container > button:first-child { font-weight: bold; }
Source: http://www.w3.org/TR/CSS2/selector.html#first-child
Upvotes: 5
Reputation: 187110
Use the :first-child selector
$("div.button-container button:first-child" ).addClass ( "yourclass" );
Upvotes: 7
Reputation: 63136
You can add a second class like this.
<div class="button-container">
<button class="save SecondClass" />
<button class="reset" />
</div>
Upvotes: 4