$(document).on('keypress', function(e){ if(e.which == 13){ e.preventDefault; console.l" /> $(document).on('keypress', function(e){ if(e.which == 13){ e.preventDefault; console.l" /> $(document).on('keypress', function(e){ if(e.which == 13){ e.preventDefault; console.l"/>

jquery on keypress works only if e.which is 13

541 Views Asked by At
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>

$(document).on('keypress', function(e){
    if(e.which == 13){
        e.preventDefault;
        console.log('323');
    }
});

the above works fine
but for example e.which == 107 or 109 or 27 - doesn't work

e.keyCode instead of e.which - doesn't help

on('.keyup' instead of on('keypress - works
but I need keypress because of repeating the console.log endlessly while the key is pressed
please help

0

There are 0 best solutions below