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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:42:42+00:00 2026-05-11T09:42:42+00:00

I want to make a simple photo gallery function. However, there are some strange

  • 0

I want to make a simple photo gallery function. However, there are some strange behavior of JQuery’s click().

After the user clicks the forward button, 10 next images should be shown. After the user clicks the backward button, 10 previous images should be shown.

In the following code, 4 lines which works fine in my code are commented. I expect the JQuery click() should do the same thing as the commented lines, but it doesn’t. Code using JQuery click() doesn’t work after I click backward and forward several times. I want to ask where’s the problem of the code. Thank you.

<script type='text/javascript'> $(document).ready(function() {   var numImages = imagesObj.images.image.length; var imagePath = 'images/'; var currentIndex = 0;   function changeImageList(startIndex){      var imageIndex = 0;     $('#imagesList img').css('display','none');     for (var i=startIndex; i<numImages && i<startIndex + 10; i++)     {         var imageId = 'image' + imageIndex;         var image = imagesObj.images.image[i];          $('#' + imageId).attr('src',imagePath + image.imageurl).css('display','');          imageIndex++;     }      currentIndex = startIndex;     if (numImages > currentIndex+10){         $('#forward').css('cursor','pointer');         //document.getElementById('forward').onclick = function(){changeImageList(currentIndex+10);};         $('#forward').click(function(){  changeImageList(currentIndex+10);});     }else{         $('#forward').css('cursor','default');         //document.getElementById('forward').onclick = function(){};         $('#forward').click(function(){});     }      if (currentIndex < 10){         $('#backward').css('cursor','default');         //document.getElementById('backward').onclick = function(){};         $('#backward').click(function(){});     }else{         $('#backward').css('cursor','pointer');         //document.getElementById('backward').onclick = function(){changeImageList(currentIndex-10);};         $('#backward').click(function(){changeImageList(currentIndex-10);});      } }      changeImageList(0);  });   </script>  </head> <body> <table border='0' cellpadding='0' cellspacing='0'>       <tr>         <td align='center'><img id='backward' src='images/lft_arrow.gif' alt='' width='39' height='44' /></td>         <td id='imagesList' align='center'>         <img id='image0' width='77' style='display:none; cursor:pointer' />         <img id='image1' width='77' style='display:none; cursor:pointer' />         <img id='image2' width='77' style='display:none; cursor:pointer' />         <img id='image3' width='77' style='display:none; cursor:pointer' />         <img id='image4' width='77' style='display:none; cursor:pointer' />         <img id='image5' width='77' style='display:none; cursor:pointer' />         <img id='image6' width='77' style='display:none; cursor:pointer' />         <img id='image7' width='77' style='display:none; cursor:pointer' />         <img id='image8' width='77' style='display:none; cursor:pointer' />         <img id='image9' width='77' style='display:none; cursor:pointer' />         </td>         <td align='center'><img id='forward' src='images/rgt_arrow.gif' alt='' width='39' height='44' /></td>       </tr>     </table> </body> 
  • 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. 2026-05-11T09:42:42+00:00Added an answer on May 11, 2026 at 9:42 am

    This is the normal behaviour of event binding : when you call click, the event callback is added to the element and does not replace existing callbacks. When you click backward and forward buttons multiple times, you assign multiple handlers for the click event and now you know that this is bad 🙂

    There are two solutions to you problem :

    1. use eg $('#backward').unbind('click') before you assign a new event, this is the easy fix for your code.
    2. assign only one event to the buttons with a relative index, eg $('#backward').click(function(){ changeImageList(-10);});. I find it cleaner will a simple check at the beginning of changeImageList to calculate startIndex, but you’ll still have to set the cursor to default/pointer.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The configuration is in the code instead of config files,… May 11, 2026 at 1:56 pm
  • added an answer You could drop the primary key column and re-create it.… May 11, 2026 at 1:56 pm
  • added an answer IEnumerable<Type> GetTypesWith<TAttribute>(bool inherit) where TAttribute: System.Attribute { return from a… May 11, 2026 at 1:56 pm

Related Questions

I want to make a really simple iphone app: one screen with a single
I want to make a table that simply has two integer columns to serve
The subject says it all... I simply want Xcode to make a beep or
I want to make a table in SqlServer that will add, on insert, a
I want to make a copy of an ActiveRecord object, changing a single field
I know this won't be a popular question, because a lot of web designers
When creating a setup/MSI with Visual Studio is it possible to make a setup
I want to make a dropdown menu like delicious has at this http://delicious.com/search?context=all&p=sql&lc=1 page.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.