Reputation: 9212
I'm using this to display a image of the product.
<div class='productImageWrap' id='productImageWrapID_16'>
<img src="abc.png" width='75' height='75' />
</div>
By clicking a button i want to change the image using JQuery. I have written this code for that. But its not working.
jQuery(document).ready(function($)
{
$('#mybtn').click(function()
{
$("productImageWrapID_16").attr("src", "xyz.png");
});
});
Can someone help me what is wrong in this.
Upvotes: 0
Views: 1518
Reputation: 3938
Try this:
$("#productImageWrapID_16 img").attr("src", "xyz.png");
Upvotes: 7
Reputation: 12452
if you use class to select use this:
$('.productImageWrap img').attr('src', 'abcd.png');
if you use id's use this:
$('#productImageWrapID_16 img').attr('src', 'abcd.png');
Upvotes: 0