HTML DOM Input Color name Property


The Input Color name property returns a string, which is the value of the input color name attribute. User can also set it to a new string.

Syntax

Following is the syntax −

  • Returning string value
inputColorObject.name
  • Setting name attribute to a string value
inputColorObject.name = ‘String’

Example

Let us see an example of Input Color name property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Color Name</title>
</head>
<body>
<form id="formForColorsInput">
Color Picker: <input type="color" id="Color" name="primaryColor">
</form>
<button onclick="changeNameValue()">Change name value</button>
<div id="divDisplay"></div>
<script>
   var inputColor = document.getElementById("Color");
   var divDisplay = document.getElementById("divDisplay");
   divDisplay.textContent = 'Name of color input: '+inputColor.name;
   function changeNameValue() {
      if(inputColor.name == 'primaryColor'){
         inputColor.name = 'secondaryColor';
         divDisplay.textContent = 'Name of color input: '+inputColor.name;
      }
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Change name value’ button −

After clicking ‘Change name value’ button −

Updated on: 30-Jul-2019

53 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements