From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/htmltablerowelement/insertcell/index.html | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 files/ja/web/api/htmltablerowelement/insertcell/index.html (limited to 'files/ja/web/api/htmltablerowelement/insertcell/index.html') diff --git a/files/ja/web/api/htmltablerowelement/insertcell/index.html b/files/ja/web/api/htmltablerowelement/insertcell/index.html new file mode 100644 index 0000000000..ed195d4a80 --- /dev/null +++ b/files/ja/web/api/htmltablerowelement/insertcell/index.html @@ -0,0 +1,61 @@ +--- +title: HTMLTableRowElement.insertCell +slug: Web/API/HTMLTableRowElement/insertCell +tags: + - DOM + - Gecko + - Gecko DOM Reference + - tableRow +translation_of: Web/API/HTMLTableRowElement/insertCell +--- +
+ {{ApiRef}}
+

概要

+

テーブル行に新規セルを挿入し、セルへの参照を返します。

+

構文

+
var cell = HTMLTableRowElement.insertCell(index);
+
+ +

+
<table>
+  <tr id="row0">
+    <td>Original cell</td>
+  </tr>
+</table>
+
+<script type="text/javascript">
+
+function addCell(tableRowID) {
+  // 引数に指定された id によりテーブル行要素への参照を取得
+  var rowRef = document.getElementById(tableRowID);
+
+  // セルインデックス 0 の箇所にセルを挿入
+  var newCell   = rowRef.insertCell(0);
+
+  // セルにテキストノードを追加
+  var newText  = document.createTextNode('New cell')
+  newCell.appendChild(newText);
+}
+
+// 対象テーブル行の id をパラメータとし、関数 addCell を実行
+addCell('row0');
+
+</script>
+
+

対象テーブルを valid な HTML とするには、tr 要素が最低でもひとつ td 要素を持っていなければなりません。

+

insertCell はテーブルにセルを直接的に挿入して新しい参照を返すものである事に注意して下さい。このメソッドを用いる場合、 予め {{domxref("document.createElement()")}} によって td 要素を生成する必要はありません。

+

ブラウザ互換性

+

Gecko 固有の注意事項

+ +

仕様書

+ -- cgit v1.2.3-54-g00ecf