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 7739843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:37:26+00:00 2026-06-01T08:37:26+00:00

Newbie here! My problem is as follows: I have a dynamically populating ul where

  • 0

Newbie here! My problem is as follows: I have a dynamically populating ul where each li item contains 5 absolutely positioned inner divs. Like this:

<ul id="slider">
 <li class="slide">
   <div class="pic1"></div>
   <div class="pic2"></div>
   <div class="pic3"></div>
   <div class="pic4"></div>
   <div class="pic5"></div>
 </li>
 <li class="slide">
   <div class="pic1"></div>
   <div class="pic2"></div>
   <div class="pic3"></div>
   <div class="pic4"></div>
   <div class="pic5"></div>
 </li>
 //more li items...
</ul>

Each one of these absolutely positioned divs uses a sibling’s height to calculate its final position with jQuery. The horizontal (left, right) properties are applied directly through css. I tried using the each method for each pic class to set the css, like these examples:

var pic2 = new Array();
$('.slide .pic2').each(function(i) {
    pic2.push($(this).siblings('.pic1').find('img').height(); 
    $(this).css({ top : pic2[i] + 10 });
});

var pic4 = new Array();
$('.slide .pic4').each(function(i) {
    pic4.push($(this).siblings('.pic3').find('img').height(); 
    $(this).css({ top : pic4[i] + 10 });
});

But I think there must be a simpler, more compact way to do this, as this seems like too complicated and also it breaks in IE7 and IE8, I noticed. Maybe a for loop for example that will create a multidimensional array and will apply the css to each item according to certain if statements, or perhaps using the .position method? Any ideas? Thank you!

—- Edit to add Answer for Future newbies like myself:

Using Shasteriskt’s answer I was able to streamline my ugly each functions and also add certain parameters according to class, like this:

$('.slider li').children('div').each(function(i,picItem){
       if ( $(this).hasClass('pic2') ) {
            var top = $(picItem).prev().find('img').height();
            $(picItem).css({top: top + 100});
       }
      if ( $(this).hasClass('pic5') ) {
            var top = $(picItem).prev().find('img').height();
            $(picItem).css({top: top + 60});
       }
      else {
           var top = $(picItem).prev().find('img').height();
           $(picItem).css({top: top + 10});
      }
   });

Thank you, Shasteriskt! Lots of chocolate cookies for you! 🙂

  • 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-01T08:37:27+00:00Added an answer on June 1, 2026 at 8:37 am

    Any reason why you need to push each value into the array? Unless you need to use it after, I don’t think you really need it.

    You can streamline this as follows:

       $('.slider li').children('div:odd').each(function(i,picItem){
           var top = $(picItem).prev().find('img').height();
           $(picItem).css({top: top + 10});
       });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im newbie here.I have a problem with codeigniter segment() method.I referred 6th segment of
Newbie here, I have a struct for a word, which contains a char array
I seem to have a probably newbie problem but here it is. How do
Super newbie at Javascript here. I have a problem with whitespace that I'm hoping
Java Newbie here. I have a JFrame that I added to my netbeans project,
.NET newbie here... I'd like to make a button in a Windows form that
REAL newbie here to Objective C and Cocoa. I have this 'if statement' if
c# newbie here. seems like this user gave me a very good solution for
Java, ANTLR and Netbeans newbie here. I have installed a jdk and netbeans. I
Annoying newbie problem here. This variable isPlayerTouchingAnotherPlayer is being set to true as soon

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.