Javascript examples for DOM HTML Element:Input Color
The defaultValue property sets or gets the default value of a color picker, which is the value specified in the value attribute.
You can use defaultValue property to find out if the color of a color picker has been changed.
Set the defaultValue property with the following Values
Value | Description |
---|---|
value | Sets the default value of the color picker |
A String, representing the default value of the color picker
The following code shows how to get the default value of a color picker:
<!DOCTYPE html> <html> <body> <p>Change the color of the color picker, and then click the button below.</p> Color picker: <input type="color" id="myColor" value="#ff0080"> <p>Note that the default value is not affected when you change the value of the color picker.</p> <button type="button" onclick="myFunction()">Test</button> <p><b>Note:</b> type="color" is not supported in Internet Explorer 11 and earlier versions or Safari 9.1 and earlier versions.</p> <p id="demo"></p> <script> function myFunction() {/*from ww w .j a v a 2 s . co m*/ var x = document.getElementById("myColor"); var defaultVal = x.defaultValue; document.getElementById("demo").innerHTML = defaultValue; } </script> </body> </html>