
- 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 :checked Selector
The :checked selector in jQuery is used to select all checked or selected elements.
It applies to <input> elements of type "checkbox" or "radio", as well as <option> elements within a <select> dropdown.
Syntax
Following is the syntax of :checked selector in jQuery −
$(":checked")
Parameters
Following are the parameters of this method −
- ":checked" − This selector selects all checked elements within the entire document.
Example 1
In the following example, we are using the ":checked" to select all the checked checkboxes −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function(){ $(":checked").wrap("<span style='background-color:yellow'>") }); </script> </head> <body> <h1>Select Your Interests</h1> <label><input type="checkbox" value="Music" checked> Music</label><br> <label><input type="checkbox" value="Sports"> Sports</label><br> <label><input type="checkbox" value="Reading"> Reading</label><br> <label><input type="checkbox" value="Traveling"> Traveling</label><br> <div id="result"></div> </body> </html>
When we execute the above program, the checked checkboxes will be selected and wrapped with a <span> element with a yellow background color.
Example 2
In this example, we are using the ":checked" to select all the checked radio buttons −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function(){ $(":checked").wrap("<span style='background-color:yellow'>") }); </script> </head> <body> <h1>Select Your Interests</h1> <label><input type="radio" value="Music" checked> Music</label><br> <label><input type="radio" value="Sports" checked> Sports</label><br> <label><input type="radio" value="Reading"> Reading</label><br> <label><input type="radio" value="Traveling"> Traveling</label><br> <div id="result"></div> </body> </html>
After executing the above program, the checked radio buttons will be selected and wrapped with a <span> element with a yellow background color.