Categories: jQuery

jQuery Checkbox checked property

Share

The checkbox checked property of a checkbox element gives you the checked state of the element. But you can also check using is() method.

Example of Checkbox checked:

<input type="checkbox" id="checkID"/>

Then using checked property you can check this:

if(document.getElementById('checkID').checked){
// checked
} else {
// unchecked
}

Alternatively, you can use jQuery is() function as below:

if($("#checkID").is(':checked')){
// checked
} else {
// unchecked
}

Using attr or prop method you can check the status:

$('#checkID').attr('checked'); // "checked"
$('#checkID').prop('checked'); // true

You can use bind to change event instead of. You will probably still need to check whether or not the checkbox is checked:

$("#checkID").change(function() {
if(this.checked) {
//Do stuff
}
});

Read jQuery tips and tricks for more topics.

Recent Posts

Optimize Your Hormonal Balance: Enclomiphene Citrate for Enhanced Wellness

Hormonal balance plays a pivotal role in overall well-being, influencing various aspects of health, from…

1 hour ago

Paul Kanes Explores the World of Canine Companionship through Dog Walking

Dog walking is an excellent way to maintain your furry friend's camaraderie and provides many…

4 hours ago

Top 5 Must-Have Features Every Mobile App Needs to Succeed

Introduction Businesses understand the diverse requirements of mobile applications, which provide a competitive advantage. There…

9 hours ago

IoT Data Analytics: Ways to Gain Value from IoT Data

The Internet of Things (IoT) has recently changed the world. It links gadgets together and…

9 hours ago

The Rise of NFTs: Exploring the Impact of Non-Fungible Tokens on the Digital Economy

NFTs, or Non-Fungible Tokens, are revolutionizing the digital economy. These unique digital assets, authenticated through…

1 day ago

What to Ask Before You Hand Your Laptop For Repairing

It is safe to say that if you are in need of a good laptop…

1 day ago