JavaScript
Article
By Sam Deering

Use CSS to Hide Content when JavaScript is Turned Off

By Sam Deering

Use CSS to Hide Content when JavaScript is Turned Off

This is a tip first seen by Karl Swedberg in one of this jQuery books where you can add a JS class to your HTML attribute when jQuery has loaded like so:

$('HTML').addClass('JS');

Then by using CSS to initially hide the elements, like this:

--ADVERTISEMENT--

.JS #myDiv{display:none;}

They will only appear when JavaScript is enabled.

It is also worthy to note that altough JS can be turned off you will still be able to see the HTML markup(and search engine spiders also see this!). But nevertheless, a nifty little trick!

Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account