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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:32:32+00:00 2026-05-25T10:32:32+00:00

So, I’m using this lovely image swap fellow: jQuery Image Swap Gallery You can

  • 0

So, I’m using this lovely image swap fellow:

jQuery Image Swap Gallery

You can see a demo of it in action on my site here: http://hannahnelsonteutsch.com/v2/art-piece.php

The problem is, with the #main_image img

<div id="main_image" class="grid_7">
    <img class="wide" src="zImages/arrows-2.jpg" />
</div>

note the class=”wide”. there are two classes that need to be applied dynamically to the images, once they’re “swapped”: “wide” and “tall”, based on whether we’re using an image that is in portrait or landscape.

The nice thing, which I have a hunch that a superior coder could make use of, is that the thumbnails for each image already have the correct class assigned to them:

<img class="tall" src="zImages/arrows-1.jpg" />
<img class="wide" src="zImages/arrows-2.jpg" />
<img class="wide" src="zImages/arrows-3.jpg" />
<img class="tall" src="zImages/arrows-4.jpg" />
<img class="tall" src="zImages/arrows-5.jpg" />

Here is the jQuery that is generating the image-swap:

$(document).ready(function() {
    // Image swap on hover
    $("#details img").hover(function(){
        $('#main_image img').attr('src',$(this).attr('src').replace());
        // This is my failed attempt to assign  
        // the correct class to the #main_img img:
        $('#main_image img').attr('class',$('#details img').attr('class').replace(this));
    });
    // Image preload
    var imgSwap = [];
     $("#details img").each(function(){
        imgUrl = this.src.replace();
        imgSwap.push(imgUrl);
    });
    $(imgSwap).preload();
});
$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}

Note two things:

  1. The original tutorial has this line of code:

    $('#main-img').attr('src',$(this).attr('src').replace('thumb/', ''));
    

    which i’ve replaced with this:

    $('#main_image img').attr('src',$(this).attr('src').replace());
    

    the key being the .replace(‘thumb/’, ”) vs .replace().

    We’re using CSS to shrink the images which significantly speeds up image load times upon hover. i.e. the images have already been loaded because we’re using the same image for the thumbs and main image.

  2. my own attempt to answer this question has not worked

    $('#main_image img').attr('class',$('#details img').attr('class').replace(this));
    

So, that’s where I’m at. Anyone have any ideas to solve this ?

Thanks so much for your time.

Cheers,
Jon

  • 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-25T10:32:32+00:00Added an answer on May 25, 2026 at 10:32 am

    You need to use the $(this) selector so jquery knows which image you are hovering over. Also you should probably use mouseenter instead of hover as you only need to verify the mouse position once. Finally, got rid of replace() in your function as that wasn’t doing anything. By using attr and changing the src or class you are replacing the value automatically. Here’s a draft I set up of your page: http://jsfiddle.net/AjBDg/2/

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.