How do I detect IE with jQuery

Detect browser type and version using jQuery.

For all IE minor versions
if ($.browser.msie  && parseInt($.browser.version, 10) === 7) {
  alert('IE 7'); 
} else {
  alert('Non IE7');
}

if ($.browser.msie  && parseInt($.browser.version, 10) === 8) {
  alert('IE 8'); 
} else {
  alert('Non IE8');
}

if ($.browser.msie  && parseInt($.browser.version, 10) === 9) {
  alert('IE 9'); 
} else {
  alert('Non IE9');
}

Note: $.browser.msie undefined
$.browser have been removed from 1.9. You can use jQuery Migrate to have $.browser support.

Especially since $.browser has been removed from jQuery 1.9+.
<!--[if lt IE 7]> <html lang="en-us" class="no-js ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html lang="en-us" class="no-js ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html lang="en-us" class="no-js ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en-us" class="no-js"> <!--<![endif]-->

For javascript
<!--[if IE 8]>
<script type="text/javascript">
    ie = 8;
</script>
<![endif]-->

For other browser
if ($.browser.webkit) { 
    $('html').addClass('webkit');
}
if ($.browser.mozilla) { 
    $('html').addClass('mozilla');
}
if ($.browser.opera) { 
    $('html').addClass('opera');
}
How do I detect IE with jQuery How do I detect IE with jQuery Reviewed by Bhaumik Patel on 8:00 PM Rating: 5