
- jQuery - Home
- jQuery - Roadmap
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
jQuery :checkbox Selector
The ":checkbox" selector in jQuery is used to select all the input elements with type = checkbox".
Checkboxes are a form input elements that provides users with multiple options to select them. These checkboxes can be either checked or unchecked.
Syntax
Following is the syntax of :checkbox selector in jQuery −
$(":checkbox")
Parameters
Following is the description of above syntax:
- ":checkbox" − This selector will select all checkbox button elements in the document.
Example 1
In the following example, we are using the ":checkbox" selector to select all the <input> elements with type = "checkbox" −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $('button').click(function() { $(':checkbox').wrap("<span style='background-color:yellow'>"); }); }); </script> </head> <body> <form> <input type="text" name="username" placeholder="Enter text here"><br> Cricket: <input type="checkbox"><br> Badminton: <input type="checkbox"><br> Football: <input type="checkbox"><br> <button>Click</button> </form> </body> </html>
After executing and clicking the button, It selects all input elements with type=checkbox and wraps with a span element with yellow background color.
Example 2
In this example, we are disabling all the checkbox buttons in a form −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { $(":checkbox").prop("disabled", true); }); }); </script> </head> <body> <form> <label> <input type="checkbox" name="option" value="1"> Cricket </label> <label> <input type="checkbox" name="option" value="2"> Badminton </label> <label> <input type="checkbox" name="option" value="3"> Cricket </label> <br> <button>Disable All Checkboxes</button> </form> </body> </html>
After clicking the "Disable All Checkboxes", it selects all the input elements with type=checkbox and disables them.