XHTML Strict is invalid due to html tags inside Javascript

I am building a site using strict XHTML markup. Inside html, I need to put a js script:

<script type="text/javascript">

$(document).ready(function () { $('#nav li#nav-strona-glowna').append('<a href="/platinium/" class="hover active"><span>Strona glowna</span></a>');

</script>   

Unfortunately, xhtml is no longer valid due to the "" tag inside this script. How can I check xhtml without deleting it?

+3
source share
6 answers

You need a CDATA tag. Example stolen from this MDC page:

<script type="text/javascript">
 //<![CDATA[
  var i = 0;

  while  (++i < 10)
  {
    // ...
  }
 //]]>
</script>

In general, it is best to avoid the problem with JS (and CSS) in external files.

+6
source

Try:

<script type="text/javascript">
  <![CDATA[
      $(document).ready(function () { $('#nav li#nav-strona-glowna').append('<a href="/platinium/" class="hover active"><span>Strona glowna</span></a>');
  ]]>
</script>
+3
source

CDATA

 <script>
 //<![CDATA[

 // js goes here - bypasses browser HTML parser

 //]]>
 </script>

HTML , HTML JavaScript. - , , , .

, , CDATA JavaScript HTML.

, , HTML Strict.

+1

, , . ?

XHTML, JavaScript . CDATA script:

<script type="text/javascript">
//<![CDATA[
    $(document).ready(function () { $('#nav li#nav-strona-glowna').append('<a href="/platinium/" class="hover active"><span>Strona glowna</span></a>'); });
//]]>
</script>

, JavaScript , IE, XHTML XML. . https://developer.mozilla.org/en/properly_using_css_and_javascript_in_xhtml_documents

+1
<script type="text/javascript"><![CDATA[
// your code
]]></script>

.

+1

? , , .

Btw. XHTML - ,

(http://xhtml.com/en/xhtml/serving-xhtml-as-xml/)

, , HTML4 HTML5, .

+1

Source: https://habr.com/ru/post/1787966/


All Articles