Javascript DOM HTML Input Color name Property set

Introduction

Change the name of a color picker:

document.getElementById("myColor").name = "newColorName";

Click the buttons to display/change the name attribute of the color picker.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

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

function change() {/*from ww w  .j a  v a2s. c  o  m*/
  var x = document.getElementById("myColor").name = "newColorName";
  document.getElementById("demo").innerHTML = "The name was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related