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

Document.forms - form要素

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

概要

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

説明

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

チュートリアル

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

<form action="https://syncer.jp/"></form>
<form action="https://example.com/"></form>
var forms = document.forms ;

forms[0] ;	// <form action="https://syncer.jp/">
forms[1] ;	// <form action="https://example.com/">

Document.getElementsByTagName()と同じです。

var forms = document.forms ;

var forms = document.getElementsByTagName( "form" ) ;

デモ

Document.formsのデモです。

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

<!DOCTYPE html>
<html>
<head>
	<base target="_blank">
</head>
<body>
<form action="https://syncer.jp/">
	<input name="hoge" value="fuga">
	<button>送信</button>
</form>

<form action="https://example.com/">
	<input name="piyo" value="toto">
	<button>送信</button>
</form>
<hr>
<script>
var value = document.forms ;

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

サポート状況

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