I have a div and I want to remove all the HTML inside of that div.
How can I do this?
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:
This is bold and this is italic.
And then you do:
$("#foo").stripTags();
Which will result in:
This is bold and this is italic.