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();
});
});
Your CSS is looking for
atags with theselectedclass notimgtags:This:
Should change to:
Other than that you just need to add and remove the
selectedclass on click: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 eachclickevent handler:Here is a demo: http://jsfiddle.net/Qhdaz/12/
Here is your code optimized to run speedily:
CSS–
JS–
Demo: http://jsfiddle.net/Qhdaz/13/