Reputation:
how can I wrap a part of a content when I have elements and normal text? I've tried .after()
but this automaticaly adds a closing tag.
I have got this:
<div class="block">
<a href="#">example 1</a>
.
<a href="#">example 1</a>
.
<a href="#">example 1</a>
.
<a href="#">example 1</a>
</div>
And I have to transform it to:
<div class="block">
<a href="#">example 1</a>
<div class="wrap">
.
<a href="#">example 1</a>
.
<a href="#">example 1</a>
.
<a href="#">example 1</a>
</div>
</div>
Upvotes: 0
Views: 45
Reputation: 35478
The others answers are much clearer while this gives you some spesificity
var target = $($(".block a").slice(1)); // drop 1st
var container = $("<div class='wrap' />");
container.insertBefore($(target[0]));
target.each(function () {
$(this).appendTo(container);
});
Upvotes: 0
Reputation: 144709
$('.block').contents().filter(function(){
return $(this).index() > 0;
}).wrapAll('<div class="wrap"></div>');
Upvotes: 2