Skip to content
Advertisement

Pure Javascript listen to input value change

Is there any way I can create a constant function that listens to an input, so when that input value changes, something is triggered immediately?

I am looking for something using pure javascript, no plugins, no frameworks and I can’t edit the HTML.

Something, for example:

When I change the value in the input MyObject, this function runs.

Any help?

Advertisement

Answer

This is what events are for.

HTMLInputElementObject.addEventListener('input', function (evt) {
    something(this.value);
});
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement