I am trying to change the src of an image when clicking on individual links (I only have 3).
So if I click on link #1, the src changes, if I click on link #2 it changes to something else, kind of like a basic image slider.
Here is a simplified example:http://jsfiddle.net/BVmUL/164/
the jquery I tried:
var images = [
"http://lorempixel.com/400/200/",
"http://linenwoods.com/images/kitten.png",
"http://linenwoods.com/images/third.png"
],
links = $("ol.list-inline > li > a"),
img = $("figure > img");
links.each(function(){
links.click(function(){
img.prop("src", images[links.index()]);
console.log($(this).index()); // only gives back 0 instead of 0,1,2 like
// I expected ...
});
});
How can I do something like this using jquery?