SYNCERのロゴ
アイキャッチ画像

Document.scripts - script要素

scriptsは、Documentのプロパティです。ドキュメントの全てのscript要素を返します。

概要

名前
scripts
所属
Document
IDL
[SameObject] readonly attribute HTMLCollection scripts;
仕様書
https://html.spec.whatwg.org/multipage/dom.html#dom-document-scripts

説明

全てのscript要素をHTMLCollectionで返す。読み取り専用なので、値を代入して変更することはできない。

チュートリアル

Document.scriptsを利用して、script要素を取得する例です。

<script>console.log("hoge")</script>
<script>console.log("fuga")</script>
var scripts = document.scripts ;

scripts[0] ;	// <script>console.log("hoge")</script>
scripts[1] ;	// <script>console.log("fuga")</script>

Document.getElementsByTagName()と同じです。

var scripts = document.scripts ;

var scripts = document.getElementsByTagName( "script" ) ;

デモ

Document.scriptsのデモです。

<!-- このコードは編集できます。 -->

<!DOCTYPE html>
<html>
<body>
<script>console.log("hoge")</script>
<script>console.log("fuga")</script>
<hr>
<script>
var value = document.scripts ;

console.log( value ) ;
document.body.appendChild( new Text( value ) ) ;
</script>
</body>
</html>

サポート状況

ChromeFirefoxSafariEdgeIEOperaiOS SafariAndroid
9+
  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2017年10月6日 (金)
コンテンツを公開しました。