How to define IE7 using jQuery, possibly using jQuery.browser?
Got a method
if ($.browser.msie && parseInt($.browser.version, 10) === 7) { alert('IE7'); } else { alert('Non IE7'); }
- update
Please note that $. browser removed from jQuery 1.9
See $. browser . This feature is deprecated, and you should consider $ instead . Support .
To answer the question, this is a complex technology designed for use in style sheets, but can also be easily used to check the browser version or the best part of the selector.
Use the following markup (from Boilerplate HTML5)
<!--[if lt IE 7]><html class="ie6"><![endif]--> <!--[if IE 7]><html class="ie7"><![endif]--> <!--[if IE 8]><html class="ie8"><![endif]--> <!--[if gt IE 8]><!--><html><!--<![endif]--> <head>
Use selector with hasClass in jQuery
$('html').hasClass('ie7'); $('html.ie7 .myclass').dostuff();
And use as part of a regular selector in css
.mydiv {max-height:50px} .ie6 .mydiv {height:50px} /* ie6 max-height fix */
All the rest:
if ($.browser.msie && $.browser.version == 7) { //do something };
Must work. Regardless of whether this is the right way to do things, this is another question.