How to Move Element AFTER an Element Using JavaScript

When using the “append” function in javascript it adds the new element AFTER a given element.

The challenge is finding the respective elements which are stored in TWO variables. See Below…

  • The first variable locates the element we want to move
  • The second variable locates the element we want to move the new element AFTER
var TargetElement = document.getElementsByClassName('product_meta')[0];
var NewLocation = document.querySelector("#tab-product-meta > h2");

We then add a simple script to make it all work… see below…

NewLocation.append(TargetElement);

Leave a Reply