23

Possible Duplicate:
Check checkbox checked property using jQuery

What is the correct way of accessing a checkbox to check if it's checked? Is it necessary to first check if that element exists in the DOM and then see if is checked or not?

Community
  • 1
  • 1
Hommer Smith
  • 26,772
  • 56
  • 167
  • 296

2 Answers2

40

You would use the checked selector along with the is method of Jquery

if($('#chkbox').is(':checked')){

}
Pastor Bones
  • 7,183
  • 3
  • 36
  • 56
4

You can see if the checkbox is checked by using the following condition.

   if( $("input:checked").length == 1 ) {
           //Checkbox is selected and Do stuff here
       }
kazinix
  • 28,987
  • 33
  • 107
  • 157
defau1t
  • 10,593
  • 2
  • 35
  • 47