Thursday, November 23, 2006

<script> and XHTML

You already knew that in XHTML, all tags must be closed even it is an empty tag but there are always exceptions. In XHTML, it's <script>.

When you use <script> to add JavaScript code to your page, in familiar way, it will look like that

<script type="text/javascript" language="javascript">
// code here

And if you want to include a external JavaScript file, you can use (in XHTML way)

<script type="text/javascript" language="javascript" src="blah.js" />

But it doesn't work (in IE and Firefox). If you want to make it works, you must use

<script type="text/javascript" language="javascript" src="blah.js">

It makes me want to be crazy 'cause I don't understand what happens to my application when the script went mad with JavaScript errors.

FYI: Script and Style elements

Update: Can you find some other tags which do not following the "empty tag" rule in XHTML for me? ;-)

No comments: