Description: Remove all child nodes of the set of matched elements from the DOM.
This method removes not only child (and other descendant) elements, but also any text within the set of matched elements. This is because, according to the DOM specification, any string of text within an element is considered a child node of that element. Consider the following HTML:
<div class="container"> <div class="hello">Hello</div> <div class="goodbye">Goodbye</div> </div>
We can target any element for removal:
This will result in a DOM structure with the
Hello text deleted:
<div class="container"> <div class="hello"></div> <div class="goodbye">Goodbye</div> </div>
If we had any number of nested elements inside
<div class="hello">, they would be removed, too. Other jQuery constructs such as data or event handlers are erased as well.