Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery HTML classes for IE 10+
/*
* A hack to add classes to the HTML element (a la Paul Irish) for IE 10+
* IE 10 and over no longer support conditional classes. However, sometimes
* you still need to target IE above 9!
*/
jQuery( document ).ready( function( $ ) {
var html = $( html );
if ( /MSIE 1[01]\.\d+;/.test( navigator.userAgent ) || /Trident/.test( navigator.userAgent ) ) {
html.addClass( 'ie' );
if ( /MSIE 10\.\d+;/.test( navigator.userAgent ) ) {
html.addClass( 'ie10' );
html.addClass( 'lt-ie11' );
html.addClass( 'lt-ie12' );
}
if ( /MSIE 11\.\d+;/.test( navigator.userAgent ) ) {
html.addClass( 'ie11' );
html.addClass( 'lt-ie12' );
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.