:checked
S2C 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 example 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
ExampleTop
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;
$("#showcount").text("You like: " + (counter < 1 ? " none" : counter)
+ " of our pies");
}
pieCount();
$(":checkbox").click(pieCount);
Please fill in our Pie Survey: