开发者

Jquery :: How can I delete content of div <div>...<li>sdsds</li>.../div>?

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


Use .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.com/empty/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜