Input Checkbox defaultChecked Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Checkbox

Description

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.

Return Value

TypeDescription
Boolean Returns true if the checkbox is checked by default, otherwise it returns false.

The following code shows how to check if the checkbox is checked by default:

Demo Code

ResultView the demo in separate window

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

<button type="button" onclick="myFunction()">if the checkbox is checked by default</button>

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

<script>
function myFunction() {/*  www . j  a  v  a  2  s  .  com*/
    var x = document.getElementById("myCheck").defaultChecked;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials