Reputation: 600
Is it possible to change the src of a image at runtime using jQuery. I have created a fiddle. I am trying to load the image specified in the variable $newsrc when the button is clicked. I am not sure as to what should be specified an argument function changeImage(). I do not want to use anonymous function.
http://jsfiddle.net/bobbyfrancisjoseph/KMFj2/5/
Upvotes: 0
Views: 1426
Reputation: 17640
This should do the trick:
$('#image_id').click(function() {
$(this).attr('src', "/new_image.jpg");
});
Upvotes: 1
Reputation: 2877
Try this
$("#myimg").attr('src', "/myNEWimage.jpg");
where ofcourse you get the path specified from somewhere in a variable
Upvotes: 3