How can I remove everything inside of a <div>
I have the following:
<div id="test开发者_Python百科">
...
...
</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?
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.
$("#test").empty()
should do the trick.
jsFiddle here
http://jsfiddle.net/53ZRw/
this should do it.
$('#test').html('');
if you want to completly remove you can use
.remove();
should this is works too
$('#test > div ').text('');
精彩评论