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.

Irshad
  • 222
  • 4
  • 17
user3010474
  • 23
  • 1
  • 5

4 Answers4

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.

Community
  • 1
  • 1
Arqu
  • 419
  • 1
  • 6
  • 18
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.

Community
  • 1
  • 1
bishop
  • 37,830
  • 11
  • 104
  • 139
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);
Nate
  • 403
  • 4
  • 14
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.

meavo
  • 1,042
  • 1
  • 7
  • 16