check whether a checkbox is checked using jQuery?

 

To check weather a checkbox is checked or not in plain javascript use the following code 

 

if(document.getElementById('SomeCheckbox').checked) {
    alert('Some checkbocx is chcked')
} else {
    alert('Some checkbocx is not chcked')
}

 

To weather checkbox  is checked or not using JQuery use the following code.



if($("#SomeCheckbox").is(':checked'))
   alert('Some checkbocx is checked')
else
    alert('Some checkbocx is not checked')


To check weather a checkbox is checked or not using .prop use the following code.

if($('#SomeCheckbox').prop('checked')) {
     alert('Some checkbocx is checked')
} else {
    alert('Some checkbocx is not checked')
}

Tags:

Share:

Related posts