2009-11-18 66 views
0

我有這個html,我想將類應用於DIV的第一個按鈕。如何將類應用於div的第一個按鈕?

<div class="button-container"> 
<button class="save" /> 
<button class="reset" /> 
</div> 

我想將類添加到第一個按鈕。

我想爲此解決方案使用jQuery。

+0

你想要一個適用於div中第一個按鈕的CSS樣式嗎?然後SleighBoy有答案。 – andho 2009-11-18 08:31:42

回答

4

使用:first-child選擇

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

您可以像這樣添加第二個類。

<div class="button-container"> 
<button class="save SecondClass" /> 
<button class="reset" /> 
</div> 
+0

哈哈,它很簡單,沒有jQuery :) +1 – 2009-11-18 07:03:50

+0

我希望它是動態的。 – 2009-11-30 08:15:55

相關問題