tags:

views:

508

answers:

3

Hey,

I have a jquery scroller i made with thumbnails and I am trying to create a mini script.

When a user clicks on the thumb nail, it updates code like this:

<div id="big_image">
    <img src="HERE.jpg" alt="my image"/>
</div

So when you click a thumbnail on the scroller it updates the SRC of the IMG tag on the page? Any ideas how I can get started?

Thanks,

Ryan

+2  A: 
$('#scroller img').click(function() {
    $('#big_image img').attr('src', whatever_full_size_image_src_is_for(this));
}
chaos
The difference between this answer and my answer is actually ">" character in the selector. > means select this direct children instead of all the descendants which means in my example only child imgs will be selected rather than all of descendants.
Braveyard
While that is true, Aaron, I don't suspect #big_picture to hold more than a single IMG as its child, based on the ID being singular.
Jonathan Sampson
+1  A: 
// Replace larger image with src of whatever thumbnail you clicked
$("img.myImage").click(function(){
  $("img.bigImage").attr("src", $(this).attr("src"));
});

Note, unless you're crushing large images into thumbnail sizes, this won't be a very elegant solution to your problem. And in all honesty, if you are crushing large images into thumbnail sizes, that also isn't a very good solution.

Jonathan Sampson
What do you recomend if i want to say add some text to the full size image meaning image-name-full.jpg, to show the large images, then have thumbnails.
Coughlin
A: 
 function updateImage()
 { 
   $("#big_image > img").attr("src","imagePath"); 
 }

you can use this function in thumbnail onclick event.

Braveyard