tags:

views:

4857

answers:

3

I have a div, and I want to remove all the HTML inside of that div.

How can I do this?

+19  A: 

You want to use the empty function:

$('#mydiv').empty();
Paolo Bergantino
A: 

Another way is just to set the html to the empty string:

$('#mydiv').html('');

karim79
+5  A: 

I don't think empty() or html() is what you are looking for. I guess you're looking for something like strip_tags in PHP. If you want to do this, than you need to add this function:

jQuery.fn.stripTags = function() { return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') ); };

Suppose this is your HTML:

<div id='foo'>This is <b>bold</b> and this is <i>italic</i>.</div>

And then you do:

$("#foo").stripTags();

Which will result in:

<div id='foo'>This is bold and this is italic.</div>

bart
I think he meant removing all content. Still +1 for good answer for future generations.
Pekka
Personally I would just do $("#foo").html($("#foo").text());
Killroy