<div>0</div> <script> window.addEventListener("click", func); window.addEventListener("keydown", func); function func(){ document.querySelector('div').textContent++; } </script>