I'm in the process of designing a basic product page for my website.
HTML:
<div class="product-image">
<div class="product-large-image">
<img src="http://demo4coder.com/gosmart/pub/media/catalog/product/cache/image/600x600/e9c3970ab036de70892d86c6d221abfe/v/e/venus100_shoes3.jpg" alt="Product Title" id="large-image"></div>
<div class="product-small-image">
<img src="https://cf2.s3.souqcdn.com/item/2015/10/13/92/68/92/8/item_XL_9268928_10008769.jpg" alt="Product Title" id="small-image"></div>
<div class="product-small-image">
<img src="https://cf2.s3.souqcdn.com/item/2015/10/13/92/68/92/8/item_XL_9268928_10008754.jpg" alt="Product Title" id="small-image"></div>
<div class="product-small-image">
<img src="https://cf2.s3.souqcdn.com/item/2015/10/13/92/68/92/8/item_XL_9268928_10008769.jpg" alt="Product Title" id="small-image"></div>
<div class="product-small-image">
<img src="https://cf2.s3.souqcdn.com/item/2015/10/13/92/68/92/8/item_XL_9268928_10008754.jpg" alt="Product Title" id="small-image"></div>
</div>
CSS:
.product-large-image {
width: 100%;
border: 2px solid #ffac00;
text-align: center;
display: inline-block;
}
.product-large-image img {
width: 90%;
}
.product-small-image {
width: 19.38%;
border: 2px solid #ffac00;
margin-bottom: 5px;
display: inline-block;
text-align: center;
cursor: pointer;
}
.product-small-image img{
width: 90%;
}
I am looking to update the src attribute of the main image with the src attribute of the clicked small image.
JS (jquery):
$('#small-image').click(function(){
var imgsrc= $(this).attr('src');
$('#large-image').attr('src', imgsrc);
});
Currently, this only works when clicking on the first small image. I want it to work with any of the small images that are clicked.
You can view a live example of my code here:
https://jsfiddle.net/MohamedMehanny/dsahrLvn/2/