I have below ul list. In which I want to wrap last three li into another ul li tag.
My html
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
I want
<ul>
<li>1</li>
<li>
<ul>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</li>
</ul>
my code
$('ul li:not(:first)').wrap('<li></li>');
But it's wraping individual li into another li. pls help
All you need here in this context is .wrapAll()
Try,
$('ul li:not(:first)').wrapAll('<li><ul></ul></li>');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With