1

I am working on getting my XHTML validated.
In my page, I have dynamic creation (in JS) of many HTML elements.
For example, I have a for loop that parses an Array that hold value's of a select tag, and then my JS code created the select with the given values. Therefore, my JS contains HTML elements inside quotes (strings). Unfortunately, I cannot get my XHTML validated because the validator things that these guys are actual elements.

How do I avoid this? Is is necessary to avoid this?

Aviv
  • 75
  • 7

1 Answers1

4

You'll need to tell the XHTML validator to parse your JavaScript different then the rest of your code. You can do this by using CDATA blocks in your script tags.

Example:

<script type="text/javascript">
//<![CDATA[
...code...
//]]>
</script>

For more information for as to why, see the question When is a CDATA section necessary within a script tag?

Community
  • 1
  • 1
rahlstrom
  • 699
  • 1
  • 5
  • 9
  • thanks - this works, but causes a different issue - I have a Pyramid app that uses Chameleon for its templates. In my – Aviv Aug 06 '11 at 23:25