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.