.html() function not working in conditional comment
Hey guys,
I was hoping someone here could help me get this simple exercise done. It invovles changing the html using jQuery when the browser is less than IE9
I was messing with the .html() jQuery function that I have used before and was having some problems, but I got help in
this post
With this code, it runs in all browsers:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <title>Replacing html with jQuery</title>
- <script src="http://code.jquery.com/jquery-1.4.4.js"></script>
- <script>
- $(document).ready(function () {
- $('nav#mainNavigation').html('<p>The HTML has been changed because the browser you are using is less than IE 9</p>');
- });
- </script>
- </head>
- <body>
- <nav id="mainNavigation">
- <ul>
- <li><a href="#">Link 1</a></li>
- <li><a href="#">Link 2</a></li>
- <li><a href="#">Link 3</a></li>
- <li><a href="#">Link 4</a></li>
- <li><a href="#">Link 5</a></li>
- <li><a href="#">Link 6</a></li>
- <li><a href="#">Link 7</a></li>
- <li><a href="#">Link 8</a></li>
- <li><a href="#">Link 9</a></li>
- </ul>
- </nav>
- </body>
- </html>
Then, I used the conditional comment for Internet Explorer so that the code is only read if the browsers is less than Internet explorer 9. I am pretty sure and
according to this my conditional comment code is fine, but for some reason when I try it in IE8, the .html() function is not executing and therefore not replacing the <u/> in the <nav> with a <p> in said <nav>
Here is the code with the conditional comment:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <title>Replacing html with jQuery</title>
- <script src="http://code.jquery.com/jquery-1.4.4.js"></script>
- <!--[if lt IE 9]>
- <script>
- $(document).ready(function () {
- $('nav#mainNavigation').html('<p>The HTML has been changed because the browser you are using is less than IE 9</p>');
- });
- </script>
- <![endif]-->
- </head>
- <body>
- <nav id="mainNavigation">
- <ul>
- <li><a href="#">Link 1</a></li>
- <li><a href="#">Link 2</a></li>
- <li><a href="#">Link 3</a></li>
- <li><a href="#">Link 4</a></li>
- <li><a href="#">Link 5</a></li>
- <li><a href="#">Link 6</a></li>
- <li><a href="#">Link 7</a></li>
- <li><a href="#">Link 8</a></li>
- <li><a href="#">Link 9</a></li>
- </ul>
- </nav>
- </body>
- </html>
Does anyone have any idea why it is not executing the function in the condition comment when it is run in a version of IE less than 9 like it is supposed to.
Is it possible that maybe the script should be in a separate file and just be linked?
Is there a conflict between the JQuery syntax and the condition comment?
I hope someone could help, I would appreciate it a lot as I have to get this done soon.
Thanks in Advance & Best Regards