File tree Expand file tree Collapse file tree 2 files changed +28
-13
lines changed
Expand file tree Collapse file tree 2 files changed +28
-13
lines changed Original file line number Diff line number Diff line change 66// firstChild
77// lastChild
88
9- const result = document . querySelector ( '#result' ) ;
10- // output get 7 length include white space
11- console . log ( result . childNodes ) ;
9+ // CHILD
10+ const child = document . querySelector ( '#shp' ) ;
11+ //total 9 cz with white space
12+ console . log ( child . childNodes ) ;
13+ //total 4 li#member cz without space just element child
14+ // following all child in #shp :
15+ console . log ( child . children ) ;
1216
13- // if use children not include white space
14- console . log ( result . children ) ;
15- // output : h2.title, li , li
16- console . log ( result . children . length ) ; //3
17+ // example u should use child.children
18+ const allChild = [ ...child . children ] ;
19+ allChild . forEach ( function ( items ) {
20+ items . style . background = 'blue' ;
21+ } ) ;
1722
18- // firstChild & lastChild this gonna be text
19- console . log ( result . firstChild ) ;
20- console . log ( result . lastChild ) ;
23+ // first-child and last-child
24+ console . log ( child . firstChild ) ;
25+ console . log ( child . lastChild ) ;
Original file line number Diff line number Diff line change @@ -40,20 +40,30 @@ <h2>hello there</h2>
4040 </ul>
4141 </div> -->
4242
43- <!-- querySelector & querySelectorAll -->
43+ <!-- querySelector & querySelectorAll
44+ <h2>SHP Pirates</h2>
45+ <ul id="shp">
46+ <li id="members">lutfy</li>
47+ <li id="members">zoro</li>
48+ <li id="members">sanji</li>
49+ <li id="members">ussop</li>
50+ </ul> -->
51+
52+ <!-- children -->
4453 < h2 > SHP Pirates</ h2 >
4554 < ul id ="shp ">
4655 < li id ="members "> lutfy</ li >
4756 < li id ="members "> zoro</ li >
4857 < li id ="members "> sanji</ li >
4958 < li id ="members "> ussop</ li >
5059 </ ul >
60+
5161 <!-- source js -->
5262 <!-- <script src="/01_getElementById.js"></script> -->
5363 <!-- <script src="/02_getElementByTagName.js"></script> -->
5464 <!-- <script src="/03_getElementByClassName.js"></script> -->
55- < script src ="/04_querySelector.js "> </ script >
56- <!-- < script src="https://github.com/05_children.js"></script> -- >
65+ <!-- < script src="https://github.com/04_querySelector.js"></script> -- >
66+ < script src ="/05_children.js "> </ script >
5767 <!-- <script src="/06_parentElement.js"></script> -->
5868 <!-- <script src="/07_nextSibling_previous.js"></script> -->
5969 <!-- <script src="/08_nextElementSibling_previous.js"></script> -->
You can’t perform that action at this time.
0 commit comments