Welcome to WebHeadStart.org

Web Technologies

Sponsored By

WebHeadStart.org is currently in beta.
Please pardon our appearance as we work to provide you with the most comprehensive reference on today's web technologies.

Interested in advertising on WebHeadStart? Become an advertising partner today!

[WWW-HTML Mailing List Archive Home] [Messages By Thread] [Messages By Date]

Re: cdata, javascript and xhtml1.1

From: Sjoerd van Leent Pronexus <svleent@pronexus.nl>
Date: Tue, 29 Jul 2003 12:22:56 +0200
To: <www-html@w3.org>
Message-ID: <CCEJKJAPAPLDIBEOBHOOEEBPCAAA.svleent@pronexus.nl>

Pretty simple why <![CDATA[ ... ]]> exists

look at the following code:

<script type="text/javascript">
	function x()
	{
		return 2 < 1 // returns false
	}
</script>

The function won't work, becose there is a less-than ("<") sign which says
to the parser, here a new tag begins. Well you already guessed that this is
not what you really want, becose you expect it to be all javascript. Well
the solution is <![CDATA[ ... ]]>

look at the changed code:

<script type="text/javascript"><![CDATA[
	function x()
	{
		return 2 < 1 // returns false
	}
]]></script>

If you do this, the < will be interpret as a real less-than sign, not as e
tag start character. Note that IE seems to have problems with <![CDATA[
... ]]>, this is easy to solve:

<script type="text/javascript">//<![CDATA[
	function x()
	{
		return 2 < 1 // returns false
	}
//]]></script>

While this is still correct XHTML, you'll fool the browser with using
comment notation.

Sjoerd van Leent
Received on Thursday, 31 July 2003 03:54:30 GMT
Valid XHTML 1.0! Valid CSS! Site Map | Privacy Policy | Terms of Use | WebHeadStart.org © 2005 All Rights Reserved.