This is not a duplicate, because the value of the input is changed by a function, not by user input.
Is it possible to call a function if the value of the attribute of an element has changed?
E.g. I use an input text with the id color and a button which opens a color picker. If I select a color then the color value is written into the input text with id color.
I try to detect if the value of the input text with id color has changed and call a function which sets the background-color
of my input text to the selected color.
My attempt:
$("input#color").on
(
"change",
function()
{
console.log("SOMETHING HAS CHANGED");
var color = $("input#color").val();
$("input#color").css("background-color", color);
}
);
But SOMETHING HAS CHANGED
is never shown.
I know I could solve this by using timers, but I think there must be a better solution.