Check if a checkbox is checked or not using JQuery

For checking if a checkbox is checked using jQuery, we can use the prop() method to access the checked property. Below is a simple example:


<html>
<head>
    <title>Example if checkbox is checked in JQuery</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <input type="checkbox" id="checkboxElem"> Click me
    <button id="btnElem">Is Checked</button>

    <script>
        $(document).ready(function () {
            $('#btnElem').on('click', function () {
                if ($('#checkboxElem').prop('checked')) {
                    alert("Checked");
                } else {
                    alert("Not checked");
                }
            });
        });
    </script>
</body>
</html>