Created
December 17, 2014 13:53
-
-
Save tfevens/4505057bec1f4a1d0b02 to your computer and use it in GitHub Desktop.
Simple function to swap an image on click.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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