I have simple list:
<ul>
<li>some text 1 </li>
<li>some text 2</li>
<li>some text 3</li>
<li>some text 4</li>
<li>some text 5</li>
<li>some text 6</li>
<li>some text 7</li>
</ul>
I need add after each 4n element some div
I have:
$("ul li:nth-child(4n)").after("<div style='color:black'>test</div>");
But for example I have 4 elements and my div after it, and than I have only 3 element, but I need append my div after third element…How to make this?
Thank you!
You could use
.add()to add to the jQuery resultset the lastli,if it is not matched by thenth-childrule..Demo at http://jsfiddle.net/gaby/a8vAU/