How to check if checkbox is checked using jQuery

JQuery Add comments
SocialTwist Tell-a-Friend

There are 3 ways in jQuery to find a check box is checked or not.

// First way 
$('#checkBox').attr('checked'); 
// Second way 
$('#edit-checkbox-id').is(':checked'); 
// Third way for jQuery 1.2
$("input[@type=checkbox][@checked]").each( 
    function() { 
       // Insert code here 
    } 
);
// Third way == UPDATE jQuery 1.3
$("input[type=checkbox][checked]").each( 
    function() { 
       // Insert code here 
    } 
);

 

First two methods return true or false. True if that particular checkbox was checked or false if it is not checked. The third method iterates though all checkboxes with checked attribute defined and performs some action.

0 responses to “How to check if checkbox is checked using jQuery”

Leave a Reply

*** Please do not post spam. All comments require moderation,
So it may take some time to post to this blog! ***





Powered by Mango Blog. Design and Icons by N.Design Studio