views:

38

answers:

1

Hi, i've been using jquery succesfully with almost any browser but ie6, i'm giving up i wish i could use a conditional statement like

  <!--[if IE 6]>
    <link rel="stylesheet" type="text/css" href="css/style-for-ie.css" media="screen" />
  <![endif]-->

To disable my scripts, is there anyway i can tell ie6 to stop loading something or to disable javascript altogether? or can i make a script.js for jquery that stops ie6 from loading certain functions? I'm willing to use php to disable some code in my html if ie6 present, as long as is transparent to the user. Thank you in advance

A: 

Use a downlevel-revealed conditional comment to place a class on the <body>:

<!--[if lt IE 7]><body class="ie6"><![endif]-->
<!--[if gte IE 7]><!--><body class="notie6"><!--<![endif]-->

Now you can target selectors at IE6 or not-IE6, from both stylesheets (so you don't necessarily have to use a separate stylesheet) and scripts (either checking the class of document.body manually, or just using selectors like $('body.notie6 div.something') in jQuery).

There are conditional comments directly in JScript too, but, annoyingly, they only target particular JScript engine version numbers, which don't always tie up with IE version numbers. Using the HTML conditional comments for everything makes it more consistent.

bobince
that does it thanks! i just need to add the body to all my jquery selectors, i was getting tired of googling, i begging to look for a php that strips the <script> </script> if ie6 or ie7 detected, your solution is much simpler for me.
Guillermo Siliceo Trueba
You can also say eg. `if (!$('body').hasClass('ie6'))` to wrap a load of script at once, if you don't want to change each selector.
bobince