Document.scripts

  • Revision slug: DOM/Document.scripts
  • Revision title: Document.scripts
  • Revision id: 18199
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment 41 words added

Revision Content

{{ DomRef() }}

Summary

Returns a list of the {{ HTMLElement("script") }} elements in the document. The returned object is an {{ domxref("HTMLCollection") }}.

Syntax

var scriptList = document.scripts;

The returned scriptList is an {{ domxref("HTMLCollection") }}. You can use this just like an array to get all the elements in the list.

Example

This example looks to see if the page has any {{ HTMLElement("script") }} elements.

var scripts = document.scripts;

if (scripts.length) {
  alert("This page has scripts!");
}

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatGeckoDesktop("9.0") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatGeckoMobile("9.0") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}

Specification

{{ spec("http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-scripts", "DOM: document scripts") }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 name="Summary">Summary</h3>
<p>Returns a list of the {{ HTMLElement("script") }} elements in the document. The returned object is an {{ domxref("HTMLCollection") }}.</p>
<h3 name="Syntax">Syntax</h3>
<pre class="eval"><code>var <em>scriptList</em></code> = document.scripts;
</pre>
<p>The returned <code>scriptList</code> is an {{ domxref("HTMLCollection") }}. You can use this just like an array to get all the elements in the list.</p>
<h3>Example</h3>
<p>This example looks to see if the page has any {{ HTMLElement("script") }} elements.</p>
<pre class="brush: html">var scripts = document.scripts;

if (scripts.length) {
  alert("This page has scripts!");
}
</pre>
<h3 name="Specification">Browser compatibility</h3>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoDesktop("9.0") }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoMobile("9.0") }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> </tbody> </table>
</div>
<h3 name="Specification">Specification</h3>
<p>{{ spec("http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-scripts", "DOM: document scripts") }}</p>
Revert to this revision