how can I disable the key in second time press same in jquery?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how can I disable the key in second time press same in jquery?



When press first time 37 it showing alert message, again press the same key second time I want to disable that key. How can do that?


$(document).on (‘keydown’ , function (e)
var userVal = e.which ∥ e.keycode
valadation (userVal)

)

function valadation (userVal)
if (37 == userVal)
alert (“Wecome”)






Disable what key? 37 isn't a key...? Do you mean keyCode 37?
– Rory McCrossan
Aug 6 at 16:29



37





how can you press 37? do you mean on keyup?
– brk
Aug 6 at 16:29




2 Answers
2




//name the handler
$(document.body).on('keydown', function alertOnEnter (e)
if ([e.keyCode, e.which].indexOf(13) > -1)
//remove the handler from the event
$(document.body).off('keydown', alertOnEnter);
alert('you hit enter');

);


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>



Create a variable and update its value.




let clickVar = 0
$(document).on('keydown', function(e) )

function valadation(userVal)

if (37 === userVal && clickVar === 0)
alert('Welcome');
clickVar++


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>





Thank you so much bro!! It's working fine right now. I was training past 2 days so finally I got it right now.
– Bharath Mb
Aug 6 at 17:18






Can you explaing how does clickVar variable working.
– Bharath Mb
Aug 6 at 17:19






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS