sephiith sephiith - 26 days ago 11
Javascript Question

How to remove a div's content with jQuery

How would I go about removing the content inside a div tag with the class

content
.

<div class="content"></div>


I would imagine it would be something like:

$(.content).remove


Separately, how would I go about adding a string of text inside that same
div
?

PSL PSL
Answer

Use .empty() to remove the contents in the Div tag.

$('.content').empty();

For your second question; you can add the any text or content using $('.content').html(newcontent) or

$('.content').text(newcontentText); //specifically for text content.
Comments