2

I'd like to output scripts into HTML without knowing whether it's going into a HTML4, HTML5 or XHTML document. The best format I can find is:

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

That validates in all three schemes, but will it work in all browsers in all three doctypes?

1 Answer 1

3

It's fine.

In HTML it is parsed as JavaScript, so treated as comments. In XHTML it is parsed as XML, so treated as CDATA markers.

(This is rather essential to the way the HTML compatibility guidelines for XHTML work to deal with the issue of script elements being handled differently in the two languages).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.