How can i remove the property of required to the Second Element "Second Name" ?
Here is my Code :
<form action="#" novalidate>
First Name:
<input type="text" name="first" required>
Second Name :
<input type="text" name="second" required>
<input type="submit">
</form>
How can i remove the property of required to the Second Element "Second Name" ?
Here is my Code :
<form action="#" novalidate>
First Name:
<input type="text" name="first" required>
Second Name :
<input type="text" name="second" required>
<input type="submit">
</form>
Share
Improve this question
asked Dec 10, 2014 at 9:44
AngularAngularAngularAngularAngularAngular
3,7795 gold badges27 silver badges42 bronze badges
2
- what do you mean by to the Second one "Class" – Kartikeya Khosla Commented Dec 10, 2014 at 9:48
- Updated for your understanding – AngularAngularAngular Commented Dec 10, 2014 at 9:48
5 Answers
Reset to default 3You can set required
property to false
$("input[name=class]").prop("required", false);
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
Name: <input type="text" name="name" required>
Class: <input type="text" name="class" required>
<input type="submit">
</form>
Using jQuery you can do:
$('input[name=second]').prop('required', false);
Example
Try using .removeAttr().
$('input[name="class"]').removeAttr('required')
Try this:
$('input[type="text"][name="second"]').prop('required', false);
it just removes the required property on the target element which has the name "second".
you can use the
removeAttribute mand:
First set ID's for the inputs.
I set it to the same value as the name.
Next removeAttribute
document.getElementById("class").removeAttribute("required");
This should do the trick ;)
Here, have a fiddle:
Fiddle