-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboardEvents.html
38 lines (35 loc) · 1.07 KB
/
keyboardEvents.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>New Learn</title>
</head>
<body>
<h1>Keyboard Events in JQuery</h1>
<div id="box" class="test">
<h2> Box text </h2>
<p> Lorem ipsum some many things</p>
</div>
<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
$("#box").css("border", "1px solid pink");
$("#box").css("background-color", "pink");
// keypress() event : if pressed any keyword in keyboard it triggers
$("body").keypress(function() {
// this keyword here means the selector of this function
$(this).css('background-color', 'green');
})
// keyup() event : if left any key after pressing
$("body").keyup(function() {
$(this).css('background-color', 'red');
})
// keydown() event : if pressed any key down
$("body").keydown(function() {
$(this).css('background-color', 'orange');
})
});
</script>
</body>
</html>