Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing html5 required attribute with jQuery

Hi I would like to remove the 'required=""' attribute with jquery.

<input     type="text"     id="edit-submitted-first-name"     name="submitted[first_name]"     value=""     size="30"     maxlength="128"     required="" > 
like image 947
LeBlaireau Avatar asked Dec 19 '12 11:12

LeBlaireau


People also ask

What jQuery method is used to completely remove attributes from elements?

To remove all attributes of elements, we use removeAttributeNode() method.

How do you make a field not required in HTML?

Just unset the required attribute. If you're trying to unset it after some user action (with javascript) then use the . removeAttribute("required") function.

How can we make fields mandatory in jQuery?

$("input"). attr("required", "true");


2 Answers

Just:

$('#edit-submitted-first-name').removeAttr('required');​​​​​ 

If you're interested in further reading take a look here.

like image 189
Minko Gechev Avatar answered Oct 11 '22 04:10

Minko Gechev


If you want to set required to true

$(document).ready(function(){ $('#edit-submitted-first-name').prop('required',true); }); 

if you want to set required to false

$(document).ready(function(){ $('#edit-submitted-first-name').prop('required',false); }); 
like image 27
Latief Anwar Avatar answered Oct 11 '22 04:10

Latief Anwar