Input Checkbox checked Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Checkbox


The checked property sets or gets the checked state of a checkbox.

This property reflects the HTML checked attribute.

Set the checked property with the following Values

Value Description
true|false Sets whether a checkbox should be checked or not.
  • true - The checkbox is checked
  • false - Default. The checkbox is not checked

Return Value

A Boolean, returns true if the checkbox is checked, and false if the checkbox is not checked

The following code shows how to set the checked state of a checkbox:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
Checkbox: <input type="checkbox" id="myCheck">

<button onclick="check()">Check Checkbox</button>
<button onclick="uncheck()">Uncheck Checkbox</button>

function check() {/*from   ww w  . ja  v a 2s  .  c o  m*/
    document.getElementById("myCheck").checked = true;

function uncheck() {
    document.getElementById("myCheck").checked = false;


Related Tutorials