jQuery: Get checked checkboxes, radio buttons using Pseudo selectors

jQuery Pseudo Selectors are very efficient way to get the checked checkboxes or radio buttons.
The Pseudo Selector used is - :checked

Following are some simple examples to follow:
$("#chkBoxIdOrRadioButtId").is(":checked");
- returns a boolean true if checked or false
$("#chkBoxIdOrRadioButtId").not(":checked");
- returns a boolean true if unchecked or false
$("#chkBoxIdOrRadioButtId").attr('checked','checked');
- programmatically check the desired.
$("input:radio[name='myRadioGrpName']:checked").val();
- return the value of the checked radio from the 'myRadioGrpName' group.
$("input[name='myChkBoxGrp']:checked").length;
- returns the count of the checked
$("input[name='myChkBoxGrp']:not(:checked)").length;
- returns the count of the unchecked

No comments:

Post a Comment

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...