Reputation: 497
I have the following:
<div id="test">
...
...
</div>
I would like to remove all of the elements within the div so I tried:
$('#test > div').remove();
But this doesn't seem to work. Am I doing the right thing here?
Upvotes: 6
Views: 22254
Reputation: 54032
try with right syntax
Remove : Remove the set of matched elements from the DOM.
$('div#test').remove();
try with empty
empty : Remove all child nodes of the set of matched elements from the DOM.
$('#test').empty();
see html() also, sometime it is helpful
html: When .html() is used to set an element's content, any content that was in that element is completely replaced by the new content.
Note: To remove the elements without removing data and events, use .detach() instead.
Upvotes: 17
Reputation: 15835
jsFiddle here
this should do it.
$('#test').html('');
if you want to completly remove you can use
.remove();
Upvotes: 2