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 use jQuery to zip files?
- How do I use jQuery to detect window resize events?
- How do I download a zip file using jQuery?
- How can I get the y position of an element using jQuery?
- How do I use a jQuery x-csrf-token?
- How do I add a zoom feature to my website using jQuery?
- How can I prevent jQuery XSS vulnerabilities?
- How can I use jQuery to yield a result?
- Include latest jQuery library version into HTML
See more codes...