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

I used this html code above for my project .. but I don't know how to get the value above input using javascript

<form>
  <input type="color" id="favcolor">
</form> 

Can someone help me?

thank

+4
source share
1 answer

To just get the value

document.getElementById("favcolor").value;

You can add an event listener if you want to get color when you change the selection. Would you do something like this

   var theInput = document.getElementById("favcolor");
   var theColor = theInput.value;
   theInput.addEventListener("input", function() {

   <<Do something with theColor value here>>

    }, false);

Here is a working example: http://jsfiddle.net/3fehj/

+7
source

Source: https://habr.com/ru/post/1540767/


All Articles