Skip to content
Advertisement

JavaScript moving element in the DOM

Let’s say I have three <div> elements on a page. How can I swap positions of the first and third <div>? jQuery is fine.

Advertisement

Answer

Trivial with jQuery

JavaScript

If you want to do it repeatedly, you’ll need to use different selectors since the divs will retain their ids as they are moved around.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement