Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

JavaScript - how to check if input checkbox is checked?

0 contributions
9 points

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>
<html>
<body>
  <label>
    <input id="my-checkbox" type="checkbox" /> Agreement
  </label>
  <script>

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

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

  </script>
</body>
</html>

 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey đź‘‹
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more