CSS that depends upon JavaScript — Amit Merchant — A blog on PHP, JavaScript, and more

0
20

If there are two things without which you can not imagine a modern website, these must be JavaScript and CSS and most of the time, both of these can co-exist and work perfectly in isolation.

But there might be some scenarios where one of these technologies can be dependent on one another.

Adam Argyle has recently explained a scenario where it’d be nice if we can control the CSS when the JavaScript is disabled in the browser.

The idea here is to use the Noscript element <noscript> that defines a section of HTML to be inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser.

So, for instance, if we want some CSS to be inserted only when the scripting is turned off in the client’s browser, here’s how we can do it.

<noscript>
  <style>
    .hide-if-no-js 
        display: none;
    
  </style>  
</noscript>

This can come in handy in certain situations. Like Adam mentioned, we can hide arrow control from a scroller when the scripting is turned off and show it otherwise!

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here