The value attribute from input color element specifies the default color for the color picker.
The value
property sets or gets the value of the value attribute of a color picker.
The default color is #000000, black.
value |
Yes | No | Yes | No | Yes |
Return the value property.
var v = colorObject.value
Set the value property.
colorObject.value=#hexvalue
Value | Description |
---|---|
#hexvalue | Specifies a color for the color picker. The value must be a hexadecimal value. Default color is #000000 (black). |
A String type value representing a color.
The following code shows how to change the default color of a color picker.
<!DOCTYPE html>
<html>
<body>
<!-- w ww .j a va 2 s . c o m-->
A color picker: <input type="color" id="myColor">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myColor").value="#FF8080";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the color of a color picker.
<!DOCTYPE html>
<html>
<body>
A color picker: <input type="color" id="myColor" value="#ff8080">
<button onclick="myFunction()">test</button>
<!--from w ww . ja v a 2 s.c om-->
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myColor").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: