Sam’s posterous

 
« Back to blog

<Script> element gotcha

Was testing out some external javascript stuff last night, and it turns out that you need to be careful in XHTML whether you have an end tag with no content, as opposed to an empty element.

And empty <script> element looks like this:

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

While one with an end tag, but no content looks like this:

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

Now in normal HTML both are probably valid, but in XHTML (i.e if you supply a DOCTYPE at the start of your document) the former is NOT valid, and the latter is. This had me going round in circles for ages, as firebug would quite happily step through the code in the external JS script, but would not process anything after that.

See XHTML spec for more details: http://www.w3.org/TR/xhtml1/#h-4.3

Loading mentions Retweet

Comments (0)

Leave a comment...

 
Got an account with one of these? Login here, or just enter your comment below.
Posterous-login    Connect    twitter