开发者

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

开发者 https://www.devze.com 2023-01-07 00:45 出处:网络
How can I delete开发者_开发知识库 content of div with jquery? example of div id container input:

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

精彩评论

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