views:

87

answers:

4

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.

+4  A: 

You can add a second class like this.

<div class="button-container">
 <button class="save SecondClass" />
 <button class="reset" />
</div>
Mitchel Sellers
lol, it was so simple, without jQuery :) +1
Rakesh Juyal
I want it to be dynamic.
Wazdesign
+4  A: 

Use the :first-child selector

$("div.button-container button:first-child" ).addClass ( "yourclass" );
rahul
+4  A: 

You could look at this: http://docs.jquery.com/Selectors/firstChild

$('div button:first-child').addClass(...)

James Black
+3  A: 
div.button-container > button:first-child { font-weight: bold; }

Source: http://www.w3.org/TR/CSS2/selector.html#first-child

SleighBoy