0

I'm not talking about floating, nor z-index (which is used to put one above the other). I'm talking about changing the order that a DIV is displayed through Javascript.

For example, I have:

<div id='bottom'></div>
<div id='header'></div>

I want to change the order so the 'header' will be displayed above the 'bottom', but not "overlaying" it, neither "floating". Just:

<div id='header'></div>
<div id='bottom'></div>

It is a simple question that haven't been asked before, I guess.

2
  • 1
    I'm a little confused on what you are asking. Do you mean the way you insert the html with javascript into the DOM? Commented Nov 19, 2013 at 20:21
  • I think this might help you: stackoverflow.com/questions/558614/reorder-divs Commented Nov 19, 2013 at 20:29

4 Answers 4

0

You could work with this Remove element by id where you remove the first one (save it to some variable first) and then append it using appendChild() in JS or append() in jQuery if you're using the framework. That should effectively swap places of the two.

EDIT: Take a look at this it basically is the same question you asked for, with an answer containing code and everything else you might need. Seems like you didn't search good enough.

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

Comments

0

Perhaps this previous answer: Reordering of Divs, which shows a pure-Javascript way and a jQuery way to re-arrange the divs. Googling "rearrange div" also proves fruitful.

Comments

0

It depends on the javascript library you use but if you use jquery, this can easily be done. Just type the following:

var header = $('#header');
$('#bottom').next().remove;
$('#bottom').before(header);

Comments

0

You can do this with CSS only using flexbox depending on the browsers you want to support. Otherwise you can go for the javascript solution like mentioned by others already.

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.