Search code examples
javascripthtml

How to empty the content of a div


Does someone know how to empty the content of a div (without destroying it) in JavaScript?


Solution

  • If your div looks like this:

    <div id="MyDiv">content in here</div>
    

    Then this Javascript:

    document.getElementById("MyDiv").innerHTML = "";
    

    will make it look like this:

    <div id="MyDiv"></div>