DO YOU NEED A CONTENT WRITER FOR YOUR BUSINESS?

Your One-Stop Solution for All Content Needs! Click here for more!
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.

Namaste UI

For any types of queries, you can contact us on info[at]namasteui.com.

Recent Posts

Are We All Addicted to Stimulation? The New Face of Anxiety Disorders

Does your phone control your mind more than you control your phone? Modern life exploits…

13 hours ago

What Lifestyle Changes Help Prevent BPH from Coming Back

Did you know that the prostate continues growing throughout a man's entire life, making BPH…

13 hours ago

Sleep Apnea in Children: Could Enlarged Adenoids Be the Cause?

Could your child's snoring be more than just a noisy night? When adenoids—the lymphoid tissue…

13 hours ago

Fitting Electric Strike Sensors Safely

There are a number of steps that need to be taken in order to fit…

2 days ago

The Future of Cryptocurrency 100 Years From Now: Bold Predictions & Key Forces

Cryptocurrency has transformed from a digital experiment into a global financial force in just over…

3 days ago

Silent Layoffs in Indian Tech Sector: Subtle Signs Employees Shouldn’t Ignore

Introduction Layoffs have always been a part of corporate life, but the way they’re happening…

5 days ago