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

Top Programming Trends You Need to Know in 2024

Programming continues to evolve at a rapid pace, with new trends and technologies emerging every…

20 mins ago

How to Find the Best SEO Consultant in Toronto to Boost Your Rankings

Introduction In today's digital age, having a strong online presence is crucial for businesses in…

20 hours ago

Sharing USB across networks

You may need access to a printer, scanner, webcam, or dongle connected to another computer.…

1 day ago

Tourist Attractions: 5 Top-Rated Must-See Places in Dubai

From skyscrapers to endless deserts, from luxurious malls to Michelin star restaurants, Dubai has it…

2 days ago

Fractional CTO Services: Catalyzing Growth in the Logistics Sector

In today's fast-paced digital world, the logistics and supply chain sector is encountering unprecedented challenges…

2 days ago

Email Marketing Professionals: Masters of Digital Connection

In the vast landscape of digital marketing, one strategy has stood the test of time…

2 days ago