I have one wrapper div with several sub-divs inside and tags inside those sub-divs as well. I want to remove the wrapper div. I have considered JQuery's unwrap, but it appears as though I need to specify the child divs to tell Jquery what to unwrap. Will this work if there are several children?
So, the code looks like:
<div id="wrapper">
<div id="innerDiv1"></div>
<div id="innerDiv2"></div>
<div id="innerDiv3"></div>
</div>
Any help, as always, is appreciated.
Thank you.
The unwrap
method will work fine (you can select any of/any number of the siblings):
$("#innerDiv1").unwrap();
From the docs (emphasis added):
The matched elements (and their siblings, if any) replace their parents within the DOM structure.
To add on to @james
You can do something like this
var innerDivs = $("#wrapper").html();
$("#wrapper").remove();
$("body").append(innerDivs); // you will need to change this to append to whatever element you like
jsfiddle example
http://jsfiddle.net/dAZ9D/
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