how to get value of type="color" input using javascript

html, javascript

Solution

To simply get the value

document.getElementById("favcolor").value;

You can add an event listener if you want to get the color when the selection changes. You’d do something like this:

var theInput = document.getElementById("favcolor");

theInput.addEventListener("input", function(){
  var theColor = theInput.value;
  
  // Do something with `theColor` here.
}, false);
<input id="favcolor" type="color"/>

Here’s a working JSFiddle.

Problem

I used this above html code for my project..but i don't know how to get value of above input using javascript ``` <form> <input type="color" id="favcolor"> </form> ``` can someone help me ? Thanks

Original source

Related problems