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=""
>
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=""
>
Just:
$('#edit-submitted-first-name').removeAttr('required');
If you're interested in further reading take a look here.
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);
});
document.querySelector('#edit-submitted-first-name').required = false;
$('#edit-submitted-first-name').removeAttr('required');
$('#id').removeAttr('required');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Even though the ID selector is the simplest, you can also use the name selector as below:
$('[name='submitted[first_name]']').removeAttr('required');
For more see: https://api.jquery.com/attribute-equals-selector/
© 2022 - 2024 — McMap. All rights reserved.