jQuery nth with DIV
jQuery nth with DIV
在Business Catalyst中,我有一个输出无序列表的div。我需要在每4个项目之后列出一个单独的非无序项目。硬编码版本如下所示:
<div class="article-list">
<ul class="article-list grid">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
<div class="sponsored-post">
<ul class="sponsored-post grid">
<li>Hardcoded Item 1</li>
<li>Hardcoded Item 2</li>
</ul>
</div>
<div class="article-list">
<ul class="article-list grid">
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
</ul>
</div>
使用jQuery .each()
并跟踪循环中的变量。如果该计数器能被4整除,则在<li>
$(".article-list").each(function(i, value) {
if(i % 4 == 0) {
newDiv = $("<div></div>").html("new div");
$(this).append(newDiv);
}
});
相关文章:
- Fighting with FRP
- 添加文字和评论功能更新Div
- issue with FB.Event.subscribe
- 点击后隐藏潜水?(但如果Div是一面旗帜呢?)
- Trouble overlaying one div with another with JavaScript &
- TinyMCE/IE9/DIV with Width/Height/ContentEditable/如何阻止DIV选择
- Save in MYSQL the value of a div with HTML5 Drag &Drop
- Toggle Class of Div with <img> click
- JQuery appendTo Div with ID instead of appendTo('body
- Reusing <div> with jQuery
- Window.Print() Div with Overflow-x?
- Div height with child margin
- Select Menu onChange DIV element with Javascript
- Change DIV id with javascript
- Summary of form in a <div> with jQuery
- jQuery nth with DIV
- Expand div with "display: table-cell" on click?
- <a> with :hover or <div> with hover event for bu
- Div to image with jQuery/JavaScript
- Div with contenteditable=“true” - 在 DOMSubtreeModified event