Categories
JavaScript Answers

How to set HTML5 required attribute in JavaScript?

Spread the love

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.

And then we set its required property to true to make it a required input.

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 *