"enter" event listener problem/wikipedia API

"enter" event listener problem/wikipedia API
0.0 0

#1

Hello guys. I made a function so it listens to “enter” key to submit a search.However it works but it doesn’t. If i type something into the box and press enter it doesn’t work,but if i press the button,it works,then i type another word and press enter it works as many times as i want. Any ideea why is that?
Here’s my CodePen
https://codepen.io/GummyGod/full/PEaJgL/


#2

You need to look at where you’ve placed your event handler for the text input. It is inside the callback for the search submit, so it doesn’t get set up until after the first search. I would move it down, as the last thing before closing the $(document).ready section.


#3

Oh right. Thanks. It worked after putting it outside the callback