我有這個html,我想將類應用於DIV的第一個按鈕。如何將類應用於div的第一個按鈕?
<div class="button-container">
<button class="save" />
<button class="reset" />
</div>
我想將類添加到第一個按鈕。
我想爲此解決方案使用jQuery。
我有這個html,我想將類應用於DIV的第一個按鈕。如何將類應用於div的第一個按鈕?
<div class="button-container">
<button class="save" />
<button class="reset" />
</div>
我想將類添加到第一個按鈕。
我想爲此解決方案使用jQuery。
使用:first-child選擇
$("div.button-container button:first-child").addClass ("yourclass");
您可以像這樣添加第二個類。
<div class="button-container">
<button class="save SecondClass" />
<button class="reset" />
</div>
哈哈,它很簡單,沒有jQuery :) +1 – 2009-11-18 07:03:50
我希望它是動態的。 – 2009-11-30 08:15:55
你可以看看這個: http://docs.jquery.com/Selectors/firstChild
$('div button:first-child').addClass(...)
div.button-container > button:first-child { font-weight: bold; }
你想要一個適用於div中第一個按鈕的CSS樣式嗎?然後SleighBoy有答案。 – andho 2009-11-18 08:31:42