Is there a HTML tag that does the opposite of <noscript>? That is, displays some content only if JavaScript is enabled? For example:
<ifscript>
<h1> Click on the big fancy Javascript widget below</h1>
<ifscript>
Of course <ifscript> doesn’t actually exist. I know I could achieve the same result by adding <h1> to the DOM using JavaScript, but if I’d prefer to do this with (X)HTML if possible.
Thanks,
Donal
There the
<script>is for. Just initially hide the particular piece using CSS and use JavaScript to display it. Here’s a basic kickoff example:…or, with little help of jQuery
ready()which is a tad sooner with displaying the content:To improve user experience, consider placing the
<script>call directly after the particular HTML element which needs to be toggled, so that there’s no “flash of content” or “element shuffle”. Andrew Moore has given a good example in this topic.Alternatively, you can do it (hacky) the other way round with
<style>in<noscript>. This is syntactically invalid, but allowed by all browsers from IE6 and up, including the W3C-strict Opera: