Browser detection vs. feature detection
$.browser
is deprecated from jQuery for a reason (since 1.3). Using it for stuff like you wanted to use it for is not a recommended practice. If you are depending on a certain feature, test for that feature (this is called feature detection, $.support
is one way to do this) instead of testing for a specific browser.
Conditional Comments
If you really need to target old IE, use conditional comments (can easily be removed when old IEs do not exist anymore and does not bloat other browsers unnecessarily):
<!--[if IE 8]>
<script src="my_ie8_specific_stuff.js"></script>
<![endif]-->
Inside my_ie8_specific_stuff.js
you can write anything you need, it will only be executed on IE8.
Conditional class on the <html>
element
Another way of doing it is putting a class on your <html>
tag with conditional comments:
<!--[if IE 8]> <html class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
This clever and tricky technique will put an ie8
class on html
in IE8, any other browser will not get it.
You can easily check for this in jQuery:
var isIE8 = $('html').hasClass('ie8');