The id
is just another accessor of the <script>
tag inside the DOM tree. You could in theory use document.getElementById()
to retrieve the <script>
node and delete it or add other attributes (though I don't believe you can modify the src
attribute once it has loaded in the DOM). The id
isn't required for those operations though -- it could have been accessed by any DOM function such as getElementsByTagName("script")
as well.
If you do need to access the <script>
tag with DOM manipulations, the id
makes it just a little easier. Otherwise, there is little benefit1.
1That is sort of true of adding an id
attribute to any DOM node, though nodes affecting presentation can also benefit from CSS targeting the id
, unlike a <script>
tag...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…