I want to update the src of an image depending on a link that I click with jquery. I have four links and an image displayed above.
If I click on the first link, I want the src of the image to change of the first element of the container array. It should increment like that until reaching the last element of the array.
What is the best way to do this basic approach?
<figure>
<img src="http://lorempixel.com/g/400/200/" />
<figcaption>
<nav>
<a href="#">Image One</a>
<a href="#">Image Two</a>
<a href="#">Image Three</a>
<a href="#">Image Four</a>
</nav>
</figcaption>
</figure>
jquery:
$(function(){
var container = [
"http://lorempixel.com/g/400/200/",
"http://lorempixel.com/g/400/200/",
"http://lorempixel.com/g/400/200/",
"http://lorempixel.com/g/400/200/"
];
var i;
$("nav a").on("click", function(){
for(i = 0; i < 4; i++) {
$("img").attr("src", container[i]);
}
});
});