javascripthtmlcdata

How do I prevent a `<![CDATA[` section within an HTML `<script>` tag from causing a syntax error?


<script type="text/javascript"><![CDATA[
  jQuery(".track").hide();
  jQuery(document).ready(function() {
    jQuery(".track").show();
  });
]]></script>

Console says:

Uncaught SyntaxError: Unexpected token <

What is the issue with the syntax? I don't see it. I'm assuming it really means everything inside the <script> tags, since it starts off with a <

Not sure how to get to this file to fix, I'm thinking something/plugin is injecting this, but how do I find out what is causing it?


Solution

  • This would fix the error if for some reason you insist on using CDATA, but again its not needed because the page is very HTML5

    <script type="text/javascript">
    //<![CDATA[ 
    jQuery(".track").hide();jQuery(document).ready(function() {jQuery(".track").show();});
    //]]>
    </script>