HTML DOM insertAdjacentElement() Method

<!DOCTYPE html>
<html>
<body>

<h1>HTML DOM insertAdjacentElement() Method</h1>

<p>This method inserts a specified element, into a specified position.</p>

<span style="color:red">My span</span>

<h2 id="myH2">My Header</h2>

<p>Click the button to insert the red span after the header:</p>

<button onclick="myFunction()">Move span</button>

<script>
function myFunction() {
  var s = document.getElementsByTagName("span")[0];
  var h = document.getElementById("myH2");
  h.insertAdjacentElement("afterend", s);
}
</script>

</body>
</html>

0
7
Awgiedawgie 440220 points

                                    &lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

&lt;h1&gt;HTML DOM insertAdjacentHTML() Method&lt;/h1&gt;

&lt;p&gt;This method inserts a specified text as HTML, into a specified position in the document.&lt;/p&gt;

&lt;h2 id=&quot;myH2&quot;&gt;My Header&lt;/h2&gt;

&lt;p&gt;Click the button to insert a paragraph after the header:&lt;/p&gt;

&lt;button onclick=&quot;myFunction()&quot;&gt;Insert a paragraph&lt;/button&gt;

&lt;script&gt;
function myFunction() {
  var h = document.getElementById(&quot;myH2&quot;);
  h.insertAdjacentHTML(&quot;afterend&quot;, &quot;&lt;p&gt;My new paragraph&lt;/p&gt;&quot;);
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
document.head.insertAdjacentHTML( html insertadjacenthtml .insertAdjacentHTML property html inserAdjacenthtml js html insertAdjacentHTML dom insertadjacenthtml how does insertadjacenthtml work in javascript insertAdjacentHTML what is insertAdjacentHTML html insertadjacenthtml properties in javascript javascript insertAdjacentHTML before start js addAdjacentElement() javascript insertadjacent html insertAdjacentHTML js insertAdjacentElement() js insertAdjecenthtml document insertadjacenthtml .insertAdjacentHTML() document.body.insertadjacenthtml html insert adjacent element insertadjacentelement js insertadjecentelement js what is insertadjacenthtml in javascript insertAdjacentElement Javscript open html tag insertadjacentHTML insertAdjacentElement( insertAdjacentHTML() JS insertAdjacentElement w3 insertadjacenthtml insertAdjacentHTML al js insertadjacenthtml mdn javascript insertadjacentelement explain insert adjacent html in javascript .insertAdjacentElement() javascript .insertAdjacentElement insertAdjacentHTML inside insertAdjacentHTML insertadjacenthtml javascript w3schools javascript DOM, insertAdjacentElement insertAdjacentHTML(&quot;beforeend&quot;, ); node.insertAdjacentHTML javascript insertadjacenthtml insertadjacenthtml in js with example insertadjacenthtml in js document.insertadjacenthtml .insertadjacenthtml HTML DOM insertAdjacentHTML and delete insertadjacenthtml w3schools js insertadjacenthtml javascript insertAdjecentHTML what is the the use of insertadjacenthtml in java script document.head.insertAdjacentHTML insertadjacentelement javascript JavaScript insertAdjacentElement &amp; insertAdjacentHTML insertadjacenthtml in javascript insertadjacentelement in javascript insertadjacenthtml javascript insertAdjacentHTML HTML DOM insertAdjacentElement() Method HTML DOM insertAdjacentHTML() Method
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source