How to check if checkbox is checked or not using jquery

In this programming tutorial you will learn how to check if checkbox is checked or not using jquery. Jquery is a best javascript library to deal with dom's elements. There are various methods in jquery for this. Let's have a look over it.
How to check if checkbox is checked or not using jquery

//Method 1
if($('#checkBox').attr('checked'))
{
//Your code will come here
} 
else
{
//Your code will come here
}

//Method 2 
if($('#checkBox').is(':checked'))
{
//Your code will come here
}
else
{
//Your code will come here
} 

The above two methods return true or false. Return true if checkbox is checked or false if it is not checked. The third method iterates though all checkboxes with checked attribute defined and performs some action.

So that's it.
I love your feedback.

0 comments: