From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/element/insertadjacenttext/index.html | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 files/ja/web/api/element/insertadjacenttext/index.html (limited to 'files/ja/web/api/element/insertadjacenttext') diff --git a/files/ja/web/api/element/insertadjacenttext/index.html b/files/ja/web/api/element/insertadjacenttext/index.html new file mode 100644 index 0000000000..7b13ef97b8 --- /dev/null +++ b/files/ja/web/api/element/insertadjacenttext/index.html @@ -0,0 +1,147 @@ +--- +title: Element.insertAdjacentText() +slug: Web/API/Element/insertAdjacentText +translation_of: Web/API/Element/insertAdjacentText +--- +

{{APIRef("DOM")}}

+ +

insertAdjacentText() メソッドは、与えられたテキストノードを、メソッドを実行した要素に対する相対的な位置に挿入します。

+ +

構文

+ +
element.insertAdjacentText(position, element);
+ +

パラメーター

+ +
+
position
+
element に対する相対的な位置を {{domxref("DOMString")}} 表現で指定します。次の文字列のうち1つを取ります。 +
    +
  • 'beforebegin': element 本体の前。
  • +
  • 'afterbegin': element のすぐ内側の、最初の子要素の前。
  • +
  • 'beforeend': element のすぐ内側の、最後の子要素の後。
  • +
  • 'afterend':element 本体の後。
  • +
+
+
element
+
DOM ツリーに挿入するテキストの {{domxref("DOMString")}} 表現。
+
+ +

返り値

+ +

Void。

+ +

例外

+ + + + + + + + + + + + + + +
例外説明
SyntaxErrorposition として指定した文字列が認識できない値だった。
+ +

ポジション名の視覚的な表現

+ +
<!-- beforebegin -->
+<p>
+<!-- afterbegin -->
+foo
+<!-- beforeend -->
+</p>
+<!-- afterend -->
+ +
注記: beforebegin および afterend の positions が使えるのは、対象ノードがツリーの中にあって、親要素を持つ時に限られます。
+ +
beforeBtn.addEventListener('click', function() {
+  para.insertAdjacentText('afterbegin',textInput.value);
+});
+
+afterBtn.addEventListener('click', function() {
+  para.insertAdjacentText('beforeend',textInput.value);
+});
+ +

私たちが GitHub に用意した insertAdjacentText.html デモを見てください。(同時に source code も読んでください。) ここにはシンプルなパラグラフが1つあります。フォーム要素に好きなテキストを入力してから、Insert before または Insert after ボタンを押すと、insertAdjacentText() が、入力したテキストをパラグラフのテキストの前または後に挿入します。すでにあるテキストノードにテキストが追加されるのではなく、新しい追加テキストが含まれる別のテキストノードが生成されて、それが追加されることに注意してください。

+ +

仕様

+ + + + + + + + + + + + + + + + +
仕様ステータスコメント
{{SpecName('DOM WHATWG', '#dom-element-insertadjacenttext', 'insertAdjacentText()')}}{{ Spec2('DOM WHATWG') }} 
+ +

ブラウザー間の互換性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
機能ChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
基本サポート{{ CompatVersionUnknown() }}{{ CompatGeckoDesktop("48.0") }}{{ CompatUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
機能AndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
基本サポート{{ CompatUnknown() }}{{ CompatGeckoMobile("48.0") }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}
+
+ +

関連項目

+ + -- cgit v1.2.3-54-g00ecf