Categories
JavaScript Answers

How to get list of all input objects using JavaScript, without accessing a form object?

Spread the love

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.

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 *