This is my html.
<span id="current" class="green unselctable" data-original-title="" title="">
Lorem Ipsum is simply dummy
</span>
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():
$("#current").contents().unwrap();
contents()
will return all the children of #current
, including text nodes, and unwrap()
can be applied to text nodes.
var $current = $('#current');
$current.replaceWith($current.text());
Fiddle with the two current answers - pun?
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.
$("#current").replaceWith($("#current").contents());
©2020 All rights reserved.