How do I commit all changes to the input field?

  • 0
    The task is to change the div depending on the value in the input field, if you enter it by hand, everything works, but I don't understand how to make it work when you add the value with the buttons, wrapped it in a function and hung the action click does not work, please help me add the code

    JavaScript Caleb Zhang, Oct 12, 2020

  • 2 Answers
  • 0
    Replace $ input.change (); with $ input.get (0) .dispatchEvent (new Event ('input')); .



    Or, rewrite the input event handler connection using jquery ( $ input.on ('input', ... ), then $ input instead of . change (); should be $ input.trigger ('input'); .
    Anonymous

  • 0
    there is such an event as input

    const $ input = document.querySelector ('input')

    const Arr = []

    $ input.oninput = () = & gt; {

    Arr.push ($ input.value)

    console.log (Arr)

    }
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!