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.
-
Sorry. Forgot to add fiddle. I have edited and added it.Bobby Francis Joseph– Bobby Francis Joseph2012-03-30 12:27:39 +00:00Commented Mar 30, 2012 at 12:27
-
want to something like this : jsfiddle.net/KMFj2/8Jignesh Rajput– Jignesh Rajput2012-03-30 12:29:06 +00:00Commented Mar 30, 2012 at 12:29
Add a comment
|
3 Answers
Try this
$("#myimg").attr('src', "/myNEWimage.jpg");
where ofcourse you get the path specified from somewhere in a variable
1 Comment
Steen
jsfiddle.net/KMFj2/13 - Note the change in when the jquery is loaded (didn't work with the previous setting - should resemble real world use though)
I have updated your fiddle
1 Comment
Abel
Please update your answer such that the Q and A can be read and understood in the thread. It's better to copy a (small) piece of code here that explains what you did and why you did it. Now it's unfortunately impossible for others to read and understand the solution...