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
  • 24,944
  • 53
  • 156
  • 273

2 Answers2

40

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

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

}
Pastor Bones
  • 6,895
  • 3
  • 34
  • 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
       }
dpp
  • 27,256
  • 30
  • 100
  • 152
defau1t
  • 10,457
  • 2
  • 33
  • 46