19

Using the new input="color" element within Chrome triggers a new popup dialog:

screenshot color dialog

I would like to know if there is an event handler that fires as soon as the value in this preview window changes and not only after clicking on "OK"

jQuery('#colorinput').on('change', function() { // fires only after clicking OK
    jQuery('#main').css('background-color', jQuery(this).val()); 
 });​

See http://jsfiddle.net/Riesling/PEGS4/

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
Riesling
  • 6,343
  • 7
  • 29
  • 33

3 Answers3

17

What you are looking for is the input event.

Your modified fiddle should now work in all (decent) browsers:

$('#colorinput').on('input', function() { ... } )
Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
1

You really want input event per HTML spec. Nothing guarantees change event to fire before the input element has lost focus.

"The input event fires whenever the user has modified the data of the control. The change event fires when the value is committed, if that makes sense for the control, or else when the control loses focus. "

anon
  • 11
  • 1
-2

To get the value of color input, you should use the event attribute onchangeprovided in w3school

<input name="eventColor" type="color" onchange="getColorVal(eventColor.value)"/>

and define a function that handle the event

 function getColorVal(colorValue){

     alert(colorValue);
}
palAlaa
  • 9,500
  • 33
  • 107
  • 166