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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:15:58+00:00 2026-06-18T02:15:58+00:00

I have been wrangling with my code all day with no luck in solving

  • 0

I have been wrangling with my code all day with no luck in solving the problem.

My website has a series of images acting as navigation:

    <div id="thumbs">
    <a href="#" rel="images/edwards1.jpg" class="image"><img src="images/edwardsthumb1.jpg" class="thumb" border="0"/></a>
    <a href="#" rel="images/sample1.jpg" class="image"><img src="images/sample1thumb.jpg" class="thumb" border="0"/></a>
    </div>

when these are clicked, content is added to blank divs:

<div id="image">  <!-- main image container -->
</div>

<div id="gallerytext"> <!-- text box -->    
</div>

<div id="thumbset"> <!-- series of sub images/navigation -->
</div>

with this javascript:

        $(function() {
        var text = $('#gallerytext1').html();  <!-- blank divs are filled with content on page load -->
        $('#gallerytext').html(text);
        var thumbset = $('#thumbset1').html();
        $('#thumbset').html(thumbset);  
        $('#image').html('<img src="images/edwards1.jpg" border="0"/>');


  <!-- click handler -->

  $(".image").click(function() {    <!-- image variable is set when an image with class "image" is clicked -->
        var image = $(this).attr("rel"); <!-- each image has appropriate rel attribute to fill variable -->

    if (image == 'images/edwards1.jpg'){   <!-- different text and gallery loaded on click of specific image -->
        var text = $('#gallerytext1').html();
        $('#gallerytext').html(text);
        var thumbset = $('#thumbset1').html();
        $('#thumbset').html(thumbset);
        $('#thumbset').hide();
        $('#thumbset').fadeIn('slow');
    }

    if (image == 'images/sample1.jpg'){     <!-- different text and sub-gallery loaded on click of specific image -->
        var text = $('#gallerytext2').html();
        $('#gallerytext').html(text);
        var thumbset = $('#thumbset2').html();
        $('#thumbset').html(thumbset);
        $('#thumbset').hide();
        $('#thumbset').fadeIn('slow');
    }

    $('#image').hide();                 <!--  main image changed -->
    $('#image').fadeIn('slow');
    $('#image').html('<img src="' + image + '"/>');
    return false;

      });
      });

It works fine after the intial load, however if one of the “if” statements is triggered and the content is changed, images with the class .image within the div “thumbset” are now unclickable and the main image no longer changes. Images within the main navigation div: “thumbs” still work fine, and the “if” statements still go off.

all images are tagged and formatted as per the top code box in my post, and I cannot figure out why only images within “thumbset” decide to stop working.
I am very very green to Javascript, so any assistance will be greatly appreciated!

UPDATE: here is my updated code. Much cleaner now but the function is not working at all. I’m thinking the problem may be with the variable setting of “image” variable?

    $(document).ready(function() {
    var $doc = $(document.body);


        var text = $('#gallerytext1').html();  //blank divs are filled with content on page load 
        $('#gallerytext').html(text);
        var thumbset = $('#thumbset1').html();
        $('#thumbset').html(thumbset);  
        $('#image').html('<img src="images/edwards1.jpg" border="0"/>');


    //click handler
       $doc.on("click",".image",function(){

        var image=$(this).attr("rel"); 
        var imid=$(this).attr("data");
        var text=$('#gallerytext'+imid).html();
        var thumbset=('#thumbset'+imid).html();

        $('#debug').html(imid);

        $('#gallerytext').fadeIn('slow');
        $('#gallerytext').html(text);
        $('#thumbset').fadeIn('slow');
        $('#thumbset').html(thumbset);
        $('#image').hide();                 
        $('#image').fadeIn('slow');
        $('#image').html('<img src="' + image + '"/>');
        return false;


      });
  });
  • 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-18T02:15:59+00:00Added an answer on June 18, 2026 at 2:15 am

    use

    $(document).ready(function() {
    var $doc = $(document.body);
    $doc.on("click",".image", function() {//...
    

    then bind all events from the $doc (chain them if different selectors

    $doc.on(event,selector,function).on(ev,sel,fn)...
    

    or if multiple events on same selector

    $doc.on({
            ev : function(e) {},
            ev2 : function(e) {}
            //... 
            },selector).on()...
    

    to comment out in javascript use, it’ll comment what’s after in same line

    //
    

    instead of <!-- which is more meant to comment out html

    your code in spaghetti like with many repeated instructions,

    take out the common instructions in the if

    define a pattern so to avoid using if(stg==’sthg’)

    for example you could do

         <a ... data-idtoload="*id*">...
    

    then

        var imid=$(this).data("idtoload");
        var text = $('#gallerytext'+imid).html();  
        $('#gallerytext').html(text);
        var thumbset = $('#thumbset'+imid).html();
        //...
    

    no more if & your code is cut by 66%

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

Sidebar

Related Questions

Have been struggling all day trying to make this simple example work using socket.io.
Have been trying to figure this problem out for a while now and was
have been able to output images from BLOB, however I am now wanting to
Have been trying the whole day long and googled the **** out of the
So have been trying to automatically update SVN using this code/.exe: @echo off C:\Progrm
Have been hearing all around ArrayList getting obsolete these days. But I do have
Have been trying to find the error in one line of code. Return expected
Have been playing around with instruments with not much luck in figuring out how
Have been searching all over the internet but struggling to find my answer to
have been sitting with this problem for a few days and really can't seem

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.