Targeting IE 8 and Below?
internet-explorer, internet-explorer-8, javascript
Solution
Try doing it the HTML5 Boilerplate way. Then just target IE versions by class in JS and CSS.
Replace your opening `<html>` tag with the following. Adjust to your needs:
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
In JavaScript:
var isIE8 = document.getElementsByClassName('lt-ie9').length;
var isIE7 = document.getElementsByClassName('lt-ie8').length;
if (isIE8) {
...
}
if (isIE7) {
...
}
Problem
I have a script that runs great in IE 9+ and all other browsers. But in IE 8 or below there are visual errors. I can fix this visual errors by changing some animation effects for IE 8 and below. To do this I need to have two scripts on my page. One for IE 9+, Firefox, Chrome, Safari, and the other for IE 8 and below. Here is what I have tried: ``` // First the Script that runs for non-IE browsers. <!--[if !IE]> <script type="text/javascript"> // Script that runs </script> <![endif]--> // Now for the Script for IE 8 <!--[if lt IE 9]> <script type="text/javascript"> // Script that runs </script> <![endif]--> ``` First Question and the main one is when attempting this it doesn't seem to work. IE starts acting crazy and the script doesn't function proerply at all. If I remove the first script and leave the second one it works without issue. It would seem that the `<!--[if !IE]><!-->` is not working correctly. Second Question: Using `<!--[if !IE]><!-->` can I target only IE 8 and below?