Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Read about why website design really matters in today's demanding market.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

914 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

16 Experts available now in Live!

Get 1:1 Help Now