Posted By

PapillonUK on 05/03/10


Tagged

javascript script elment


Versions (?)

Correct sytax for the XHTML & HTML 4 tag


 / Published in: JavaScript
 

This is the correct markup for an inline script tag for HTML 4.01 and XHTML 1.0 Note the lack of any "language" attribute since this is deprecated.

In HTML 4, the content type is declared as CDATA, which means that entities will not be parsed.

In XHTML, the content type is declared as (#PCDATA), which means that entities will be parsed. So to avoid having to encode the data between the tag with enclose it in a CDATA section. Some older browsers don't recgnise the CDATA tag so we "hide" them in Javascript comments "//" This allows the page to be validated and also still work in older browsers.

  1. <!-- XHTML -->
  2. <script type="text/javascript">
  3. //<![CDATA[
  4. // Your unescaped Javascript here...
  5. //]]>
  6. </script>
  7.  
  8.  
  9. <!-- HTML 4.01 -->
  10. <script type="text/javascript">
  11. // Your unescaped Javascript here...
  12. </script>

Report this snippet  

You need to login to post a comment.