Aviv
Aviv

Reputation: 75

Document type does not allow element "span" here?

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?

Upvotes: 1

Views: 1197

Answers (1)

rahlstrom
rahlstrom

Reputation: 699

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?

Upvotes: 4

Related Questions