Unwrap selected element Javascript or Jquery

This is my html.

<span id="current" class="green unselctable" data-original-title="" title="">
    Lorem Ipsum is simply dummy

I'm selecting with with $("#current") but if I use the jQuery unwrap function the parent tag gets removed.

Is there any way to remove the span in JavaScript or jQuery without parsing the string and appending it to the dom?

Edit I wanna keep the content of the div. I just want the tag removed.



You can chain contents() into unwrap():


contents() will return all the children of #current, including text nodes, and unwrap() can be applied to text nodes.

var $current = $('#current');

Fiddle with the two current answers - pun?

unwrap vs replaceWith


Just hit this same question. I think this might be marginally better...same effect but I think jQuery has to do less magic to make this work.



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.