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 Commented Oct 31, 2012 at 19:05
  • 1
    stackoverflow.com/questions/901712/… Commented Oct 31, 2012 at 19:06
  • @Vega Given an appropriate DOMElement (which must exist), but not the most tidy way in jQuery. 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')){

}
Sign up to request clarification or add additional context in comments.

Comments

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
       }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.