Skip to content

Instantly share code, notes, and snippets.

@terkel
Last active September 29, 2015 22:48
Show Gist options
  • Save terkel/1681150 to your computer and use it in GitHub Desktop.
Save terkel/1681150 to your computer and use it in GitHub Desktop.
Detect IE and add classes to the <html> element
// Detect IE versions
// https://gist.github.com/527683
var ie = (function () {
var v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
do {
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->';
} while (all[0]);
return (v > 4)? v: void 0;
}());
// Add classes to the <html> element, like <html class="ie7 lt-ie8 lt-ie9">
ie && (function () {
var root = document.documentElement,
i,
classes = ['ie' + ie];
for (i = ie + 1; i <= 9; i++) {
classes[classes.length] = 'lt-ie' + i
}
root.className = root.className + ' ' + classes.join(' ');
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment