Last active
December 26, 2017 20:13
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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