Categories
JavaScript Answers

How to get all elements in the body tag using pure JavaScript?

Spread the love

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.

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 *