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 thecheckedproperty of the checkbox tofalse, thus unchecking it.$('#myCheckbox')- This is a jQuery selector that selects the checkbox with theidofmyCheckbox.attr('checked', false)- This is theattr()method that sets thecheckedattribute 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 validate a form?
- How do I use jQuery with Yarn?
- How can I format a number using jQuery?
- How do I download a zip file using jQuery?
- How do I use jQuery to change the z-index of an element?
- How do I use jQuery to zoom in or out on an element?
- How can I prevent jQuery XSS vulnerabilities?
- How do I prevent XSS attacks when using jQuery?
See more codes...