javascript - 如何通过索引号突破 .each()

标签 javascript jquery

我想将列表中的每三个项目分开并为那个 child 添加一个类(class);

<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li><!--target list item-->
    <li>4</li>
    <li>5</li>
    <li>6</li><!--target list item-->
    <li>7</li>
</ul>

有什么想法吗?

最佳答案

你应该使用第 nth-child 伪选择器

$("ul li:nth-child(3n)").addClass("break-here");

关于javascript - 如何通过索引号突破 .each(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10154647/

相关文章:

javascript - Meteor.methods 与标准 JS 函数调用

javascript - 将特定的 csv 文件读入 html

jquery - 使用 Jquery 创建数组

javascript - 使用 JWT 身份验证进行 WordPress Rest API 并获取 [jwt_auth] ip_blocked”

jquery - 用图像模糊 div

javascript - jQuery 定位与 CSS3 "transform: scale"

javascript - javascript/jQuery 中的 Ajax ComboBox 更改事件

javascript - setInterval 一次后停止

javascript - 我如何更改 highcharts highstock 中输入的位置?

php - 无法从 JavaScript 获取文本字段值