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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:51:02+00:00 2026-06-02T17:51:02+00:00

The code that I have is getting a little long, I think there is

  • 0

The code that I have is getting a little long, I think there is a way to simplify it, take a look on it:

var slidernav = document.getElementsByTagName('li');
slidernavinital = 20;
slidernavadd = 30;
slidernav[0].style.top = slidernavinital + slidernavadd*0 + 'px';
slidernav[1].style.top = slidernavinital + slidernavadd*1 + 'px';
slidernav[2].style.top = slidernavinital + slidernavadd*2 + 'px';
slidernav[3].style.top = slidernavinital + slidernavadd*3 + 'px';
slidernav[4].style.top = slidernavinital + slidernavadd*4 + 'px';
slidernav[5].style.top = slidernavinital + slidernavadd*5 + 'px';
slidernav[6].style.top = slidernavinital + slidernavadd*6 + 'px';
slidernav[7].style.top = slidernavinital + slidernavadd*7 + 'px';
slidernav[8].style.top = slidernavinital + slidernavadd*8 + 'px';
slidernav[9].style.top = slidernavinital + slidernavadd*9 + 'px';
slidernav[10].style.top = slidernavinital + slidernavadd*10 + 'px';
slidernav[11].style.top = slidernavinital + slidernavadd*11 + 'px';

Isn’t possible to do Something like this:

document.getElementsByTagName('li')[x].style.top = 20 + 30*x + 'px';

Thanks a lot in advance!

  • 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-02T17:51:03+00:00Added an answer on June 2, 2026 at 5:51 pm

    Yes. Wrap it in a for loop.

    for(var i = 0; i < sliderNav.length; i++) {
        sliderNav[i].style.top = sliderNavInitial + sliderNavAdd*i + "px";
    }
    

    I think you should pick up an Intro to Programming book, though, if you didn’t know about loops (what’s the point of a computer if it doesn’t take care of the repetitive stuff for you?)

    EDIT: By the way, the for loop is shorthand for the following while loop construct:

    var i = 0;
    while(i < sliderNav.length) {
        sliderNav[i].style.top = sliderNavInitial + sliderNavAdd*i + "px";
        i++;
    }
    

    It just puts all of the “bookkeeping” on the first line of the loop so you can more easily predict how many times it will loop through. (A while loop just loops until the condition is met, and then stops, so if you forgot to include the i++; part, it will never stop.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting an error when I use the SharpZipLib. I have code that looks
I have the following code that creates the meta-description. I'm getting a 0 as
hey there guys and girls i have this code that saves json as a
Little question about Ruby error handling. I have some code that roughly resembles the
I am trying to setup a few fixes in some code that have caught
Here is the code that I have for my cell of my UITableView: forKeys:[NSArray
Here's the c# code that I have: private double get806Fees (Loan loan) { Loan.Fee.Items
Let's say that I have the following code that's run in one thread of
Here is the piece of code that I have used for Java 5.0 TreeSet<Integer>
I’m after some C# code that will have the following methods that will return

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.