Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

addEventListener keyup Keydown with Keycode not working [closed]

<input class="inputVal">
<script type="text/javascript">

    var myVal = document.getElementsByClassName('inputVal')[0]; 

    myVal.addEventListener('keyup', function(e){
        var count = myVal.value;
        console.log(count)
    });  
</script>
like image 252
Der Admin81 Avatar asked Dec 08 '22 05:12

Der Admin81


1 Answers

Try bind event to document or window. If an element is not focusable and is not focused, keyboard events won't dispatch to it, instead they dispatch to document root(<body>).

like image 199
Leo Avatar answered Jan 30 '23 21:01

Leo