A Pen by Richard Oliver on CodePen.
Created
November 20, 2014 13:26
-
-
Save yodiyo/a1b879838db307a6f27b to your computer and use it in GitHub Desktop.
ZYYvEQ
This file contains hidden or 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
<button>Use img data</button> | |
<p class="img-container"> | |
<img src="https://cms.espresso.co.uk/servlet/file/store9/item756914/version9/fileservice28/756914_28_preview.jpg" data-image="https://cms.espresso.co.uk/servlet/file/store9/item756914/version9/fileservice29/756914_29_preview.jpg"/> | |
</p> | |
<p class="img-container"> | |
<img src="https://cms.espresso.co.uk/servlet/file/store9/item757379/version5/fileservice28/757379_28_preview.jpg" data-image="https://cms.espresso.co.uk/servlet/file/store9/item757379/version5/fileservice29/757379_29_preview.jpg"/> | |
</p> |
This file contains hidden or 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
$( "button" ).click(function() { | |
applyImgData(); | |
}); | |
applyImgData = function(){ | |
$.each($(".img-container img"), function( index, value ) { | |
var imgSrc = $(value).data("image"); | |
$(value).attr("src", imgSrc); | |
}); | |
} | |
This file contains hidden or 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-container{ | |
img{ | |
width: 450px; | |
border: 1px solid red; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment