:checked
JQ Home <<
Selectors <<
:checked
UI element states pseudo-class match selector.
Shorthand version $(':checked')
Description
The :checked
selector, selects all checked elements.
- Selections apply to checkboxes, radio buttons and options of <select> elements.
- If this selector is not preceded by another selector, the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the examples below to narrow the search and improve performance.
Syntax
Signature | Description |
---|---|
jQuery(':checked') | UI element states pseudo-class match |
Parameters
None.
Return
N/A.
:checked
Example
Selectors << Top
Selects all checked elements.
The following example will check to see which checkboxes have been ticked and put out an appropriate message. Click on the boxes to see the output message change.
function pieCount() {
var counter = $("form input:checked").length-1;
$("#showcount").text("You like: " + (counter < 1 ? " none" : counter)
+ " of our pies");
}
pieCount();
$(":checkbox").click(pieCount);
Please fill in our Pie Survey:
Related Tutorials
jQuery Basic Tutorials - Lesson 3 - CSS Selectors