Change the color of a color picker:
document.getElementById("myColor").value = "#FF8040";
Click button to change the color of the color picker.
<!DOCTYPE html> <html> <body> A color picker: <input type="color" id="myColor"> <button onclick="myFunction()">Test</button> <script> function myFunction() {//from w w w . j av a 2 s . co m document.getElementById("myColor").value = "#FF8040"; } </script> </body> </html>
The value
property sets or gets the value attribute of a color picker.
The value attribute specifies the color for the color picker.
If nothing is specified, the default color is #000000 (black).
The value to set must be a hexadecimal (hex) value, like #FF5577.
The value
property accepts and returns a String value.