How can I delete content of div with jquery?
example of div id container
input:
<div id="container">
<h1>sdsdsdsd</h1>
dsdsdsdsds
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
dsfdfsd
</div>
output:
<div id="container">
</div>
Thanks
How can I delete content of div with jquery?
example of div id container
input:
<div id="container">
<h1>sdsdsdsd</h1>
dsdsdsdsds
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
dsfdfsd
</div>
output:
<div id="container">
</div>
Thanks
Share Improve this question asked Jul 9, 2010 at 11:15 BenBen 25.8k35 gold badges113 silver badges166 bronze badges2 Answers
Reset to default 6Use .empty()
, like this:
$("#container").empty();
You can give it a test here, it's important to use .empty()
or .remove()
when you have events/data bound to any descendants inside what you're clearing...otherwise you're leaking memory that won't be cleaned up.
$("#container").empty()
http://api.jquery./empty/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745209409a4616747.html
评论列表(0条)