HTMLTableElement: createCaption() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

HTMLTableElement.createCaption() メソッドは、この <table> に関連付けられた <caption> 要素を返します。 この表に <caption> 要素がない場合が、このメソッドは生成して返します。

メモ: キャプションが存在しない場合、 createCaption() は新しいキャプションを表に直接挿入します。 Document.createElement() を使用して新しい <caption> 要素を生成する場合とは異なり、キャプションを個別に追加する必要はありません。

構文

js
createCaption()

引数

なし。

返値

この例は JavaScript を使用して、表に最初は存在しないキャプションを追加します。

HTML

html
<table>
  <tr>
    <td>セル 1.1</td>
    <td>セル 1.2</td>
    <td>セル 1.3</td>
  </tr>
  <tr>
    <td>セル 2.1</td>
    <td>セル 2.2</td>
    <td>セル 2.3</td>
  </tr>
</table>

JavaScript

js
let table = document.querySelector("table");
let caption = table.createCaption();
caption.textContent = "このキャプションは JavaScript で生成されました。";

仕様書

Specification
HTML
# dom-table-createcaption-dev

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
createCaption

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support