1var d1 = document.getElementById('one');
2d1.insertAdjacentHTML('afterend', '<div id="two">two</div>');
3
1
2
3
4
5 function insertAfter(newNode, existingNode) {
6 existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
7}
1<!DOCTYPE html>
2<html>
3<body>
4 <p id='up'>Up</p>
5 <p id="down">Down</p>
6 <button id="switchBtn" onclick="switch_place()">Switch place</button>
7 <script>
8 function switch_place(){
9 var downElement = document.getElementById("down")
10 var upElement = document.getElementById("up")
11 downElement.after(upElement);
12 document.getElementById('switchBtn').innerHTML = "Switched!"
13 }
14 </script>
15</body>
16</html>