Run

Tutorial With Example

Run your live code

 
20
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8">
5
<title>Javascript Replacing Existing Elements in DOM</title>
6
​
7
</head>
8
<body>
9
  <div id="main">
10
      <h1 id="title">My Heading</h1>
11
      <p id="hint"><span>This is some text.</span></p>
12
  </div>
13
​
14
  <script>
15
    var hint = document.getElementById("hint");
16
    alert(hint.parentNode.nodeName); // Outputs: DIV
17
    hint.parentNode.style.backgroundColor = "yellow";
18
  </script>
19
</body>
20
</html>