views:

64

answers:

3

Hi guys, i came across a scenario where giving a <script> element an "ID" would solve a problem easily. However, after reading about the script tag at w3schools and quirksmode, it seems doing so could have some unforeseen consequences. Has anyone come across any of these issues with modern browsers such as Chrome, Safari, FF3 up and IE 7 up?

Thanks

+4  A: 

It's fine in all current browsers.

The only browser that got <script id> wrong was Netscape 4, which we stopped caring about a long, long time ago.

That quirksmode page seems to be badly out of date, what with its use of language attributes, script <!-- hiding, and application/x-javascript. Its advice about avoiding <script> in the <body> (and putting it in <head> instead) is at odds with today's encouraged practices.

If we're talking <script> attribute compatibility problems: defer doesn't work everywhere so don't rely on it; charset doesn't work everywhere, and neither does the charset parameter on the served script's Content-Type, so your script charset had better match the page; type should always be text/javascript and not one of the non-working alternatives the pedants who wrote RFC 4329 would like you to use.

bobince
Your browser attribute support history astounds me! +1
alex
Well I cheated a bit as quirksmode mentions it :-) I do remember the problem, but I couldn't have told you off-hand which Netscape version it was... brrr, bad times.
bobince
Thanks you guys..
The Code Pimp
+1  A: 

I don't think a browser would have a problem by adding an id attribute to a script element.

On some of my sites, that load additional JavaScripts via JavaScript, I have added a class attribute to make referencing them easier. The validator did not complain.

alex
+1  A: 

If you're still having to support Netscape 4, you've got a lot of trouble – and the pity and condolences of the rest of the developer world.

Short answer, I wouldn't worry about it.

Robusto