Hi Zoe,

One way to do this is use .appendBefore() to move the children up one level
in the DOM before the element you want to remove & then do the .remove()

------------------
<style type="text/css">
#parent { background-color: red; }
</style>

<a href="javascript:void(0);" onClick="removeParent();">Remove div
id=parent</a>
<br /><br />
<div id="wrapper">
This is the wrapper element
<div id="parent">
 <ul><li>Item 1</li><li>Item 2</li></ul>
</div>
 <span>Another Child</span>
</div>

<script type="text/javascript" language="javascript">
 function removeParent(){
$('#parent').children().insertBefore('#parent');
 $('#parent').remove();

/* or the one line alternative:
 $('#parent').children().insertBefore('#parent').end().end().remove();
*/
 }
</script>

Cheers,
Gus


On Thu, Jan 14, 2010 at 10:29 PM, MonkeyGirl <z...@monkeehouse.com> wrote:

> Hi!
>
> Is there a way to remove an element from the DOM, like with remove(),
> but to keep its children?  Alternatively, is there a way to move an
> element one branch up the tree, so when I remove what used to be its
> parent, it'll take its place?
>
> Thank you,
> Zoe.
>

Reply via email to