Skip to content

Instantly share code, notes, and snippets.

@tfevens
Created December 17, 2014 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tfevens/4505057bec1f4a1d0b02 to your computer and use it in GitHub Desktop.
Save tfevens/4505057bec1f4a1d0b02 to your computer and use it in GitHub Desktop.
Simple function to swap an image on click.
$('img.swap').click(function() {
var src = ($(this).attr('src'));
var swap = ($(this).data('swap'));
$(this).attr('src', swap );
$(this).data('swap', src );
});
// <img src="images/pic1.jpg" data-swap="images/pic2.jpg" class="swap">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment