+ 1
How to swap html elements with JavaScript?
For example we have 2 div elements with id's "div1" and "div2". In the original html div2 goes after div1, but how to swap them with js?
1 Resposta
+ 4
You remove div1 and create it again.
var div = document.getElementById("div1");
div.remove();
div = document.createElement("div");
div.setAttribute("id", "div1");
document.getElementById("parent").appendChild(div);