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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:06:45+00:00 2026-05-31T18:06:45+00:00

I am doing an image gallery viewer, with little thumbnails, one medium-sized viewer, and

  • 0

I am doing an image gallery viewer, with little thumbnails, one medium-sized viewer, and if you click on that viewer, it fadeIn a div that displays image in full size.

Here is a screenshot:

Image

My problem is that when I click on a little thumbnail, then I click on the medium-sized photo, i.e. mediumpic (in order to fadeIn() the invisible div), jQuery fails in executing html() and fadeIn(). However, it works only when document is ready (that is, with photo#1 that was loaded in the viewer by default). But when I click on any of those little thumbnails, it ruins it. What is happening there?

My HTML is the following:

echo "<div class='largepic_div'></div>";
echo "<div class='viewer'><img class='mediumpic'src='upload/photos/".$dbphoto1."'></div>
echo "<div class='allpics'>";

echo "<div class='thumbnail_viewer'><img class='thumbnail_item' 
src='upload/photos/".$dbphoto1."' height='60'></div>";

echo "<div class='thumbnail_viewer'><img class='thumbnail_item' 
src='upload/photos/".$dbphoto2."' height='60'></div></div>";

My jQuery is the following:

$(document).ready(function() {

$('.thumbnail_item').click(function(){

    $('.viewer').html("<img class='mediumpic' src='upload/photos/"+ $(this).attr('src').split('/')\[2\] +"'>");

    });

$('.mediumpic').click(function(e){
    e.stopPropagation();
    $('.largepic_div').html("<img src='upload/photos/"+ $(this).attr('src').split('/')\[2\] +"'>").fadeIn();

    });

$('body').click(function(){
        $('.largepic_div').fadeOut();
        }); 
});
  • 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-31T18:06:46+00:00Added an answer on May 31, 2026 at 6:06 pm

    You are assigning the click handler to mediumpic on document ready, but when you click the thumbnail, you are removing the img element and replace it by a new one… therefore the handler is no longer attached.

    You can either attach the handler again after you click on the thumbnail, or keep the original element and just replace the src of the img element (instead of using .html()).

    UPDATE 1:

    Method 1:

    $('.thumbnail_item').click(function(){
        $('.viewer').html("<img class='mediumpic' src='upload/photos/"+ $(this).attr('src').split('/')\[2\] +"'>");
        $('.mediumpic').click(mediumpicHandler);
    });
    
    $('.mediumpic').click(mediumpicHandler);
    
    var mediumpicHandler = function(e){
        e.stopPropagation();
        $('.largepic_div').html("<img src='upload/photos/"+ $(this).attr('src').split('/')\[2\] +"'>").fadeIn();
    }
    

    Method 2:

    $('.thumbnail_item').click(function(){
        $('.viewer img').attr("src","upload/photos/"+ $(this).attr('src').split('/')\[2\]);
    });
    

    Warning: I didn’t actually test the above code… it’s just an idea on where to take it.

    UPDATE 2:

    I just showed how to fix the problem with the thumbnail/medium pic interaction… you would need to apply the same fix to the medium/large pic interaction too.

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

Sidebar

Related Questions

I'm doing photo gallery and like to enlarge an image when I click on
I'm doing a little gallery of images and for each image I wanna tell
I am very new to grails.I am doing one sample project for image uploading
I'm building an application that is an image gallery but with lots of images
I'm having trouble to integrate the Galleria image gallery plugin onto one of my
I'm trying to combine the capability of doing image zoom/panning inside of a Gallery
I have an image gallery within a Drupal site that uses the 'Image Gallery'
I currently have a div that acts like a gallery so to speak. div
So I'm trying to build a gallery that displays images from a folder on
I am doing some image sampling. What my question is, is there a 'crosshair'

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.