0

I have all my jQuery code for different elements of my website in one single file called scripts.js however there is one block of code I wish to disable if the user is using IE8. This is what I want to disable:

    $(document).ready(function(){
 $('.parallax-block-1').parallax("50%", 0.1);
});

I've looked up everywhere and the only thing I found is to place an IF conditional comment like - <!--[if !(IE 8)]><!--> before <script> </script> in the html code but since I have everything in one single js file the IF statement would disable all the other scripts in it.

Hope my question makes sense. Thank you all!

Nesta
  • 988
  • 2
  • 16
  • 44

1 Answers1

1

You can use <!--[if !(IE 8)]><!--> to insert a class name into <html> tag, then inside your js file you can use that class name to specify whether enable the js function. For example: in html file:

 <!--[if IE 8]> <html class="lt-ie9"> <![endif]--> /* Rendered in IE8 browser */
<!--[if gt IE 8]><!--> <html> <!--<![endif]--> /* Rendered in other browsers */

then in your JS file:

if ($("html.lt-ie9").length > 0) {
   //your functions or code that should work on all browsers except for IE8 goes here
}

Hope it helps.

OfficeDoge
  • 36
  • 3