Javascript Element How to - Find the script tag's id








Question

We would like to know how to find the script tag's id.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function()<!--   w  w w . j a  v a2 s .co m-->
{
 console.log( document.getElementById('scriptID').src);   
}

</script>
</head>
<body>
  <script id="scriptID" type="text/javascript"
    src="http://external.script.com/file.js">
</script>
</body>
</html>

The code above is rendered as follows: