13
for Enter keyThere are certain situations when you want to check whether user has pressed Enter key on keyboard, for example sending form data through Ajax on pressing Enter key, and so on.
To do this, you can simply use the key code 13
, which is the ASCII equivalent of Enter key and supported in all major browsers. Let's try out an example to understand how it works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Check if Enter Key is Pressed with jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).on("keypress", function(e){
if(e.which == 13){
$("body").append("<p>You've pressed the enter key!</p>");
}
});
</script>
</head>
<body>
<p><strong>Note:</strong> Click on the viewport and press the Enter key on the keyboard. A message will be displayed.</p>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Class 'Form' not found in Laravel 7
In Laravel 5 earlier versions, Laravel F...Python Numpy Array Tutorial Part 2
In the first part, we have discussed wha...Laravel 5.6 - Google Firebase Notification In Android
Today, We are going to share with you gu...How to assign block of HTML code to a JavaScript variable
Use the concatenation operator (+) Th...How to Detect Browser Window is Active or not
Javascript is great programming language...