Devesh Agrawal
Devesh Agrawal

Reputation: 9212

How to update image using jquery

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

Answers (2)

Max Brodin
Max Brodin

Reputation: 3938

Try this:

$("#productImageWrapID_16 img").attr("src", "xyz.png");

Example

Upvotes: 7

Razvan Dumitru
Razvan Dumitru

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

Related Questions