File tree 2 files changed +17
-14
lines changed
2 files changed +17
-14
lines changed Original file line number Diff line number Diff line change 1
1
// nextSibling
2
2
// previousSibling
3
- // remember return white space too
3
+ // remember return white space too and comment html
4
4
5
- const li_one = document . querySelector ( 'li' ) ;
6
- // index 1 be red
7
- li_one . nextSibling . nextSibling . style . color = 'red' ;
8
- // index 2 be blue
9
- li_one . nextSibling . nextSibling . nextSibling . nextSibling . style . color = 'blue' ;
5
+ const nextSubtitle = document . querySelector ( 'h3' ) ;
6
+ // h2 main-title if one nexSibling result #text
7
+ // cause nextSibling read white space too remember!
8
+ console . log ( nextSubtitle . nextSibling . nextSibling ) ;
10
9
11
- // use previous
12
- const last = document . querySelector ( '#last' ) ;
13
- console . log (
14
- ( last . previousSibling . previousSibling . style . textTransform = 'uppercase' )
15
- ) ;
10
+ const previousTitle = document . querySelector ( 'h2' ) ;
11
+ // h3 sub-title
12
+ console . log ( previousTitle . previousSibling ) ;
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ <h2>SHP Pirates</h2>
58
58
<li id="members">ussop</li>
59
59
</ul> -->
60
60
61
- <!-- parentElement -->
61
+ <!-- parentElement
62
62
<div class="container">
63
63
<h2>SHP Pirates</h2>
64
64
<ul id="shp">
@@ -67,6 +67,12 @@ <h2>SHP Pirates</h2>
67
67
<li class="members">sanji</li>
68
68
<li class="members">ussop</li>
69
69
</ul>
70
+ </div> -->
71
+
72
+ <!-- nextSibling & previousSibling -->
73
+ < div class ="container ">
74
+ < h3 > sub title</ h3 >
75
+ < h2 > main title</ h2 >
70
76
</ div >
71
77
72
78
<!-- source js -->
@@ -75,9 +81,9 @@ <h2>SHP Pirates</h2>
75
81
<!-- <script src="/03_getElementByClassName.js"></script> -->
76
82
<!-- <script src="/04_querySelector.js"></script> -->
77
83
<!-- <script src="/05_children.js"></script> -->
78
- < script src ="/06_parentElement.js "> </ script >
84
+ <!-- < script src="/06_parentElement.js"></script> -- >
79
85
<!-- <script src="/07_nextSibling_previous.js"></script> -->
80
- <!-- < script src="/08_nextElementSibling_previous.js"></script> -- >
86
+ < script src ="/08_nextElementSibling_previous.js "> </ script >
81
87
<!-- <script src="/09_textContent.js"></script> -->
82
88
<!-- <script src="/10_getAttribute.js"></script> -->
83
89
</ body >
You can’t perform that action at this time.
0 commit comments