Simplify your business
Monday, 13 October 2008 10:44 pm

JavaScript with XHTML

Wednesday, 4 October 2006  

Having recently ported some HTML pages to XHTML, we were a little surprised that our favourite validator continued to warn us that our very simple one-line javascript code was no longer correct:

<script language="javascript" type="text/javascript">
copthis();
</script>

Apparently, the trick is to enclose the actual javascript code with a “CDATA” section like this:

<script language="javascript" type="text/javascript">
//<![CDATA[
copthis();
//]]>
</script>

The reason is apparently that under the XHTML standard, the javascript code is considered as “PCDATA” and therefore treated by the validator in the same manner as the rest of the markup code. See this article from About.com for more.

Posted in Development, HTML, JavaScript by Ivan
Blinklist icon Del.iocio.us icon Furl icon Reddit icon Technorati icon Yahoo! icon

Got something to say?

To protect your privacy, your email address will not be displayed.





Some basic rules for commenting:

  • Watch your language.
  • Keep comments on-topic and relevant.
  • You can use basic XHTML tags for formatting and linking but not bbcode.
  • Comments are moderated, so don't double post if your comment doesn't appear immediately.
  • Please proof-read your comments for spelling and grammar mistakes.
  • Watch your language.