Categories
JavaScript Answers

How to get name of form element with JavaScript?

Spread the love

Sometimes, we want to get name of form element with JavaScript.

In this article, we’ll look at how to get name of form element with JavaScript.

How to get name of form element with JavaScript?

To get name of form element with JavaScript, we use the getAttribute method.

For instance, we write

const name = element.getAttribute("name");

to call element.getAttribute with 'name' to get the value of the name attribute of the element.

Conclusion

To get name of form element with JavaScript, we use the getAttribute method.

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 *