Input Color name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Color

Description

The name property sets or gets the name attribute of a color picker.

Set the name property with the following Values

name Description
name Sets the name of the color picker

Return Value

A String, representing the name of the color picker

The following code shows how to get the name of a color picker:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

A color picker: <input type="color" id="myColor" name="favcolor">

<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
    var x = document.getElementById("myColor").name;
    console.log("The name of the color picker is: " + x);
}

function change() {//from w w w .  ja  v a  2  s . co  m
    var x = document.getElementById("myColor").name = "newColorName";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials