I have the following html
<div class="foobar">
<div> child 1 </div>
<div> child 2 </div>
<ul>
<li> list elem 1 </li>
<li> list elem 2 </li>
<li> list elem 3 </li>
</ul>
</div>
When I try the following jquery the list is removed as expected:
$(".foobar ul").remove();
However when I try this, it does not seem to work:
$(".foobar").remove("ul");
Just trying to understand….
The remove method does not remove the elements inside that match the selector, it removes the elements in the group that match the selector.
For example, this will remove the first and the third div:
JavaScript:
Actually, having the selector inside the remove is pretty much useless, because you can also do:
And the same thing will happen.