Posted By

EvanHahn on 03/12/12


Tagged

css javascript class html detection modernizr


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dop3


Remove "no-js" class from html tag, add "js" class


 / Published in: HTML
 

Add the "no-js" class to your topmost html element, so you can use CSS to style JavaScript-free pages. This snippet will then replace that tag with "js", allowing you to style pages with JavaScript.

The excellent HTML5 Boilerplate puts no-js in the <html> element and then uses Modernizr to replace it with js. If you don't want to use all of that stuff, this snippet does the same thing.

  1. <html class="no-js">
  2.  
  3.  
  4. document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/g, '') + ' js ';
  5. </script>
  6.  
  7. <!-- ... -->

Report this snippet  

You need to login to post a comment.