Change the order of HTML element by jQuery?

javascript, jquery

Solution

If you refer to the API documentation, you'll find the `insertBefore` function:

$("#be_top").insertBefore("#t1");

Live Example | Source

Or of course, you could do it the other way around with `insertAfter`:

$("#t1").insertAfter("#be_top");

Live Example | Source

An hour spent reading the API documentation beginning to end (and it really only takes that long) is hugely rewarding, saving you a lot of time over even just a brief period.

Problem

I'd love to change the order of HTML elements from: ``` <div id="d1"> <div id="dd1"></div> <table id="t1"></table> <div id="be_top"></div> </div> ``` to: ``` <div id="d1"> <div id="dd1"></div> <div id="be_top"></div> <table id="t1"></table> </div> ``` Does anyone have ideas about how to do this? Thanks!

Original source