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?

4
  • 2
    See :checked
    – Mark Meyer
    Commented Oct 31, 2012 at 19:05
  • 1
    stackoverflow.com/questions/901712/…
    – bvulaj
    Commented Oct 31, 2012 at 19:06
  • @Vega Given an appropriate DOMElement (which must exist), but not the most tidy way in jQuery.
    – user166390
    Commented Oct 31, 2012 at 19:07
  • @pst In the FM doesn't say if I first need to check if the element exists, and that was my doubt. Commented Nov 1, 2012 at 11:16

2 Answers 2

40

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

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

}
0
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
       }

Not the answer you're looking for? Browse other questions tagged or ask your own question.