Check if a checkbox is checked or not using JavaScript

For checking if a checkbox is checked using JavaScript, we can access the checked property of the checkbox element. Below is a simple example:


<html>
<head>
    <title>Example if checkbox is checked in JavaScript</title>
</head>
<body>
    <input type="checkbox" id="checkboxElem"> Click me
    <button id="btnElem" onclick="checkStatus()" >Is Checked</button>

    <script>
        function checkStatus() {
            var chkbox = document.getElementById('checkboxElem');
            if (chkbox.checked) {
                alert("Checked!");
            } else {
                alert("Not checked.");
            }
        }
        </script>
</body>
</html>