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

  • Home
  • SEARCH
  • 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 8979075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:45:46+00:00 2026-06-15T19:45:46+00:00

Okay – I am trying to reverse loop through the <li> contained in an

  • 0

Okay – I am trying to reverse loop through the <li> contained in an unordered list. During this loop I want to remove each <li> and then compare the height of it’s parent column to that of an adjacent column until it is =< the other. Once this is true break the loop and display remaining <li>. Before this happens I am using shuffle.js to shuffle the list. I have been able to capture the height of both columns but my code seems to be messed up once I start looping through the <li>

Here is the HTML short version…

<body>  
  <div id="wrap">
        <div id="header"></div>
             <div id="main">This is the column that would set the height that determines the amount of [li] shown
            </div>
        <div id="sidebar">
            <ul id="shuffleunorderedlist">
                <li id="promo_1">
                    1
                </li>
                <li id="promo_2">
                    2
                </li>
                <li id="promo_3">
                    3
                </li>
                <li id="promo_4">
                    4
                </li>
                <li id="promo_5">
                    5
                </li>
                <li id="promo_6">
                    6
                </li>
                <li id="promo_7">
                    7
                </li>
                <li id="promo_8">
                    8
                </li>
                <li id="promo_9">
                    9
                </li>
                <li id="promo_10">
                    10
                </li>
                <li id="promo_11">
                    11
                </li>
                <li id="promo_12">
                    12
                </li>

            </ul>
        </div>
<div id="footer"></div>

And here is the jQuery and Javascript I have written so far.

<script type="text/javascript">
jQuery(function($)
{
    window.onload = function()
    { 
        $('#shuffleunorderedlist').shuffle();   //********** Shuffle List 
    };
    var mainHeight = $('#main').height();   //********** Capture 'main' height 
    var sidebarHeight = $('#sidebar').height();     //********** Capture 'sidebar'     height 
        if (mainHeight > sidebarHeight)     //********** Compare 'sidebar' height 
            {
                var liCheck = $('div#sidebar.li').reverse().each(function ()    //********** reverse Loop through <li>'s  
                    {
                    while(liCheck())
                        {
                           $('li').hide(); //********** reverse Loop through <li>'s 
                             if (sidebarHeight =< mainHeight) 
                                    {
                                    break;  // breaks loop completely   //**********  Output <li>'s that are left 
                                    }
                        }  
                    }   
            }               
});
</script>

So basically why isn’t this working? Where am I breaking it? How can I get it to work?

Any suggestions, Help and answers are greatly appreciated.

  • 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-06-15T19:45:47+00:00Added an answer on June 15, 2026 at 7:45 pm

    Your code was riddled with problems, so instead of detailing them all, compare your code to this:

    var mainHeight = $('#main').height();
    var sidebarHeight = $('#sidebar').height();
    if (mainHeight < sidebarHeight) { // You are hiding things from the sidebar correct? Strictly speaking, this check isn't necessary, but it prevents us from looping when we don't need to. 
        $('div#sidebar li').each(function() {  // I removed reverse as it gave me a reference error. If it is defined for you, feel free to use it. 
            if (sidebarHeight > mainHeight) {  
                $(this).hide();  // hide only the current element
                sidebarHeight = $("#sidebar").height(); // update sidebarHeight 
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I'm trying to reverse engineer a feature on a website I found -
Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay I've spent the last hour trying to find a solution to this but
okay so I have two arrays $array_one([a]=>2,[b]=>1,[c]=>1); $array_two([a]=>1,[b]=>2,[c]=>1); I want to be able to
Okay, so I'm not even sure how to ask this question (much less search
Okay,I've been following this tutorial http://coenraets.org/blog/android-samples/androidtutorial/ Basically it gives me exactly what i need
Okay so I currently have: /(#([\]))/g; I want to be able to check for
Okay, I'm a little fuzzy on how this works or if it's possible. I
Okay so im working on this php image upload system but for some reason
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my

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.