How to get all the script tags from HTML documents using JavaScript?

August 30, 2020 - 1 min read

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;


To see the working example see JSBin.

Feel free to share if you found this useful 😃.