henhen henhen - 1 year ago 78
HTML Question

Hide html elements after a key is pressed in javascript

I was wondering if there was a way to hide header tags, images, divs etc from showing on an html page after a certain key is pressed. I am making a hangman game and when the player loses or wins, I display a message with a header tag. If the user presses Y, the game restarts but I dont how to make the header tag that ask "play again" to disappear once the player chooses Y

Answer Source

Hey there are several methods for doing this I am just showing here a keypress example for Enter button click lets try the below code

$(document).keypress(function(e) {
  if(e.which == 13) {    //for enter button
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download