Sometimes, we want to get all elements in the body tag using pure JavaScript.
In this article, we’ll look at how to get all elements in the body tag using pure JavaScript.
How to get all elements in the body tag using pure JavaScript?
To get all elements in the body tag using pure JavaScript, we use the getElementsByTagName method.
For instance, we write
const elems = document.body.getElementsByTagName("*");
to call the getElementsByTagName method on the body element with '*' to get all the elements in the body element.
Conclusion
To get all elements in the body tag using pure JavaScript, we use the getElementsByTagName method.