Skip to content Skip to sidebar Skip to footer

Bind Event Handler On Keydown Listen Function Javascript Jquery

I am trying to bind a handler to an event. The event is a keydown function. The handler will listen for hit variables to produce one of two conditions. The 1st condition (odd numbe

Solution 1:

declare hits outside your keydown function so it doesn't get reset to 0 each time.

Solution 2:

No, not the condition is in the wrong place but your variable declaration and initialisation. If you do

hits = 0;
if (hits % 2 !== 0) …

the condition will obviously be always false.

Move the declaration outside the scope of your event handler function, and don't reset it each time right before you query it.

Post a Comment for "Bind Event Handler On Keydown Listen Function Javascript Jquery"