Last active
September 29, 2015 22:48
-
-
Save terkel/1681150 to your computer and use it in GitHub Desktop.
Detect IE and add classes to the <html> element
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
// 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