Document.scripts is a read-only instance property that returns a live HTMLCollection of every <script> in the document. Learn how to count scripts, read src and type, compare with querySelectorAll, and five examples with try-it labs.
01
Kind
Read-only property
02
Returns
HTMLCollection
03
Items
HTMLScriptElement
04
Access
Index like array
05
Live
Updates with DOM
06
Status
Baseline widely
Fundamentals
Introduction
Modern pages load JavaScript from many places—inline blocks, bundled files, analytics snippets, and module scripts. When your code needs to inspect every <script> tag on the page, document.scripts is the built-in collection to use.
MDN: the scripts property returns a list of the <script> elements in the document. The returned object is an HTMLCollection. You can use it just like an array to get all the elements in the list.
💡
Not the same as currentScript
document.scripts lists every script tag. document.currentScript returns only the one classic script currently being processed (or null in callbacks).
Document.scripts is marked Baseline Widely available on MDN (since June 2018). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.scripts
Read-only live HTMLCollection of every <script> — count, index, and inspect src/type.
WidelyAvailable
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in legacy IE
Full support
Document.scriptsBaseline support
Bottom line: Use document.scripts to list every script tag on a page. Pair with currentScript when you need the one script currently executing.
Wrap Up
Conclusion
Document.scripts is the standard, live list of every <script> in a document. Use length to count tags, loop to inspect src and type, and remember it updates when the DOM changes.
Use document.scripts for a live list of all scripts
Check length before assuming scripts exist
Read src, async, defer, and type per item
Pair with currentScript when debugging execution order
Prefer for...of to loop the collection clearly
❌ Don’t
Confuse scripts with currentScript
Assume a static snapshot if you mutate the DOM later
Expect scripts to include scripts not yet in the tree
Rely on script count alone for security audits
Modify the collection directly (it is read-only)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.scripts
Live HTMLCollection of every script tag on the page.
5
Core concepts
📄01
Returns
HTMLCollection
API
📝02
Items
HTMLScriptElement
Type
🔄03
Live
DOM sync
Collection
📊04
Count
.length
MDN
✅05
Status
Baseline
2018+
❓ Frequently Asked Questions
A read-only HTMLCollection of every <script> element in the document. Each item is an HTMLScriptElement. MDN: you can use it like an array to get all elements in the list.
No. MDN marks Document.scripts as Baseline Widely available (since June 2018). It is a standard Document collection property.
document.scripts lists every <script> tag in the document. document.currentScript returns only the one classic script currently being processed (or null).
Yes. HTMLCollection updates when script elements are added or removed from the document.
Both work. document.scripts is the dedicated Document API and returns a live HTMLCollection. querySelectorAll returns a static NodeList snapshot.
Yes. Any <script> element in the document tree is included, whether it has a src attribute or inline code.
Did you know?
MDN says you can use document.scripts just like an array. That means familiar patterns—length, bracket indexing, and for...of loops—work without converting to a real array first.