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.
The unwrap() method is an inbuilt method in jQuery which is used to remove the parent element from the selected element. Parameters: This method does not accept any parameter. Return Value: This method returns the selected element with the changes made by unwrap() method.
unwrap() method removes the element's parent and returns the unwrapped content. This is effectively the inverse of the . wrap() method. The matched elements (and their siblings, if any) replace their parents within the DOM structure.
createElement() to create an element, and wrap it around each selected element. Wrap elements using a function. Using a function to specify what to wrap around each selected element. Wrap and unwrap an element. How to toggle between wrapping and unwrapping an element.
The unwrap() method removes the parent element of the selected elements.
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.
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