How to set HTML5 required attribute in JavaScript?

Spread the love

Sometimes, we want to set HTML5 required attribute in JavaScript.

In this article, we’ll look at how to set HTML5 required attribute in JavaScript.

How to set HTML5 required attribute in JavaScript?

To set HTML5 required attribute in JavaScript, we set the required property.

For instance, we write

document.getElementById("edName").required = true;

to select the input with getElementById.

Then we add the required attribute to it by setting its required property toi true.

Conclusion

To set HTML5 required attribute in JavaScript, we set the required property.

Leave a Reply

Your email address will not be published. Required fields are marked *