• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>JavaScript Node Access</title>
7
</head>
8
​
9
<body>
10
​
11
    <h1 id="heading">nodeValue 프로퍼티</h1>
12
    <p id="text1">텍스트</p>
13
    <p id="text2">텍스트</p>
14
    
15
    <script>
16
        // 아이디가 "heading"인 요소의 첫 번째 자식 노드의 노드값을 선택함.
17
        var headingText = document.getElementById("heading").firstChild.nodeValue;
18
        
19
        document.getElementById("text1").innerHTML = headingText;
20
        document.getElementById("text2").firstChild.nodeValue = headingText;
21
    </script>
22
    
23
</body>
24
​
25
</html>