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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:08:47+00:00 2026-05-22T22:08:47+00:00

I have a bunch of div’s like <div class=slides> <div id=box_bg> <div class=previous></div> <img

  • 0

I have a bunch of div’s like

            <div class="slides">
                <div id="box_bg">
                    <div class="previous"></div>
                    <img src="images/minido_pic.png" width="267" height="252" alt="MiniDo" class="img1" />
                    <div class="next"></div>
                </div>
                <div id="text1">
                    <p>MiniDo - Adobe Air App - Simplistic design wrapped around a simple iOS style window built for the Windows environment using Adobe Air.</p>
                </div>
            </div>

and a bunch of jquery

$(document).ready(function(){   
    $(".slides").hide();

        var length = $(".slides").length;
        var ran = Math.floor(Math.random()*length);
        $(".slides:nth-child(" + ran + ")").show();

    $('.previous').click(function() {
        $(".slides").parentsUntil(".slides").prev().show();
        $('.slides').hide();
    });

    $('.next').click(function() {
        $(this).parentsUntil(".slides").next().show();
        $('.slides').hide();
    });
});

Now what I want to so is on page load, show a random “.slides” which works fine. And then when a user presses “.next” or “.previous” it loads the next “.slides”.

However I can’t seem to get it to work? When I press next or previous it shows nothing?

Any help?

  • 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-22T22:08:47+00:00Added an answer on May 22, 2026 at 10:08 pm

    You should use

    for previous

    $(this).closest('.slides').prevAll('.slides').eq(0).show();
    

    and for next

    $(this).closest('.slides').nextAll('.slides').eq(0).show();
    

    And the most important is to hide the .slides before you show the next one.

    So the $('.slides').hide(); should be before the .show() commands otherwise, you just show the one you want and then hide all (including the one you just showed)


    Altogether

    $('.previous').click(function() {
        $('.slides').hide();
        var previous = $(this).closest('.slides').prevAll('.slides').eq(0);
        if (previous.length === 0) previous = $(this).closest('.slides').nextAll('.slides').last();
        previous.show();
    });
    
    $('.next').click(function() {
        $('.slides').hide();
        var next = $(this).closest('.slides').nextAll('.slides').eq(0);
        if (next.length === 0) next = $(this).closest('.slides').prevAll('.slides').last();
        next.show();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of elements like the following: <div class=droppableP id=s-NSW style=width:78px; height:63px;
I have a bunch of divs like this: <div class=bear></div> <div class=dog></div> How do
I have a bunch of elements that look like.. <div id=hi> <div class=head> </div>
I have a bunch of divs that are all hidden like this <div class=elements>
I have whole bunch of <div class=productlistname><a href=#>The Text!</a></div> . What I want to
I have a bunch of images that are in a hidden div. The div
I have a bunch of elements like this: <div></div> <span></span> <table></table> <div></div> <span></span> <div></div>
I have a bunch of photos in an array. <div> <img id=photo1> <img id=photo2>
I have a bunch of div's: <div class='option'> <span>here is a label for one
I have a bunch of these on a page: <div class=item id=555> <div class=wrapper>

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.