HTML - how to empty a container?
-
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 -
document.querySelector('.container').innerHTML = '';
Anonymous -
const button = document.querySelector("button");
const container = document.querySelector(".container");
button.addEventListener("click", () => {
container.innerHTML = "";
});Nathaniel Poole -
Document.querySelector ('. Container'). InnerHTML = '';Anonymous
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!