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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:59:40+00:00 2026-05-30T09:59:40+00:00

Right now I have a image gallery that changes images when a user clicking

  • 0

Right now I have a image gallery that changes images when a user clicking on a thumbnail image the appropriate div’s style changes to block and the rest are hidden. I want to be able to add next/previous buttons for additional navigation.

My thought was to use getElementByAttribute to find the only image with the ‘style=”display:block”‘, and then somehow add/subtract one to the div. But I am afraid I’m at a loss. Any advice?

Current code:

<div id="image1" style="display:block"><img src="resources/images/larges/01.jpg"></div>
<div id="image2" style="display:none"><img src="resources/images/larges/02.jpg"></div>
. . .

<img style='cursor:pointer;' onclick="showDiv(1)" src="resources/images/thumbs/01.jpg">
<img style='cursor:pointer;' onclick="showDiv(2)" src="resources/images/thumbs/02.jpg">
. . .

<script type = "text/javascript">       
   function showDiv(which) {
    for(i = 0; i < 13; i++) {
       document.getElementById("image"+i).style.display="none";
    }
       document.getElementById("image" + which).style.display = "block";
    }   
</script>
  • 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-30T09:59:42+00:00Added an answer on May 30, 2026 at 9:59 am

    you can declare a global variable

    var currentImage = 1; //assuming the 1st image shown is always the first
    

    then, you add two buttons,

    <button type="button" onclick="showDiv(currentImage - 1)">Previous</button>
    <button type="button" onclick="showDiv(currentImage + 1)">Next</button>
    

    on your function you update the currentImage with the given param

    function showDiv(which) {
       for(i = 0; i < 13; i++) {
          document.getElementById("image"+i).style.display="none";
       }
       //in the next 2 lines, you make sure which isn't lower than 1, and isn't greater than the number of images
       if(which < 1) which = 1;
       if(which > 13) which = 13;
       document.getElementById("image" + which).style.display = "block";
       currentImage = which;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have an SSIS package that runs every morning and gives me
Right now I have a JSP page that allows to sort some items, when
Right now I have a table called Campaigns that has many Hits, if I
As of right now, in my app I have created a rudimentary gallery app
I have a image that I want to display a DIV on the bottom
Right now I have the following code set up: $(function() { $('.thumbnail').mouseenter(function() { $('.thumbnail').fadeOut(200,
I have a gallery of images that I'm ajaxing in and I'd like to
Right now I have some code that generates <li> elements that have a height
I have an array like this. int image[] = {R.drawable.d002_p001,R.drawable.d002_p002,R.drawable.d002_p003, R.drawable.d002_p004,R.drawable.d002_p005,R.drawable.d002_p006}; Right now I
Good day! I right now have a function the drags an element from a

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.