Jake Barnes wrote:
I'm reading over this page:
http://wiki.script.aculo.us/scriptaculous/show/Usage
I'm struck by this code example
+++++++++++++++++++++++++++++++
3. Use
To call upon the functions, use HTML script tags. The best way is to
define them like this:
<script type="text/javascript" language="javascript">
// <![CDATA[
Effect.Appear('element_id');
// ]]>
</script>
+++++++++++++++++++++++++++++++
For god's sake, what are the CDATA blocks for? I've never seen that
before.
The CDATA tag, which also has a close tag, is an XML tag. When you
write a true xhtml page using the correct mime type
application/xhtml+xml, you often have to enclose everything after the
script tag up to the close script tag in CDATA tags. The CDATA tags
tell an xml parser that the contents within them are not part of the
xml(script in this case) and should not be parsed as xml. Some
characters often used in script code are forbidden in xml and, if the
parser detects them, the page may not be displayed and just gives you a
report of an xml error. You can avoid all of this by using the script
as an external script in the usual way. Unfortunately many current
browsers do not understand CDATA tags, and if you use them the script
does not work. This is solved by making the CDATA tags JS comments.
Besides the // in your example, the multi-line JS comments often are
used instead such as /* <![CDATA[ */ and /* ]]> */ . XML aware browsers
and servers, including the W3C validator see right through the JS
comment tags, find the CDATA tags, and are happy. The many browsers
that are not properly xml aware see the CDATA tags as just ordinary JS
comments, and they are happy and your script works.