There are a number of different ways to check if a checkbox is checked (ticked). You can use either jQuery or plain JavaScript it doesn’t really matter. Here are 3 examples to wet your appetite. Could be useful when you need to check that a user has ticked a checkbox before submitting a form.

Check if a checkbox IS CHECKED

// 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 
    } 
);

Check if a checkbox IS NOT CHECKED

if ($('input[name=termsckb]').attr('checked') != true) {
	$('#captcha-wrap').hide();
}

or

if ($('#email_ckb').attr('checked') != true) {
	$('#captcha-wrap').hide();
}
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.


  • Pingback: jQuery Check if Checkbox is Checked « « Big Engine Media Big Engine Media()

  • Jordon

    Couldn’t you also do the following to validate checkbox is unchecked:

    if(!$(‘#mycheckbox’).attr(‘checked’)) {
    //code here
    }

    or is this frowned on due to how easy it is to overlook when reading?

  • http://www.jquerythis.com kevin

    how about prop()?

    :)

  • Lapaix Jasmin

    Hi,
    Can u please tell me, How to check checked checkboxes from multiple forms on same page

  • G

    SE

Learn JavaScript for free!
Free course: Introduction to JavaScript

Yours when you take up a free 14-day SitePoint Premium trial.