I've tried both of the following but none of them worked:
$('#divhtml').remove('span')
$('#divhtml').find('span').remove()
EDIT: $('#divhtml').find('span').remove()
worked on 2nd try.
Inline text styles are often set by using the span tags. Activating this option will remove all span tags including their styles, classes etc.
To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements) empty() - Removes the child elements from the selected element.
jQuery remove() Method The remove() method removes the selected elements, including all text and child nodes. This method also removes data and events of the selected elements. Tip: To remove the elements without removing data and events, use the detach() method instead.
Given an HTML element and the task is to add and remove multiple classes from it using JQuery. Approach: First select the element to which multiple classes will be added. Then use addClass() method to add multiple classes to the element and removeClass() method to remove multiple classes.
You have already used a correct statement:
$('#divhtml').find('span').remove()
This should work. Please provide more context... See this jsfiddle as "proof" that something else is wrong: http://jsfiddle.net/Pbgqy/
Try this:
$("#divhtml span").remove()
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