I have a comma separated list of links like this:
<a href="#">link</a>,
<a href="#">link</a>,
<a href="#">link</a>,
<a href="#">link</a>,
<a href="#">link</a>,
<a href="#">link</a>
<div></div>
Now I would like to wrap the links from position 3 to the last so that it looks like:
$("a").eq(1).nextUntil("div").wrapAll('<span>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#">link</a>,
<a href="#">link</a>,
<span>
<a href="#">link</a>,
<a href="#">link</a>,
<a href="#">link</a>,
<a href="#">link</a>
</span>
<div></div>
I tried it like this:
<a href="#">link</a>,
<a href="#">link</a>,
<span>
<a href="#">link</a>,
<a href="#">link</a>,
<a href="#">link</a>,
<a href="#">link</a>
</span>
<div></div>
However, this does not wrap the commas and the result looks as follows:
<a href="#">link</a>,
<a href="#">link</a>,
<span>
<a href="#">link</a>
<a href="#">link</a>
<a href="#">link</a>
<a href="#">link</a>
</span> ,,,
<div></div>
How can I include the commas in the nesting?
wrapAllwraps the anchors, but the commas are not inside the anchors so they get pushed outside the span. I'll have a think and then come back and find someone has answered it for you :p