Changes to SCRIPT Content

One of the changes of XHTML which will make transitioning from HTML based browsers to XHTML based browsers difficult is the handling of

Unfortunately, the above code would be invalid under XHTML. Why_ Under XML, the script code would actually be parsed for HTML tags. The less-than sign, <, in the line if (counter < 5) would be interpreted as the beginning of a tag. and an XHTML parser would get confused. It only requires a slight modification to fix.

Encapsulating the script in a CDATA element would inform a XML parser not to check the contents for tags. You do this by starting the script with

Where the file script.js contains:

var counter = 0;
function test() {
if (counter < 5) {
counter++;
} else {
alter("Call Doug & Margaret for " +
"permission to go above 5!")
}
}

Also, it should be noted that the following is valid XHTML:

Why_ Because the script does not contain any of the XHTML special characters of < >, [, ], or &. But as soon as you add one, your XHTML becomes invalid again.