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.
Your code was riddled with problems, so instead of detailing them all, compare your code to this: