jqueryHow do I uncheck a checkbox using jQuery?
To uncheck a checkbox using jQuery, you can use the prop()
method. This method will set the property of the checkbox to false
:
$('input[type="checkbox"]').prop('checked', false);
The code above will uncheck all checkboxes on the page. To uncheck a specific checkbox, you can use the attr()
method, passing in the checked
attribute and setting it to false
:
$('#myCheckbox').attr('checked', false);
The code above will uncheck the checkbox with the id
of myCheckbox
.
Code explanation
$('input[type="checkbox"]')
- This is a jQuery selector that selects all checkboxes on the page.prop('checked', false)
- This is theprop()
method that sets thechecked
property of the checkbox tofalse
, thus unchecking it.$('#myCheckbox')
- This is a jQuery selector that selects the checkbox with theid
ofmyCheckbox
.attr('checked', false)
- This is theattr()
method that sets thechecked
attribute of the checkbox tofalse
, thus unchecking it.
Here are some ## Helpful links
More of Jquery
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I add a zoom feature to my website using jQuery?
- How do I use jQuery to zoom in or out on an element?
- How can I use jQuery to zoom an image when the user hovers over it?
- How can I use JQuery with Yii2?
- How can I use jQuery in WordPress?
- How do I use a jQuery zoom plugin?
- How do I get the y-position of an element using jQuery?
- How can I get the y position of an element using jQuery?
- How can I make a jQuery XMLHttpRequest?
See more codes...