javascripthtmljquery

How to remove required to an element using jQuery?


I need to remove required on an element using jQuery. For example, I want to remove required in the class, but jquery isn't working:

<div class="form-group" id="hidden_other" style="display:none;">
<input class="form-control required"  id="other_model" name="other_model" title="Other Model" placeholder="Please fill in other model">
</div>
$("#other_model").removeAttr("required");

Solution

  • You're looking for the removeClass(class) method, not the removeAttr(attr) method. This should do the trick:

    $("#other_model").removeClass("required")