Solved

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

Posted on 2004-10-14
3
594 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
[X]
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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

617 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