Chaminda Nuwan
Chaminda Nuwan

Reputation: 35

How to move an HTML tag after an id with JavaScript without using jQuery?

<div id="A"></div>
<div id="B"></div>

<div id="D"></div>
<div id="E"></div>


<div id="C"></div>`

How can I move <div id="C"></div> between id B and D with pure javascript (without JQuery)?

Upvotes: 1

Views: 87

Answers (1)

CodingIntrigue
CodingIntrigue

Reputation: 78525

You can use insertBefore:

var C = document.getElementById("C");
var D = document.getElementById("D");
D.parentElement.insertBefore(C, D);

jsFiddle

Upvotes: 4

Related Questions