Answer the question
In order to leave comments, you need to log in
How to optimize this code?
I have something like "custom textarea" i.e. when you click on the button (I did so far only when you click on the numbers) of the keyboard, the button that I clicked should be displayed in the span:
$(document).on("keydown", e => {
switch(e.keyCode) {
case 48:
$("span").append("0");
break;
case 49:
$("span").append("1");
break;
case 50:
$("span").append("2");
break;
case 51:
$("span").append("3");
break;
case 52:
$("span").append("4");
break;
case 53:
$("span").append("5");
break;
case 54:
$("span").append("6");
break;
case 55:
$("span").append("7");
break;
case 56:
$("span").append("8");
break;
case 57:
$("span").append("9");
break;
}
});
Answer the question
In order to leave comments, you need to log in
$(document).on("keydown", e => {
if(e.key.search(/\d/) != -1)
$("span").append(e.key);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question