Reputation: 1821
I want to move all the text(html content) after a div(which is again under a div) to another tag. For example, if i have a page like below, i want to move everything after div2 to body:
<body>
<div id=div1>
<div id=div2></div>
<div id=div3></div>
<script>blah</script>
and much more
</div>
</body>
to
<body>
<div id=div1>
<div id=div2></div>
</div>
<div id=div3></div>
<script>blah</script>
and much more
</body>
How can i do this? Using
$('#div').appendTo('body');
only moves that div.
Upvotes: 0
Views: 129
Reputation: 6235
As of my tries, response above isn't correct because it doesn't move the text nodes. Try this, hope it's what you are looking for:
var $div = $("#div2"), $con = $div.parent().contents();
$con.slice($con.index($div)+1).appendTo("body");
Upvotes: 0