Solved

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

Posted on 2004-10-14
3
553 Views
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>

<div class="order3">
   Text 3
</div>

<div class="order1">
   Text 1
</div>

needs to be displayed in the browser as

Text1
Text2
Text3

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?
0
Comment
Question by:soBC
3 Comments
 
LVL 3

Expert Comment

by:kumvjuec
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..
0
 

Author Comment

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

Accepted Solution

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

<html>
<head>
</head>
<body>

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

</div>

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

c.removeChild(d1);
c.removeChild(d2);
c.removeChild(d3);
c.appendChild(d1);
c.appendChild(d2);
c.appendChild(d3);
</script>
</body>
</html>
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now