Reputation: 35
Trying to make make page refresh when the enter key pressed, as opposed to the default click on a button. I assume that an event listener is needed by not sure how to call the button.
$(document).ready(function() {
function refresh (e) {
if(e.keyCode === 13){
}
}
$('body').on('keydown', refresh);
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div class='win'>
<button><a href="index.html" style="text-decoration:none">Play Again</a></button>
</div>
</body>
</html>
Upvotes: 0
Views: 42
Reputation: 38502
This should work to refresh page when you hit ENTER
whose keyCode is 13
$(document).keypress(function(e) {
if(e.which == 13) {
location.reload();
}
});
Upvotes: 1