Sometimes, we want to find the type of an input element with JavaScript.
In this article, we’ll look at how to find the type of an input element with JavaScript.
How to find the type of an input element with JavaScript?
To find the type of an input element with JavaScript, we use the type
property.
For instance, we write
<input type="text" />
to add an input.
Then we get the type
attribute of the input with
const type = document.querySelector("input").type;
We select the input with querySelector
.
And we get the type
attribute value with the type
property.
Conclusion
To find the type of an input element with JavaScript, we use the type
property.