Skip to content

Instantly share code, notes, and snippets.

@JonMcL
Last active December 26, 2017 20:13
Show Gist options
  • Save JonMcL/596c29b92449aa54f5a5c54b60ef6853 to your computer and use it in GitHub Desktop.
Save JonMcL/596c29b92449aa54f5a5c54b60ef6853 to your computer and use it in GitHub Desktop.
Simple Javascript to force 'js' class into document root as soon as <head> is loaded and parsed. This happens before CSS and before JS assets are loaded. Also removes 'no-js' if it is there.
<script type="text/javascript">
var root = document.documentElement;
if (root.classList) {
root.classList.add('js');
root.classList.remove('no-js');
}
else {
root.className += ' js';
var regex = new RegExp('(\\s|^)' + 'no-js' + '(\\s|$)');
el.className = root.className.replace(regex, ' ');
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment