Javascript DOM HTML Input Color name Property get

Introduction

Get the name of a color picker:

var x = document.getElementById("myColor").name;
<p>Click button to display the value of 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">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*w  ww  . j av a2  s . com*/
  var x = document.getElementById("myColor").name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

The name attribute can identify form data after it has been submitted to the server.

Only form elements with a name attribute will be sent to server when submitting a form.

The name property accepts and returns a string value.




PreviousNext

Related