Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving the script tag an ID

I came across a scenario where giving a script element an id attribute would solve a problem easily. However, after reading about the script element at w3schools and quirksmode, it seems doing so could have some unforeseen consequences.

Has anyone come across any of these issues with browsers such as Chrome, Safari, FF3 up and IE 7 up?

like image 958
The Code Pimp Avatar asked Apr 29 '10 23:04

The Code Pimp


People also ask

How do you put an id in a tag?

The syntax for id is: write a hash character (#), followed by an id name.

Can you give HTML tag an id?

Note: In HTML5, id attributes can be used by any HTML tag but in HTML 4.01 there are some restriction to use id attributes. It can not be used by <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title> tag.

What does it mean to tag a script?

Tagging a screenplay is the process of going through the script line by line and highlighting (the old method) all the elements needed for production.


1 Answers

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.

like image 76
bobince Avatar answered Oct 09 '22 10:10

bobince