简体   繁体   中英

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)?

You can use insertBefore :

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

jsFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM