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.

1 response to “How to check if checkbox is checked using jQuery”

  1. larry
    larry Says:
    I am looking for a way to dynamically show content for one checked box at a time. I have 3 check boxes (1 - 3) I want to show the one closest to the top that is selected.<br />example: If I select 2 and 3. then the text from 2 is visible, not 3.<br />If I select 1 and 3 then the texzt from 1 is visible.<br />I can easily hide and show content, but not to this extent. I think the third function will work if i can figure out how to see if the box closest to the top is checked only show that content.

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