forked from MakeSchool-18/front-end-web-Q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-0.html
57 lines (48 loc) · 1.65 KB
/
index-0.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!doctype html>
<html>
<head>
<title></title>
<style>
.main > div {
width: 40px;
height: 40px;
margin: 5px;
background-color: coral;
}
.main > div.selected {
background-color: chocolate;
}
</style>
</head>
<body>
<div class="main">
<div></div>
<div></div>
<div></div>
</div>
<!-- JS -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
// Chaining method calls with jQuery
// The script below uses chaining in two forms
$(".main>div").click(function(event){
$(this).addClass("selected").siblings().removeClass("selected");
}).eq(0).addClass("selected");
// $(".main>div").click().eq(0).addClass()
/*
This line does the following:
- selects all child div's of .main and assigns a click
- filters the selection to the first element
- adds a class (which applies only to the first element)
*/
// $(this).addClass().siblings().removeClass();
/*
This line handles clicks by:
- selecting the current element
- adds a class
- filters the selection to the sibling elements
- remove a class name from all siblings
*/
</script>
</body>
</html>