forked from MakeSchool-18/front-end-web-Q1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-siblings.html
54 lines (39 loc) · 1010 Bytes
/
jquery-siblings.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
<style>
div {
height: calc(100% / 12);
background-color: black;
margin: 1px;
}
body {
background-color: hsl(35, 90%, 55%);
}
</style>
<div></div>
<div style=""></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
/*
Use each() to loop through all elements in the collection.
Provide each() with a function which will be run on each
of the elements.
*/
// Add a click action to each div
$("div").click(function(){
// Clicking this div
$(this)
.css({backgroundColor:"black"}) // Sets the background color to black
.siblings() // filter the selection to siblings
.css({backgroundColor:"red"}); // set the background color to red for all siblings
});
</script>