Do most modern browsers support ids in script tags such as:
<script id="aParticularScript">/* ... */</script>
The reason I ask is that Eclipse displays a warning stating "undefined attribute name" but it works fine in Google Chrome when I use jQuery selectors to get other properties of the script element. W3Schools states that the script element does not support any standard attributes (including the id attribute), but I've learned not to trust W3Schools.
Is it okay to have the script tag have an id?
HTML 4 Answer:
No, you can't, at least not if you want valid HTML...
The following elements can't have an ID attribute:
<base>
<head>
<html>
<meta>
<script>
<style>
<title>
There might be a couple more.
This is confusing because viewing just the documentation for the ID/class attributes doesn't specifically say that they can't be used with these elements. You have to look at the DTD for the elements to see that the general attributes are not defined for the element, and thus cannot be used.
HTML 5 Answer:
The default document type declaration, HTMLElement, which applies to all elements in HTML specifies that these global attributes (including the ID attribute) can be used on any element you create, so it would appear you can do this in HTML 5, but not in HTML 4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With