File tree 2 files changed +18
-15
lines changed
2 files changed +18
-15
lines changed Original file line number Diff line number Diff line change 1
- // textContent get content text
1
+ // textContent for getText
2
+ // same with childNodes
2
3
3
- const item = document . querySelector ( '#title' ) ;
4
+ const useChildNodes = document . querySelector ( 'h3' ) ;
5
+ // only childNodes get index node-list, so use []
6
+ // if not will undefined
7
+ // if not use nodeValue will write like "Hello people"
8
+ console . log ( useChildNodes . childNodes [ 0 ] . nodeValue ) ;
4
9
5
- // use nodeValue
6
- // u should .nodevalue if not will use ""
7
- const node_values = item . childNodes [ 0 ] . nodeValue ;
8
- console . log ( node_values ) ;
9
- // output : The heading 2
10
-
11
- // use textContent
12
- const getText = item . textContent ;
13
- console . log ( getText ) ;
10
+ // but for efisien use textContent
11
+ const useTextContent = document . querySelector ( 'h2' ) ;
12
+ console . log ( useTextContent . textContent ) ;
Original file line number Diff line number Diff line change @@ -75,13 +75,17 @@ <h3>sub title</h3>
75
75
<h2>main title</h2>
76
76
</div> -->
77
77
78
- <!-- nextElementSibling & previousElementSibling -->
78
+ <!-- nextElementSibling & previousElementSibling
79
79
<h2>The Pirates</h2>
80
80
<ul id="list-item">
81
81
<li class="lutfy">shp</li>
82
82
<li>rhp</li>
83
83
<li>marine ford</li>
84
- </ ul >
84
+ </ul> -->
85
+
86
+ <!-- textContent and childNodes -->
87
+ < h3 > Hello people</ h3 >
88
+ < h2 > Hello World</ h2 >
85
89
<!-- source js -->
86
90
<!-- <script src="/01_getElementById.js"></script> -->
87
91
<!-- <script src="/02_getElementByTagName.js"></script> -->
@@ -90,8 +94,8 @@ <h2>The Pirates</h2>
90
94
<!-- <script src="/05_children.js"></script> -->
91
95
<!-- <script src="/06_parentElement.js"></script> -->
92
96
<!-- <script src="/07_nextSibling_previous.js"></script> -->
93
- < script src ="/08_nextElementSibling_previous.js "> </ script >
94
- <!-- < script src="/09_textContent.js"></script> -- >
97
+ <!-- < script src="/08_nextElementSibling_previous.js"></script> -- >
98
+ < script src ="/09_textContent.js "> </ script >
95
99
<!-- <script src="/10_getAttribute.js"></script> -->
96
100
</ body >
97
101
</ html >
You can’t perform that action at this time.
0 commit comments