javascript - 如何将类应用于 div 的第一个按钮?

标签 javascript jquery html css

我有这个 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/

相关文章:

php - 如何在 prestashop 的产品页面上显示自定义表格字段

javascript - 防止动态创建的 onclick 事件过早触发

javascript - 谷歌街景位置

javascript - 谷歌图表 - "this.ug is not a function"

javascript - 如何根据文档执行与 vuejs 插槽通常执行的操作相反的操作?

jquery - 简单的 jQuery nth-child 查询 - 动画不起作用

javascript - 如何使用时间日期条件向 WordPress 的 body 元素添加类?

javascript - 过滤/删除 View 中的数据而不刷新页面

Jquery & KendoUI 下拉列表动态创建

html - 通过 html 设置 css 值?