Skip to content

Instantly share code, notes, and snippets.

@yodiyo
Created November 20, 2014 13:26
Show Gist options
  • Save yodiyo/a1b879838db307a6f27b to your computer and use it in GitHub Desktop.
Save yodiyo/a1b879838db307a6f27b to your computer and use it in GitHub Desktop.
ZYYvEQ
<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>
$( "button" ).click(function() {
applyImgData();
});
applyImgData = function(){
$.each($(".img-container img"), function( index, value ) {
var imgSrc = $(value).data("image");
$(value).attr("src", imgSrc);
});
}
.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