This defaultChecked
property returns true
if the checkbox is checked by default, otherwise it returns false.
defaultChecked |
Yes | Yes | Yes | Yes | Yes |
var v = checkboxObject.defaultChecked
A Boolean type value, true if the checkbox is checked by default, otherwise it returns false.
The following code shows how to check if an checkbox is checked by default.
<!DOCTYPE html>
<html>
<body>
<!--from ww w . j a va 2s . c om-->
Checkbox:<input type="checkbox" id="myCheck" checked>
<button type="button" onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myCheck").defaultChecked;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: