HTML DOM Input Color defaultValue Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input Color defaultValue property sets/returns the default value corresponding to a color. It may or may not be same as value attribute.

Syntax

Following is the syntax −

  • Returning string value
inputColorObject.defaultValue
  • Setting defaultValue to string
inputColorObject.defaultValue = ‘string’

Boolean Value

Here, “string” can be the following −

booleanValue
Details
#000000 - #ffffff
It defines that input color can have a default value between the defined range

Example

Let us see an example of Input Color defaultValue property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Color Default Value</title>
</head>
<body>
<form>
Color Picker: <input type="color" id="Color" value="#00cc00">
</form>
<button onclick="getDefaultValue()">Get Default Value</button>
<div id="divDisplay"></div>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputColor = document.getElementById("Color");
   function getDefaultValue() {
      divDisplay.textContent = 'Default Color: '+inputColor.defaultValue;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Get Default Value’ button −

After clicking ‘Get Default Value’ button −

raja
Updated on 30-Jul-2019 22:30:26

Advertisements