jQuery kepress is always done twice #5163
-
Description
Every time I go to press any key ONE time, it always triggers it twice, and I am not sure about how to do a workaround for this issue, considering I have only been doing JavaScript for a few months. I found jQuery makes sensing for a keydown a lot easier, but it keeps sensing more than one time. I expected it to only trigger one time whereas it triggered twice, and I am unsure of the total number of browsers where this is the case, but I can say that I use Google Chrome 102.0.5005.185 (Official Build) (64-bit) Link to test caseI have a test case on jsfiddle: https://jsfiddle.net/Dabman2392/qpvm6Lu0/22/ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The |
Beta Was this translation helpful? Give feedback.
The
keypress
event bubbles so when thebody
is focused, the handler is being invoked on both<body>
and<html>
elements, causing the issue you observe. Attach the handler just on a single element to avoid the issue. This has nothing to do with jQuery.