I want to add an attribute to a HTML element without a value using JQuery
<input id="r1" type="radio name="r1" value="1">
Add required
<input id="r1" type="radio name="r1" value="1" required>
How can this be done without the =""after the attribute?
The standard practice would be to set the property to true
$("#r1").prop("required", true);
This actually results in markup that exactly reads
<input id="r1" required>
JSFiddle demo: http://jsfiddle.net/8SrED/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With