Skip to content

Commit 3cf92dc

Browse files
committed
nodeValue & textContent
1 parent aba7bbc commit 3cf92dc

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

09_textContent.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// textContent get content text
2+
3+
const item = document.querySelector('#title');
4+
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);

index.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,19 @@ <h5 id="title-2">The heading two</h5>
6767
//
6868
nextElementSibling, previousElementSibling
6969
-->
70-
<ul class="list-items">
70+
<!-- <ul class="list-items">
7171
<li>ubuntu</li>
7272
<li id="first">manjaro</li>
7373
<li>debian</li>
7474
<li class="last">crunchbang</li>
7575
</ul>
7676
77-
<h1>hello</h1>
77+
<h1>hello</h1> -->
78+
79+
<!-- textContent -->
80+
<div class="container">
81+
<h2 id="title">The heading 2</h2>
82+
</div>
7883

7984
<!-- source js -->
8085
<!-- <script src="/01_getElementById.js"></script> -->
@@ -84,6 +89,7 @@ <h1>hello</h1>
8489
<!-- <script src="/05_parentElement.js"></script> -->
8590
<!-- <script src="/06_childNodes.js"></script> -->
8691
<!-- <script src="/07_nextSibling_previous.js"></script> -->
87-
<script src="/08_nextElementSibling_previous.js"></script>
92+
<!-- <script src="/08_nextElementSibling_previous.js"></script> -->
93+
<script src="/09_textContent.js"></script>
8894
</body>
8995
</html>

0 commit comments

Comments
 (0)