Alternative ways of checking if a checkbox is checked or not.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under jQuery category on | Points: 40 | Views : 240
<input id = "checkbox1" type = "checkbox" name = "one" value = "1" checked = "checked">
<input id = "checkbox2" type = "checkbox" name = "two" value = "2">
<input id = "checkbox3" type = "checkbox" name = "threr" value = "3">


1st method:-
$('#checkbox1').is(':checked');

true
$('#checkbox3').is(':checked');

false

2nd method:-
$('#checkbox1:checked').length;
('#checkbox2:checked').length;


3rd method:-Getting DOM object reference
$('#checkbox1').get(0).checked;  
$('#checkbox1')[0].checked;

true

Comments or Responses

Login to post response