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.
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.
You can add a second class like this.
<div class="button-container">
<button class="save SecondClass" />
<button class="reset" />
</div>
Use the :first-child selector
$("div.button-container button:first-child" ).addClass ( "yourclass" );
You could look at this: http://docs.jquery.com/Selectors/firstChild
$('div button:first-child').addClass(...)
div.button-container > button:first-child { font-weight: bold; }