Sometimes, we want to access elements by type in JavaScript.
In this article, we’ll look at how to access elements by type in JavaScript.
How to access elements by type in JavaScript?
To access elements by type in JavaScript, we use the querySelectorAll method.
For instance, we write
const els = document.querySelectorAll("input[type=text]");
to call querySelector to select all input elements with type attribute set to text.
A node list is returned with all the selected elements included.
Conclusion
To access elements by type in JavaScript, we use the querySelectorAll method.