JavaScript Checkbox Checked or Not

In this tutorial we will see how to Check if Checkbox is Checked or Not in JavaScript. HTML DOM Input Checkbox checked Property can be used to check the state of a checkbox.

Checked Property

The HTML DOM Checked Property either checks or unchecks the checkbox or it is used to read the state of the checkbox.

In this example checked property is used to check if checkbox is checked or not.


HTML Code is given below, This code contains a label tag for the checkbox and a button tag with onclick event.

<input id='chk' type="checkbox">  
<button onclick="checkFunction()">Check If Checked or Not</button>

JavaScript Code

JavaScript Code is given below, this code will check the state of the checkbox. The code will be executed on click event of button tag.

getElementById() is used to select the checkbox using it's id. The checked property will either return true or it will return false depending on the state of checkbox.

True is returned if checkbox is checked, otherwise False is returned.

function checkFunction()
  var checkbox = document.getElementById("chk").checked;
  alert('Checkbox is Checked!');
  alert('Checkbox is not Checked!');


Video Tutorial

Watch video tutorial on how to Check if Checkbox is Checked or Not using JavaScript.

How To Detect Shift Key Press with JavaScript Change Text Color On Hover with JavaScript Hide and Show div using JavaScript Get Button text with JavaScript Get textarea value with JavaScript Get table row Height with JavaScript Auto Increase width of input field with JavaScript Set Textarea maxLength with JavaScript Set Textarea Value with JavaScript JavaScript Count list items JavaScript set input field value Count Button Clicks with JavaScript Scroll Page to the Top on Click with JavaScript Change id of Element with JavaScript JavaScript Change li Text Color JavaScript Change li Text JavaScript Remove id from Element Check If id Exists in JavaScript How To Delete Table Row by id in JavaScript Update Textarea value in JavaScript Change Variable Value in JavaScript Uncheck Radio Button Dynamically JavaScript Check Radio Button Dynamically JavaScript JavaScript Check if Radio Button is Checked or Not Change h1 Tag Text with JavaScript