Search code examples
javascripthtmlnoscript

How to hide parts of HTML when JavaScript is disabled?


I'm trying to accommodate users without JavaScript. (By the way, is it worth the effort nowadays?)

In one HTML file I'd like part of it execute if scripts are on, and another part if scripts are OFF.

The <noscript> tag lets me do the former, but how to achieve the latter? How can I mark a part of HTML so that it is not parsed by browser if scripts are off?


Solution

  • here's a video tutorial on how this can be done with jQuery: http://screenr.com/ya7

    Code:

    <body class="noscript">
    <script>
    $('body').removeClass('noscript');
    </script>
    </body>
    

    And then just hide the relevant elements under body.noscript accordingly.

    edit However, JQuery might be bloated for a small fix like this one, so I suggest Zauber Paracelsus' answer since it does not require JQuery.