Onkeyup is not working

3.1k views Asked by At

Although I can see an "onkeyup" event in the chrome console, for whatever reason, the event is not firing.

var el = document.getElementById("userInput");
el.addEventListener("onkeyup", function() {
    alert('yahoooo0');
});
<input type="text" id="userInput" name="food"/>
    
    

4

There are 4 answers

0
frnt On BEST ANSWER

Update your event listener from onkeyup to keyup.

var el = document.getElementById("userInput");
el.addEventListener("keyup", function() {
    alert('yahoooo0');
});
<input type="text" id="userInput" name="food"/>
    

0
Andy Ray On
el.addEventListener("keyup", function() {
1
Ikhsan On

try this :

$("#userInput").keyup(function() {
   alert('yahoooo0');
});

test on fiddle

0
Jagajit Prusty On

You can change the eventlistener name from onkeyup to keyup or you may use below simple eventlistenter attaching method

<input type="text" id="userInput" name="food" onkeyup="doSomething()"/>