-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery_exercises.html
More file actions
133 lines (90 loc) · 2.47 KB
/
jquery_exercises.html
File metadata and controls
133 lines (90 loc) · 2.47 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<header>
<h1 class="head" id="heading">I am a header</h1>
</header>
<main>
<a href="#" class="anchor" id="pageLink">link to nowhere</a>
<h2>Duplicate ID step</h2>
<ul id="list">
<li class="codeup" id="listItem1"> item 1</li>
<li class="codeup" id="listItem2"> item 2</li>
<li class="codeup" id="listItem3"> items 3</li>
<li class="codeup" id="listItem4"></li>
</ul>
<div class="container" id="divider">
<p class="textholder" id="pOne">I'm a paragraph</p>
</div>
<p class="textholder" id="pTwo">I'm a paragraph element also!</p>
</main>
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
crossorigin="anonymous"></script>
<!-----custom JS goes below ------>
<!--<script src="js/custom-js.js"></script>-->
<script>
$(document).ready(function() {
// $(document).ready(function() {
//
// alert($('#heading').html())
//
// alert($('#pOne').html())
//
// console.log($('#heading'))
//
//
// $('.codeup').css('border', '1px solid red')
//
// $('.codeup').css('font-size', '20px')
// $("h1").css('background-color', 'yellow')
// $('p').css("background-color", 'yellow')
// $('li').css("background-color", "yellow")
// $("h1, p, li").css('background-color', 'yellow')
// alert($('h1').html())
// })
// ==================== mouse events exercise =============
//1
// $('#heading').click(function () {
// $('#heading').css('background-color', 'blue')
// })
//---------walk through:
$('h1').click(function(e) {
e.target.style.backgroundColor = "red";
})
//2
// $('.textholder').dblclick(function () {
// $('.textholder').css("font-size", '18px')
// })
//-------walk thru:
$('p').dblclick(function(e) {
e.target.style.fontSize = "18px";
})
//3
// $('.codeup').hover(
// function() {
// $('ul > li').css('color', 'red')
// },
// function() {
// $('ul > li').css('color', '')
// }
// )
//-----walkthru :
$('li').hover(hoverIn, hoverOut)
function hoverIn (e) {
//when in, color red
e.target.style.color = 'red';
}
function hoverOut (e) {
//when out, reset to black
e.target.style.color = '';
}
//with .(on) instead of hover, syntax boils down to:
// $('').mouseenter(handlerIn).mouseleave(handlerOut)
})
</script>
</body>
</html>