Table createTHead() メソッド
定義と使用法
createTHead()
メソッドは空の <thead> 要素 それをテーブルに追加します。
注記:テーブルに<thead>要素が既に存在する場合、 createTHead()
メソッドは既存の要素を返し、新しい要素を作成しません。
注記:<thead> 要素内には1つ以上の <tr> タグが必要です。
ヒント:テーブルから<thead>要素を削除するには、以下を使用してください: deleteTHead() メソッド。
も参照してください:
HTML リファレンスマニュアル:HTML <thead> タグ
例
例1
<thead> 要素を作成し、その中に <tr> と <td> 要素を挿入:
// id="myTable" の <table> 要素を検索: var table = document.getElementById("myTable"); // 空の <thead> 要素を作成し、テーブルに追加: var header = table.createTHead(); // 空の <tr> 要素を作成し、<thead> の最初の位置に追加: var row = header.insertRow(0); // "新しい" <tr> 要素の最初の位置に新しいセル (<td>) を挿入: var cell = row.insertCell(0); // 新しいセルに太文字を追加: cell.innerHTML = "<b>This is a table header</b>";
例2
テーブルの<thead>要素の作成と削除:
function myCreateFunction() { var table = document.getElementById("myTable"); var header = table.createTHead(); var row = header.insertRow(0); var cell = row.insertCell(0); cell.innerHTML = "<b>This is a table header</b>"; } function myDeleteFunction() { document.getElementById("myTable").deleteTHead(); }
構文
tableObject.createTHead()
パラメータ
なし。
技術的詳細
戻り値: | 新しく作成された(または既存の)<thead> 要素。 |
---|
ブラウザのサポート
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
サポート | サポート | サポート | サポート | サポート |