Skip to content

Instantly share code, notes, and snippets.

@donabrams
Created July 5, 2011 13:32
Show Gist options
  • Save donabrams/1064841 to your computer and use it in GitHub Desktop.
Save donabrams/1064841 to your computer and use it in GitHub Desktop.
Add class ieX where X is version to enclosing html tag
(function () {
"use strict";
var browserClass = null;
if (navigator.appName === 'Microsoft Internet Explorer') {
if (navigator.appVersion.indexOf('MSIE 6', 0) !== -1) {
browserClass = "ie6";
} else if (navigator.appVersion.indexOf('MSIE 7', 0) !== -1) {
browserClass = "ie7";
} else if (navigator.appVersion.indexOf('MSIE 8', 0) !== -1) {
browserClass = "ie8";
} else if (navigator.appVersion.indexOf('MSIE 9', 0) !== -1) {
browserClass = "ie9";
}
}
if (browserClass) {
var htmlTag = document.getElementsByTagName("html")[0];
htmlTag.setAttribute("class", browserClass);
htmlTag.setAttribute("className", browserClass);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment