Sometimes, we want to get list of all input objects using JavaScript, without accessing a form object.
In this article, we’ll look at how to get list of all input objects using JavaScript, without accessing a form object.
How to get list of all input objects using JavaScript, without accessing a form object?
To get list of all input objects using JavaScript, without accessing a form object, we use getElementsByTagName
.
For instance, we write
const inputs = document.getElementsByTagName("input");
for (const input of inputs) {
// ...
}
to select all input elements with getElementsByTagName
.
It returns a node list with all the elements, which we use a for-of loop to loop through.
Conclusion
To get list of all input objects using JavaScript, without accessing a form object, we use getElementsByTagName
.