onclick change Image src jQuery

Something Like that:
onclick change Image src

First we will see normal html code.
For that you need to create first html code.

HTML

<div class="product_gallery"><a href="https://cdn3.iconfinder.com/data/icons/picons-social/57/10-html5-128.png">Change Image</a><img src="https://cdn4.iconfinder.com/data/icons/file-names-24/512/38-128.png"/><a href="https://cdn4.iconfinder.com/data/icons/file-names-24/512/38-128.png">Back Again Image</a></div>

Use jQuery Library.

After that add this JQuery code.

JS

$('.product_gallery a').click(function(){
$('.product_gallery img').attr('src',$(this).attr('href'));
return false;
});

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”dzjEby” default_tab=”html,result” user=”pradeepanvi”]See the Pen onclick change Image src jQuery by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

Leave a Reply

Your email address will not be published. Required fields are marked *