JavaScript - how to check if input checkbox is checked?

9 points
Created by:

In this article, we're going to have a look at how to check if checkbox is checked in Pure JavaScript.

Quick solution:

var checkbox = document.getElementById('my-checkbox');
var checked = checkbox.checked;

More detailed description of solution is placed below.

1. Vanilla JavaScript example

In this section checked property is used to get current state of checkbox.

// ONLINE-RUNNER:browser;

<!doctype html>
    <input id="my-checkbox" type="checkbox" /> Agreement

    var checkbox = document.querySelector('#my-checkbox');

    checkbox.addEventListener('click', function() {
        console.log(checkbox.checked); // or this.checked



Native Advertising
50 000 ad impressions - 449$
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂