treehouse : what would you like to learn today?
Web Design Web Development iOS Development

JavaScript Required Content with Fallback Content

Last updated on:

JavaScript-required area is hidden with inline CSS, and then shown after it loads with a small snippet of JavaScript. Below that, noscript tags are used for fallback content. So only one or the other of these bits of content will be required depending on if JavaScript is enabled or not.

<!-- JavaScript-Required Content -->
<div id="photoslider" style="display:none">Javascript photoslider</div>
<script>document.getElementById('photoslider').style.display='';</script>
<!-- END JavaScript-Required Content -->

<!-- Fallback Content -->
<noscript><div id="photo">Alternative static photo as content when javascript is turned off</div></noscript>
<!-- END Fallback Content -->
View Comments

Comments

  1. This code makes me happy! So simple, but so effective!

  2. stine
    Permalink to comment#

    Nice tip! thanks

Leave a Comment

Use markdown or basic HTML and be nice.