Instantly share code, notes, and snippets.

@kamichimo /.html
Last active Aug 29, 2015

Embed
What would you like to do?
画像が見つからなかった場合にデフォルト画像に置き換える
<!-- 置き換えたいimg要素のclassにreplace-noimgを指定する -->
<img class="replace-noimg" src="/library/images/step1.png" alt="">
jQuery(document).ready(function($) {
$('.replace-noimg').error(function() {
$(this).attr({
src: '/library/images/noimg.jpg', //デフォルト画像のURL
alt: 'no image'
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment