Sometimes you want to selectively display certain elements on a webpage depending on whether or not the user has Javascript enabled. Here's a neat trick to do so!
Add the
no-jsclass to thehtmlelement:<html class="no-js"> ... </html>Load the following Javascript code:
document.documentElement.classList.remove("no-js"); document.documentElement.classList.remove("js");Include the following CSS:
:root.no-js .when-js { : none !important; } :root.js .when-no-js { : none !important; }
Now you can add the when-js/when-no-js class to elements to only show it when Javascript is enabled/disabled!