seenfil
Back to feed

How to check a checkbox in JS

CODE
<input type="checkbox" id="myCheckbox" />
<button onclick="checkCheckbox()">Check</button>

<script>
  function checkCheckbox() {
    const checkbox = document.getElementById('myCheckbox');
    if (checkbox.checked) {
      console.log('Checkbox is checked');
    } else {
      console.log('Checkbox is not checked');
    }
  }
</script>
375
Comments (0)
No comments yet. Be the first to comment!
Log in to leave a comment.
Photo
1 / 1
likes
❤️ 🔥 😂 😍 👍 👏 🎉 🚀 🥳 💯

Create Post