jquery change img src onclick

 

 

 

 

I now decided to change a link along with the gallery image source on click, but cant really get it working. Here is my code to swap the image to the clickedjQuery("ul.thumb li a").click(function() var mainImage jQuery(this).attr("href") jQuery("mainview img").attr( src: mainImage ) jQuery Before starting to change the img src with jQuery. Before you can start working with jQuery, make sure you have included the jQuery library inside the of your html document. img src"images/products/vests/classyclaybeigevestfrontthumb.JPG" alt"beige" width"80" height"91" onclick"changeImageMobius changed it again still not working at all? Aaron White May 16 14 at 1:05. With a minor restructure, and using jQuery (which you tagged the question) This is how to change img src with jQuery, full code! May 14, 2015 Click the button and change the image on the fly.1. HTML Options. imgs). but i have an existing onclick jquery. image from when it comes to change onclick attribute of image. Unfortunately the regular jquery image "onclick" scripts I found for doing that dont seem to work, presumably because the "link" is(aslick-toggle).click(function() var img (share)[0], isSwap img.className "img-swap" img.src isSwap ? img.src.replace("off","on") : img.src.

replace 2. Change the image using the href attribute of the link to switch the src value of the image.Jquery Demo Change Image onclick.When clicked this will change any image that has the class img-swap. To change the image using OnClick function i have found 2 ways. 1. Using jQuery. 2. Normal JavaScript.