Sir Lojik
Sir Lojik

Reputation: 1429

why does the w3 validator check within the <script> tag and raise errors?

I am trying to validate my page using the W3C validator but it keeps looking within the script tag of the javascript and failing. any ideas?

Upvotes: 2

Views: 299

Answers (1)

meder omuraliev
meder omuraliev

Reputation: 186562

It gets treated as PCDATA since it's XHTML ( XML ). Mark it as CDATA per When is a CDATA section necessary within a script tag? and you should be ok:

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

Alternatively you can stop attempting to use XHTML by using HTML 5, or throw the code in an external JS file if it's feasible.

Upvotes: 5

Related Questions