views:

59

answers:

2

Hi,

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

+5  A: 
$("#container").empty()

http://api.jquery.com/empty/

Adrian Godong
+4  A: 

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.

Nick Craver
...because attached `event handlers` and jQuery `.data()` hash entrys are not removed... :)
jAndy