Categories
JavaScript Answers

How to get the selected element type with JavaScript?

Spread the love

Sometimes, we want to get the selected element type with JavaScript.

In this article, we’ll look at how to get the selected element type with JavaScript.

How to get the selected element type with JavaScript?

To get the selected element type with JavaScript, we use the tagName property.

For instance, we write

const elementType = document.getElementById("born").tagName;

to get the element with getElementById.

Then we use the tagName property to get a string with the element type.

Conclusion

To get the selected element type with JavaScript, we use the tagName property.

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 *