How to Check a jQuery Checkbox is Checked or Not?

if(document.getElementById('radio1').checked) { alert("Checked"); }

jQuery Checkbox

<input type="checkbox" id="radio1" checked />
You can use the jQuery prop() method to check or uncheck a checkbox dynamically such as on click of button or an hyperlink etc.
$("#radio1").prop("checked", true);
To check the current state of the checkbox you must instead use the checked property . It is dynamically updated as the user checks/unchecks.
if(document.getElementById('radio1').checked) { alert("Checked"); }

The above code returns true if checked, false if unchecked.

run this source code Browser View

Full Source
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#btn1").click(function() { if(document.getElementById('radio1').checked) { alert("Checked"); } else { alert("Unchecked"); } }); }); </script> </head> <body> <input type="checkbox" id="radio1" checked /> <br> <button id="btn1">Check It!</button> </body> </html>

jQuery prop() Method

jQuery prop() method returns properties and values of the selected elements. When prop() method is used to return the property value, it returns the value of the first matched element . This method returns undefined for the value of a property that has not been set, or if the matched set has no elements. Syntax
$(selector).prop(property)
example
if($('#radio1').prop('checked')) { alert("Checked"); }

The above code returns true if checked, false if unchecked.

run this source code Browser View

Full Source
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#btn1").click(function() { if($('#radio1').prop('checked')) { alert("Checked"); } else { alert("Unchecked"); } }); }); </script> </head> <body> <input type="checkbox" id="radio1" checked /> <br> <button id="btn1">Check It!</button> </body> </html>

jQuery prop() Vs. attr()

The difference between prop() and attr() methods can be important in specific situations. Before jQuery 1.6 , the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behaviour. As of jQuery 1.6 , the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.

jQuery is() method

jQuery is() method is to check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments. If no element fits, or the selector is not valid, then the response will be 'false'. This method traverses along the DOM elements to find a match, which satisfies the passed parameter. Syntax
selector.is(filter)
example
if ($("input[type=checkbox]").is(":checked")) { alert("Checked"); }

The above code returns true if checked, false if unchecked.

run this source code Browser View

Full Source
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#btn1").click(function() { if ($("input[type=checkbox]").is(":checked")) { alert("Checked"); } else { alert("Unchecked"); } }); }); </script> </head> <body> <input type="checkbox" name="radio1" checked /> <br> <button id="btn1">Check It!</button> </body> </html>