Category Archives: jQuery

How to check if checkbox is checked using jQuery

Working on my previous project I need a way to check if the certain checkbox is checked or not. jQuery is a great library but I had a hard time to identify if it was checked at the time. So here is the way to do just that. All you need to do is to check checked attribute of an HTML tag:

// First way 
$('#checkBox').attr('checked'); 

// Second way 
$('#edit-checkbox-id').is(':checked'); 

// Third way 
$("input[@type=checkbox][@checked]").each(
    function() {
       // Insert code here 
    }
);

Returns true or false.

Advertisements