Home > Net >  Inserting oninput to an input field
Inserting oninput to an input field

Time:11-05

Is there a way to insert [ oninput="this.nextElementSibling.value = this.value" ] through JQuery or Javascript to an input field?

<input aria-label="Quantity" size="4" max="10" min="1" value="1" type="range" step="1">
<output>1</output>

CodePudding user response:

Just set up an event listener for the input event.

document.querySelector("input").addEventListener("input", function(){
  this.nextElementSibling.value = this.value;
});
<input aria-label="Quantity" size="4" max="10" min="1" value="1" type="range" step="1">
<output>1</output>

  • Related