Basically what I am asking is what is the point of giving my script tags an id attribute? Can the routines inside of them be called or referenced differently because of this identification? Could this cause any problems making the script/page act funny?
Share
The
idis just another accessor of the<script>tag inside the DOM tree. You could in theory usedocument.getElementById()to retrieve the<script>node and delete it or add other attributes (though I don’t believe you can modify thesrcattribute once it has loaded in the DOM). Theidisn’t required for those operations though — it could have been accessed by any DOM function such asgetElementsByTagName("script")as well.If you do need to access the
<script>tag with DOM manipulations, theidmakes it just a little easier. Otherwise, there is little benefit1.1That is sort of true of adding an
idattribute to any DOM node, though nodes affecting presentation can also benefit from CSS targeting theid, unlike a<script>tag…