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!

7
  • which version of jQuery are you using? Commented Oct 18, 2013 at 0:39
  • The latest I guess (jQuery 1.10.2) Commented Oct 18, 2013 at 0:43
  • 1
    You can use the conditional comment around a different <script> before your <script>, which sets a flag. Commented Oct 18, 2013 at 0:43
  • You mean the conditional comment that goes in the html code? Commented Oct 18, 2013 at 0:45
  • Do you use any programming language inside your page? Commented Oct 18, 2013 at 0:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.