Input Color defaultValue Attribute
Definition and usage
defaultValue
Attribute sets or returns the default value of the color selector.
Note:The default value is HTML value attribute The value specified in the middle.
The difference between defaultValue and value attributes is:
- defaultValue contains the default value
- While value contains the current value after some changes
- If there is no change, defaultValue and value are the same (see the example below)
The defaultValue attribute is very useful when you want to determine whether the color of the color selector has changed.
Instance
Example 1
Get the default value of the color selector:
var x = document.getElementById("myColor").defaultValue
Example 2
An example showing the difference between defaultValue and value attributes:
var x = document.getElementById("myColor"); var defaultVal = x.defaultValue; var currentVal = x.value;
Syntax
Return the defaultValue attribute:
colorObject.defaultValue
Set the defaultValue attribute:
colorObject.defaultValue = value
Attribute value
Value | Description |
---|---|
value | Define the default value of the color selector. |
Technical Details
Return Value: | A string value representing the default value of the color selector. |
---|
Browser Support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |
Note:The <input type="color"> element does not display any color selector in Internet Explorer and Safari.