Javascript examples for DOM HTML Element:Input Checkbox
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.
Type | Description |
---|---|
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:
<!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>