Javascript DOM HTML Input Color value Property get

Introduction

Get the color of a color picker:

var x = document.getElementById("myColor").value;

Click button to display the value attribute of the color picker.

View in separate window

<!DOCTYPE html>
<html>
<body>

A color picker: <input type="color" id="myColor" value="#ff0080">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//from  w w  w . ja  va2  s  .  c  o m
  var x = document.getElementById("myColor").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related