3

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!

3 Answers 3

9

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.

Sign up to request clarification or add additional context in comments.

Comments

2
// select thing you want to move #be_top -> insert it before #t1
$("#be_top").insertBefore("#t1")

Comments

0

Alternatively, You can use appendTo also in JQuery.

Ex :

var nav = $('#t1').clone(true);
$('#t1').remove();
nav.appendTo('#be_top');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.