Answers for "javascript if key pressed"

1

how to see if user clicked key in js

document.addEventListener("keyup", function(event) {
    if (event.keyCode === 13) {
        alert('Enter is pressed!');
    }
});
Posted by: Guest on April-25-2021
0

if button is pressed js

<button>A</button>
<button>B</button>
<button>C</button>
<script>
  document.body.addEventListener("click", event => {
    if (event.target.nodeName == "BUTTON") {
      console.log("Clicked", event.target.textContent);
    }
  });
</script>
Posted by: Guest on March-31-2021

Code answers related to "javascript if key pressed"

Code answers related to "Javascript"

Browse Popular Code Answers by Language