Skip to content

Instantly share code, notes, and snippets.

@michsch
Last active April 24, 2016 16:24
Show Gist options
  • Save michsch/769ce07b7ccb6aa8799175aa240acea1 to your computer and use it in GitHub Desktop.
Save michsch/769ce07b7ccb6aa8799175aa240acea1 to your computer and use it in GitHub Desktop.
Replace no-js class in HTML element
<html class="no-js" lang="de">
<head>
<meta charset="utf-8">
<title>JS class in HTML</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/main.css">
<script>
!function(s,e){'use strict';s=document.getElementsByTagName('html')[0],e=s.className.split(' '),e.indexOf('no-js')>-1&&e.splice(e.indexOf('no-js'),1),-1===e.indexOf('js')&&e.push('js'),s.className=e.join(' ')}()
</script>
</head>
<body>
<h1>Writ <pre><code>js</code></pre> class.</h1>
</body>
(function () {
'use strict';
var html, classes;
html = document.getElementsByTagName('html')[0];
classes = html.className.split(' ');
if (classes.indexOf('no-js') > -1) {
classes.splice(classes.indexOf('no-js'), 1);
}
if (classes.indexOf('js') === -1) {
classes.push('js');
}
html.className = classes.join(' ');
})();
!function(s,e){'use strict';s=document.getElementsByTagName('html')[0],e=s.className.split(' '),e.indexOf('no-js')>-1&&e.splice(e.indexOf('no-js'),1),-1===e.indexOf('js')&&e.push('js'),s.className=e.join(' ')}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment