<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>
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>
).