Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

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. …
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.
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.
Suggested Courses

715 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