Introduction to JQUERY - Checking Check and Radio boxes using the :checked Selector

Guest Posts Paolo Nikko Nuñal

In our previous tutorial we talked about on how to deal with drop-downs and determine if they are selected or not using the :selected selector. In this tutorial we are going to deal with checkboxes, radio-buttons and select elements using the :checked selector.




<script src="">
          if($('input[id="checkbox_id"]:checked').length == 1){
                 alert("Sony is Checked");
                alert("Sony is not Checked");
<input type="checkbox" id="checkbox_id" name="checkbox_name" class="checkbox_class" value="Sony" /> Sony
<button type="button" id="btn-check">Check</button>

From the code above, everytime you select the "Check" button it will automatically verify if the Sony checkbox is selected or not. However, we did add a few parameters aside from the :checked selector. As you can see we are checking the checkbox though its ID which has a name of "checkboxid". Additionally, we can also check it through the use of class and name.

Using name:


Using class:


The reason why we use the numerical value 1, its because checked items return 1 and 0 for unchecked items.

If you are looping through an array of checkboxes sharing the same name or class then you can loop through them. Using the example code below.


var cellphones = $('input[name="checkbox


There you have it!, that's how you check a checkbox. You can also do the same with radio boxes and see which one is being selected.