How to detect IE7 with javascript or jquery and add a class to div

shin picture shin · Sep 8, 2010 · Viewed 32.2k times · Source

Is there any way to detect IE7?

I don't have any problems with my codes in IE8, but I have a problem with IE7.

So what I thought is that I can add a class with jquery when a browser is IE7 detecting it by javascript.

I want to change from

<div id="system">

to

<div id="system" class="ie7">

Thanks in advance.

Answer

Alex picture Alex · Sep 8, 2010

if you really want to solve this by using javascript you might want to check the version like this:

if (navigator.appVersion.indexOf("MSIE 7.") != -1)
    $('#system').addClass('ie7');