0

How do I add oninput to an html <input> element with javascript?

newinput.oninput = 'foo();';

This does not work - is there a way to do this?

1
  • 2
    A proper way: newinput.addEventListener('input', foo); Commented Jun 22, 2020 at 17:30

1 Answer 1

3

document.getElementById('my_input').addEventListener("input", function () {
  console.log('input happened!');
});
<input id="my_input">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.