-1

What value will the variable checked have if the checkbox is checked? What is its value if the checkbox is unchecked?

HTML:

<input type="checkbox" id="my_id" />

jQuery:

var checked = $('input#my_id').is(':checked');
Ajay Mohite
  • 119
  • 3
  • 13

2 Answers2

3

I recommend you use console.log() or any way you like to check the values, but I've made an example here.

The value will be true or false

nicosantangelo
  • 13,216
  • 3
  • 33
  • 47
1

From the jQuery documentation for is.

Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression.

If no element fits, or the expression is not valid, then the response will be 'false'.

So you can be sure the answer will either be true or false.

kojiro
  • 74,557
  • 19
  • 143
  • 201