Skip to content

Instantly share code, notes, and snippets.

@magician11
Created September 1, 2015 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magician11/4991096810c8e441b2d2 to your computer and use it in GitHub Desktop.
Save magician11/4991096810c8e441b2d2 to your computer and use it in GitHub Desktop.
How to set a fallback image for a slider
<section class="slider">
<img src="andrew-and-artist.jpg" onerror='this.src="./andrew-and-artist.jpg"' />
<nav class="slider-nav">
<ul>
<li class="arrow">
<a href="#"><i class="fa fa-long-arrow-left"></i></a>
</li>
<li class="arrow">
<a href="#"><i class="fa fa-long-arrow-right"></i></a>
</li>
</ul>
</nav>
</section>
<script type="text/javascript">
$('.arrow').on('click', function(e) {
e.preventDefault(); // stop the page reloading
$('.slider img').prop('src', 'http://lorempixel.com/1000/600/abstract?' + Math.random());
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment