Javascript examples for DOM HTML Element:Input Color
The value property sets or gets the value attribute of a color picker, which sets the color for the color picker.
The default color is #000000 (black).
Set the value property with the following Values
Value | Description |
---|---|
#hexvalue | Sets a color for the color picker. |
The value must be a hexadecimal (hex) value: 3 double digit numbers, starting with a # sign (like #FF8040).
You cannot use color keywords (like "red" or "blue") here.
A String, representing a color
The following code shows how to change the color of a color picker:
<!DOCTYPE html> <html> <body> A color picker: <input type="color" id="myColor" value="#ff0080"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w. java 2 s . com*/ document.getElementById("myColor").value = '#EEEEEE'; var x = document.getElementById("myColor").value; document.getElementById("demo").innerHTML = x; } </script> </body> </html>