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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:20:10+00:00 2026-05-27T14:20:10+00:00

In this example . By clicking on thumbnail , big images is getting changed.

  • 0

In this example . By clicking on thumbnail , big images is getting changed. I want to add border to selected thumbnail.

see example here http://jsfiddle.net/Qhdaz/2/

HTML

<div id="big-image">
    <img src="http://lorempixel.com/400/200/sports/1/">
    <img src="http://lorempixel.com/400/200/fashion/1/">
    <img src="http://lorempixel.com/400/200/city/1/">
</div>

<div class="small-images">
    <img src="http://lorempixel.com/100/50/sports/1/">
    <img src="http://lorempixel.com/100/50/fashion/1/">
    <img src="http://lorempixel.com/100/50/city/1/">
</div>

CSS

.small-images a, .big-images a {display:inline-block}
.small-images a.selected {border:1px solid red}

Current jQuery code

$(function(){
    $("#big-image img:eq(0)").nextAll().hide();
    $(".small-images img").click(function(e){
        var index = $(this).index();
        $("#big-image img").eq(index).show().siblings().hide();
    });
});
  • 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-27T14:20:10+00:00Added an answer on May 27, 2026 at 2:20 pm

    Your CSS is looking for a tags with the selected class not img tags:

    This:

    .small-images a.selected {border:1px solid red}
    

    Should change to:

    .small-images .selected {border:1px solid red}
    

    Other than that you just need to add and remove the selected class on click:

    $(function(){
        $("#big-image img:eq(0)").nextAll().hide();
        $(".small-images img").click(function(e){
            var $this = $(this),
                index = $this.index();
            $(".small-images img").removeClass('selected');
            $this.addClass('selected');
            $("#big-image img").eq(index).show().siblings().hide();
        });
    });
    

    Here is a demo: http://jsfiddle.net/Qhdaz/6/

    UPDATED

    I would suggest optimizing the code a bit by caching the $(".small-images img") selection since it will be used in each click event handler:

    $(function(){
        var $thumbnails = $(".small-images img");
    
        //this will add the `selected` class to the first thumbnail on-load
        $thumbnails.eq(0).addClass('selected');
        $("#big-image img:eq(0)").nextAll().hide();
        $thumbnails.click(function(e){
    
            //cache the `$(this)` selector since it will be used more than once
            var $this = $(this),
                index = $this.index();
    
            //remove `selected` class from all thumbnails
            $thumbnails.removeClass('selected');
            //add `selected` class to selected thumbnail
            $this.addClass('selected');
    
            $("#big-image img").eq(index).show().siblings().hide();
        });
    });
    

    Here is a demo: http://jsfiddle.net/Qhdaz/12/

    Here is your code optimized to run speedily:

    CSS–

    /*this will hide the full-sized images by default to take care of the flickering on-load*/
    #big-image img {
        display : none;
    }
    

    JS–

    $(function(){
    
        //cache both the thumbnails and the full-sized images so when we do work on them we don't have to wait for the performance hating selector to do it's magic
        var $thumbnails = $(".small-images img"),
            $fullsized  = $("#big-image img");
    
        //add `selected` class to first thumbnail
        $thumbnails.eq(0).addClass('selected');
    
        //show first full-sized image (no
        $fullsized.eq(0).show();
    
        //add `click` event handlers to all the thumbnails
        $thumbnails.click(function(e){
    
            //cache the `$(this)` selector since it will be used more than once
            var $this = $(this),
                index = $this.index();
    
            //remove the `selected` class from all thumbnails
            $thumbnails.removeClass('selected');
    
            //add the `selected` class to selected thumbnail
            $this.addClass('selected');
    
            //hide all the full-sized images and show the currently selected index
            $fullsized.hide().eq(index).show();
        });
    });
    

    Demo: http://jsfiddle.net/Qhdaz/13/

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

Sidebar

Related Questions

Good day! For this example of function html() http://api.jquery.com/html/ How to return to link
i have an asp.net mvc website. http:/mywebsite.com (just for this example) I have been
I need some simple calculations done using jquery. This example http://jsfiddle.net/tbL5r/ is pretty close.
I have two lists with images, Album and Favorites. When clicking on a thumbnail
I have been following this example http://demos.telerik.com/aspnet-mvc/grid/selectionclientside?theme=webblue , and have finished it for my
This example is from php.net: <?php function Test() { static $a = 0; echo
This example uses a StringWriter to hold the serialized data, then calling ToString() gives
This example is simplified a bit, but in my ASP.NET web page in my
this example below works when hover event is trigered and when its not, its
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT

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.