Categories
JavaScript Answers

How to get the DOM element value using pure JavaScript?

Spread the love

Sometimes, we want to get the DOM element value using pure JavaScript.

In this article, we’ll look at how to get the DOM element value using pure JavaScript.

How to get the DOM element value using pure JavaScript?

To get the DOM element value using pure JavaScript, we use the value property.

For instance, we write

<input id="theId" value="test" />

to add an input.

Then we get the input’s value attribute value with

const value = document.getElementById("theId").value;

We select the input with getElementById.

Then we get its value property to get the input’s value attribute value.

Conclusion

To get the DOM element value using pure JavaScript, we use the value property.

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 *