Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-14
3
Medium Priority
?
620 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 1050 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

877 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