Languages
[Edit]
EN

JavaScript - replace all children of HTML element

0 points
Created by:
Aisha
418

In this article, we would like to show you how to replace all children of an HTML element using JavaScript.

Quick solution:

 

Practical example

Edit

In this example, we set the container element innerHTML to an empty string ('') to remove all its children, and then we add new ones using append() method.

References

Edit
  1. Element.append() - Web APIs | MDN
  2. Element.innerHTML - Web APIs | MDN
  3. Node.textContent - Web APIs | MDN
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join