Automatically control div order, regardless of where its in the code

Posted on 2004-10-14
Last Modified: 2006-11-17
I have 3 divs that I need to show up in a certain order, regardless of how they are ordered in the code.  For instance,

<div class="order2">
   Text 2

<div class="order3">
   Text 3

<div class="order1">
   Text 1

needs to be displayed in the browser as


I know that I can use CSS to absolutely position the divs to change the order of the divs, but the content in the div's may be a different size so Im not sure it will work.  My question is:

How can I use CSS to control to ensure that the output reads as Text 1,Text 2,Text 3....regardless of how the HTML div's are ordered?
Question by:soBC
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 12310948
instead of absolute positioning, you could use javascript to play with their innerhtml instead. use the id attribute of DIVs. In your javascript code, you can find the position and thus determine which id is placed at the first position. replace its innerHTML with the innerHTML of the DIV whose text you want to display first. Hope I'm clear..

Author Comment

ID: 12312369
I understand what you're talking about, I think.  Any chance you could direct me to a simple example?
LVL 18

Accepted Solution

arantius earned 350 total points
ID: 12312667
it will always be three?  can you put them in a container div?


<div id="cont">
      <div id="order2">
        Text 2
      <div id="order3">
        Text 3
      <div id="order1">
        Text 1


var c=document.getElementById("cont");
var d1=document.getElementById("order1");
var d2=document.getElementById("order2");
var d3=document.getElementById("order3");


Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Code Coverage and Coding Standards 2 81
Word Press Fixes to Google Speed Test Issues 2 50
wordpress 4.7.4, theme 8 43
Selenium cssSelector and attribute 5 13
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question