Check if a Checkbox is Selected Using jQuery
Situation:
In jQuery, you need to determine if a checkbox is checked to perform specific actions, but the default attr('checked') method returns false when unchecked.
Solution:
1. Using DOM Element Properties:
if(document.getElementById('isAgeSelected').checked) { $("#txtAge").show(); } else { $("#txtAge").hide(); }
2. Toggling Visibility with toggle():
$('#isAgeSelected').click(function() { $("#txtAge").toggle(this.checked); });
Note:
The above is the detailed content of How Can I Check if a Checkbox is Selected Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!