Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6930617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:28:13+00:00 2026-05-27T11:28:13+00:00

I have 6 divs on a page which are dynamically placed into 2 columns

  • 0

I have 6 divs on a page which are dynamically placed into 2 columns depending on the content they have in it. In this case – some divs get placed into left column and some placed in the right column – all depending on the height of the div. I would like to grab all the divs placed in the left column or right column. I’m looking for a way to add a class for all the left column divs to distinguish between the right column divs? Is it possible to use a selector in jQuery to achieve this?

 function fixPAPanelHeights()
    {
        var column1Height = 0;
        var column2Height = 0;
        var panel1Item;
        var panel2Item;

        var panelCount = 0;

        $j("div.panelItr").each(function() {
            panelCount++;
            if ($j(this).hasClass("panel2Column"))
                {
                    if (column1Height > column2Height)
                    {
                        $j(panel2Item).css("height", $j(panel2Item).innerHeight() + column1Height - column2Height + (5 * (((panelCount - 1) / 2) - 1)));
                    }
                    else if (column2Height > column1Height)
                    {
                        $j(panel1Item).css("height", $j(panel1Item).innerHeight() + column2Height - column1Height + (5 * (((panelCount - 1) / 2) - 1)));
                    }
                    column1Height = 0;
                    column2Height = 0;
                    panelCount = 0;
                }
            else
                {           
                    if (panelCount%2 == 1)
                    {                   
                        $j(this).css("float", "left");
                                    pos = $j(this).offset();


            $j(this).css({ "left": (pos.left) + "px"});
                            panel1Item = $j(this);              
                            column1Height += $j(this).innerHeight();                
                        }
                        else
                        {

                            $j(this).css("float", "left");
                    panel2Item = $j(this);
    pos = $j(this).offset();
        $j(this).css({ "left": (pos.left) + "px"}); 


                        column2Height += $j(this).innerHeight();

                    }
                }

         });

Note: The if ($j(this).hasClass(“panel2Column”)) condition tests whether there is a div long enough to occupy both the columns and does some calculation based on it. We are concerned about the else case where all the divs have same width and possibly can occupy either left column or right column.

UPDATE:

Kind of figured out a solution for identifying in which column the divs are placed. Since its a 2 column and only 2 possible left positions for the div, the below code helps.

within the else condition above:

var dataHolder = $j("div.panelItr").first().offset().left;
else{
    if($j(this).offset().left == dataHolder){
                    $j(this).addClass("leftColumn");
                }
                else{
                    $j(this).addClass("rightColumn");
                }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:28:14+00:00Added an answer on May 27, 2026 at 11:28 am

    Kind of figured out a solution for identifying in which column the divs are placed. Since its a 2 column and only 2 possible left positions, below code would help.

    var dataHolder = $j("div.panelItr").first().offset().left;
    
    if($j(this).offset().left == dataHolder){
                    $j(this).addClass("leftColumn");
                }
                else{
                    $j(this).addClass("rightColumn");
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few links on a page which refers to some content divs
I have some dynamic content which covers up to 3 page and I want
We have an HTML page which displays a bunch of pretty bars using divs
I have a script which hides (display:none) certain divs in the list on page
I have three Divs on the page and they are absolute positioned. Lets call
I have a page with a couple of divs, sort of like this: <div
I have the 2 divs on a page which I need to animate up
I have some divs on a page that are hidden via jquery when the
I have a page which will contain 4 static divs with IDs. I will
I have a page which loads divs of rounded corners. And on each div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.