1ul = document.querySelector('ul');
2
3ul.insertAdjacentHTML('afterbegin','<li>Hello</li>');
4
5// <ul>
6// <li>Hello</li>
7// </ul>
1// <div id="one">one</div>
2var d1 = document.getElementById('one');
3d1.insertAdjacentHTML('afterend', '<div id="two">two</div>');
4
5// At this point, the new structure is:
6// <div id="one">one</div><div id="two">two</div>
1<!DOCTYPE html>
2<html>
3<body>
4
5<h1>HTML DOM insertAdjacentHTML() Method</h1>
6
7<p>This method inserts a specified text as HTML, into a specified position in the document.</p>
8
9<h2 id="myH2">My Header</h2>
10
11<p>Click the button to insert a paragraph after the header:</p>
12
13<button onclick="myFunction()">Insert a paragraph</button>
14
15<script>
16function myFunction() {
17 var h = document.getElementById("myH2");
18 h.insertAdjacentHTML("afterend", "<p>My new paragraph</p>");
19}
20</script>
21
22</body>
23</html>