nextSibling





js/script.js
  • function funMake() {
  •  var val0 = document.getElementById('d1');
  •  val0.innerHTML = '<h3>' + document.getElementById('p1').nextSibling.innerHTML + '</h3>';
  •  var val1 = document.getElementById('d2');
  •  val1.innerHTML = '<h3>' + document.getElementById('p2').nextSibling.innerHTML + '</h3>';
  • }
  • function funMake() {
  •  var val0 = document.getElementById('d1');
  •  val0.innerHTML = '<h3>' + document.getElementById('p1').nextSibling.innerHTML + '</h3>';
  •  var val1 = document.getElementById('d2');
  •  val1.innerHTML = '<h3>' + document.getElementById('p2').nextSibling.innerHTML + '</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>
  •   <p>Привет Мир!</p>
  •   <p>To be or not to be?</p>
  •  </div>
  •  <div id="d1"></div>
  •  <div>
  •   <p id="p2">Hello World!</p><p>Привет Мир!</p><p>To be or not to be?</p>
  •  </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>
  •   <p>Привет Мир!</p>
  •   <p>To be or not to be?</p>
  •  </div>
  •  <div id="d1"></div>
  •  <div>
  •   <p id="p2">Hello World!</p><p>Привет Мир!</p><p>To be or not to be?</p>
  •  </div>
  •  <div id="d2"></div>
  •  <script>
  •   funMake();
  •  </script>
  • </body>
  • </html>