Javascript DOM HTML Input Color Object get

Introduction

The Input Color object represents an HTML <input> element with type="color".

We can access an <input> element with type="color" via document.getElementById():

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

Click the button to get the color of the color picker.

View in separate window

<!DOCTYPE html>
<html>
<body>
Select your favorite color: <input type="color" id="myColor">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//from  www  .  j a v a  2 s  .  c om
  var x = document.getElementById("myColor").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related