
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Input Checkbox defaultChecked Property
The HTML DOM input checkbox defaultChecked property returns the default value of checked attribute of a checkbox in HTML.
Syntax
Following is the syntax −
object.defaultChecked
Example
Let us see an example of defaultChecked property −
<!DOCTYPE html> <html> <head> <title>HTML DOM checked property</title> <style> body{ text-align:center; } p{ font-size:1.5rem; color:#ff8741; } input{ width:30px; height:30px; } button{ background-color:#db133a; color:#fff; padding:8px; border:none; width:180px; margin:0.5rem; border-radius:50px; outline:none; font-weight:bold; } .show-msg{ color:#db133a; font-size:1.5rem; font-weight:bold; } </style> </head> <body> <h1>checked Property Example</h1> <p>Are you smart?</p> <input type="checkbox" checked> <br> <button onclick="check()">Lets Check? Click me</button> <div class="show-msg"></div> <script> function check() { var input = document.querySelector("input"); var showMsg = document.querySelector(".show-msg"); if(input.defaultChecked === true){ showMsg.innerHTML="You are right!You are smart by default"; } else { showMsg.innerHTML="Hmmmmm!You are not smart by default"; } } </script> </body> </html>
Output
This will produce the following output −
Click on “Lets Check? Click me” button to check whether the checkbox is by default checked or not?
- Related Articles
- HTML DOM Input Radio defaultChecked Property
- HTML DOM Input Checkbox checked Property
- HTML DOM Input Checkbox autofocus Property
- HTML DOM Input Checkbox disabled Property
- HTML DOM Input Checkbox form Property
- HTML DOM Input Checkbox name Property
- HTML DOM Input Checkbox required Property
- HTML DOM Input Checkbox type Property
- HTML DOM Input Checkbox value Property
- HTML DOM Input Checkbox Object
- HTML DOM Input Button type Property
- HTML DOM Input Button value Property
- HTML DOM Input Button name Property
- HTML DOM Input Button disabled Property
- HTML DOM Input Button form Property

Advertisements