Javascript DOM HTML Input Checkbox defaultChecked Property get

Introduction

Find out if the checkbox is checked by default:

var x = document.getElementById("myCheck").defaultChecked;

Click button to find out if the checkbox is checked by default.

View in separate window

<!DOCTYPE html>
<html>
<body>

Checkbox:<input type="checkbox" id="myCheck" checked>

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {// www .j a v a2s  .  co m
  var x = document.getElementById("myCheck").defaultChecked;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The defaultChecked property returns the default value of the checked attribute.

This property returns true if the checkbox is checked by default, otherwise it returns false.




PreviousNext

Related