HTML - how to empty a container?

  • 0
    how not to delete but empty the container using javaScript?
    let's say:

    <div class="container"></div>
    <button>Волшебная кнопка</button>


    click on the magic button and the text that was previously in the div is removed and a new one is added there
    P.S.
    not delete the div, but clear!
    without jQuery and .remove ();
    JavaScript Iris McLean, Dec 12, 2020

  • 3 Answers
  • 0
    document.querySelector('.container').innerHTML = '';
    Anonymous

  • 0
    const button = document.querySelector("button");
    const container = document.querySelector(".container");

    button.addEventListener("click", () => {
    container.innerHTML = "";
    });
    Nathaniel Poole

  • 0
    Document.querySelector ('. Container'). InnerHTML = '';
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!