JavaScript error when opening page – Uncaught SyntaxError

Posted on

Question :

When I open the page it breaks and when I open the browser console the following error appears:

Uncaught SyntaxError: Unexpected token ;

When I see the code on the console it looks like this:

if (linhaAnterior$.size() > 0) {}

But my code actually looks like this:

if (linhaAnterior$.size() > 0) {}

I have other if s in this code but only in this does this change occur when I open the page.

    

Answer :

Since you are using XHTML, you need to encapsulate the javascript code with CDATA, as follows:

    <script type="text/javascript">
    // <![CDATA[
        ...
    // ]]>
    </script>

However, we recommend separating the javascript code into another file:

    <script type="text/javascript" src="/pasta/script.js"></script>

To learn more, see link .

    

Leave a Reply

Your email address will not be published. Required fields are marked *