So,i have this http://jsfiddle.net/ithril/UjGhE/1/ Please check it out.
What i'm trying here is to change the main image img tag's src dynamically to the same src attribute of the image that is clicked. In short whichever image is clicked,it is displayed in the bigger window which has an id="main-photo".
Change this part of your JS code:
to:
It should work fine. Eg: http://jsfiddle.net/UjGhE/23/
All you have to do is remove the
href
attribute from your links. When clicked, this causes the page to reload. However, this attribute is also responsible for the cursor to turn into a pointer, so you'll have to manually assign one in CSS:a { cursor: pointer }
Clicking on the img's now would load said image in your main image holder, without the page reloading, which caused your problem.
I would clean up the html if i were you though, cause there are a lot of unclosed tags.
I see my original code has made it this far :) Because nobody has gotten accept, I will try my best. I will again give you some pointers on general matter:
<a>
) are unclosed. This will surely generate a validation error. You can train your html skills be validating yourself regularly (sounds dirty right?).main-photo img {}
theposition:relative:
is not closed with ;'.slider-large-image li img {}
,margin: 10px
was not closed!NOTES
Live demo
http://jsfiddle.net/hobobne/K439d/
Full version code:
It's really simple to do this using jQuery. When the user clicks on an
<img>
tag, you'll have access tothis
inside the callback function. Simply take$(this).attr('src')
and set the source of$('#main-photo')
to it like so:-
It looks like in your code, you're using
.main-photo img
, which should also work. I'm looking at it more now.-
EDIT, after reviewing your code, you seem to have many missing
</a>
s along with other errors. Here is an updated and working version (minus the CSS and extra javascript):