File tree 2 files changed +19
-8
lines changed
2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 3
3
// remember this element not read white space just element
4
4
// and not same with nextSibling read white space, read comment
5
5
6
- const result = document . querySelector ( '#result' ) ;
7
- console . log ( result . previousElementSibling ) ; //hohoho
6
+ const list_items = document . querySelector ( 'ul' ) ;
7
+ // previousElementSibling
8
+ list_items . previousElementSibling . style . background = 'blue' ;
9
+ // nextElementSibling ul > next or inside ul
10
+ // output <script src=........
11
+ const nextLi = list_items . nextElementSibling ;
12
+ console . log ( nextLi ) ;
8
13
9
- const last = document . querySelector ( '#last' ) ;
10
- const modification = last . previousElementSibling ;
11
- modification . style . fontSize = '2rem' ;
12
- modification . style . textTransform = 'uppercase' ;
14
+ const headingNext = document . querySelector ( 'h2' ) ;
15
+ // nextElement is ul and add background ul be red
16
+ headingNext . nextElementSibling . style . background = 'red' ;
Original file line number Diff line number Diff line change @@ -69,12 +69,19 @@ <h2>SHP Pirates</h2>
69
69
</ul>
70
70
</div> -->
71
71
72
- <!-- nextSibling & previousSibling -->
72
+ <!-- nextSibling & previousSibling
73
73
<div class="container">
74
74
<h3>sub title</h3>
75
75
<h2>main title</h2>
76
- </ div >
76
+ </div> -->
77
77
78
+ <!-- nextElementSibling & previousElementSibling -->
79
+ < h2 > The Pirates</ h2 >
80
+ < ul id ="list-item ">
81
+ < li class ="lutfy "> shp</ li >
82
+ < li > rhp</ li >
83
+ < li > marine ford</ li >
84
+ </ ul >
78
85
<!-- source js -->
79
86
<!-- <script src="/01_getElementById.js"></script> -->
80
87
<!-- <script src="/02_getElementByTagName.js"></script> -->
You can’t perform that action at this time.
0 commit comments