How one can add li to middle of the ul.
For example if i have list like this:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
And i want to add addiion li (<li>new</li>
) after 3rd list?
How one can add li to middle of the ul.
For example if i have list like this:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
And i want to add addiion li (<li>new</li>
) after 3rd list?
Try this out:
$('ul li:nth-child(3)').after('<li>new</li>');
var middle = Math.ceil($("#myUL li").length / 2);
$("#myUL li:nth-child(" + middle + ")").after($("<li>Item New</li>"));