To get all the script tags from an HTML document or the DOM, you can use the document.scripts
property.
Let's say you have many script tags in your HTML file like this,
<script src="script1.js"></script>
<script src="script2.js"></script>
<script src="script3.js"></script>
Let' use the document.scripts
property to get all the script tags using JavaScript
- The property returns the script tags as an
HTMLCollection
Object.
// get all script tags
const scriptTags = document.scripts;
console.log(scriptTags);
To see the working example see JSBin.