How to define IE7 using jQuery?

How to define IE7 using jQuery, possibly using jQuery.browser?

+46
jquery browser internet-explorer internet-explorer-7
Jul 02 '10 at 12:08
source share
3 answers

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

+70
Jul 02 2018-10-12T00:
source share

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 */ 
+52
Jul 02 '10 at 12:12
source share

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.

+8
Jul 02 2018-10-02T00:
source share



All Articles