Home > Web Front-end > JS Tutorial > How to Check Checkbox Status in jQuery?

How to Check Checkbox Status in jQuery?

Linda Hamilton
Release: 2024-12-23 19:57:11
Original
614 people have browsed it

How to Check Checkbox Status in jQuery?

How to Check Checkbox Status Using jQuery

In jQuery, the attr('checked') function is not used to check the checked property of a checkbox. Instead, you can use the following methods:

1. Using DOM Element's checked Property

The checked property of the checkbox DOM element provides the checked state of the checkbox:

if (document.getElementById('isAgeSelected').checked) {
  $("#txtAge").show();
} else {
  $("#txtAge").hide();
}
Copy after login

2. Using jQuery's change() Event

When the checkbox is clicked, the change() event is triggered. You can use it to toggle the visibility of the text box:

$('#isAgeSelected').click(function () {
    $("#txtAge").toggle(this.checked);
});
Copy after login

The above is the detailed content of How to Check Checkbox Status in jQuery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template