我有这个 html,我想将类应用到 DIV 的第一个按钮。
<div class="button-container">
<button class="save" />
<button class="reset" />
</div>
我想给第一个按钮添加类。
我想为这个解决方案使用 jQuery。
最佳答案
使用 :first-child选择器
$("div.button-container button:first-child" ).addClass ( "yourclass" );
关于javascript - 如何将类应用于 div 的第一个按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1754067/