parentNode





js/script.js
  • function funMake() {
  •  var str = document.getElementById('p1').parentNode.nodeName;
  •  document.getElementById('d2').innerHTML = '<h3>' + str + '</h3>';
  • }
  • function funMake() {
  •  var str = document.getElementById('p1').parentNode.nodeName;
  •  document.getElementById('d2').innerHTML = '<h3>' + str + '</h3>';
  • }


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  •  <div>
  •   <p id="p1">Hello World!</p>
  •   <h4>Привет Мир!</h4>
  •   <div>To be or not to be?</div>
  •  </div>
  •  <div id="d2"></div>
  •  <script>
  •   funMake();
  •  </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  •  <div>
  •   <p id="p1">Hello World!</p>
  •   <h4>Привет Мир!</h4>
  •   <div>To be or not to be?</div>
  •  </div>
  •  <div id="d2"></div>
  •  <script>
  •   funMake();
  •  </script>
  • </body>
  • </html>