Categories
JavaScript Answers

How to clear all div’s contents inside a parent div with JavaScript?

Spread the love

To clear all div’s contents inside a parent div with JavaScript, we set innerHTML to an empty string.

For instance, we write

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

to select the outer div with getElementById.

And then we set its innerHTML property to an empty string to clear its contents.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *