テーブルcreateTHead()メソッド
例
<thead>要素を作成します(そしてそれに<tr>要素と<td>要素を挿入します):
// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <thead> element and add it to the table:
var header = table.createTHead();
// Create an empty <tr> element and add it to the first position of <thead>:
var row = header.insertRow(0);
// Insert a new cell (<td>) at the first position of the "new" <tr> element:
var cell = row.insertCell(0);
// Add some bold text in the new cell:
cell.innerHTML = "<b>This is a table header</b>";
定義と使用法
createTHead()メソッドは、空の<thead>要素を作成し、それをテーブルに追加します。
注: <thead>要素がテーブルにすでに存在する場合、createTHead()メソッドは既存の要素を返し、新しい要素を作成しません。
注: <thead>要素には、1つ以上の<tr>タグが含まれている必要があります。
ヒント:テーブルから<thead>要素を削除するには、 deleteTHead()メソッドを使用します。
ブラウザのサポート
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
構文
tableObject.createTHead()
パラメーター
なし |
技術的な詳細
戻り値: | 新しく作成された(または既存の)<thead>要素 |
---|
その他の例
例
<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();
}
関連ページ
HTMLリファレンス:HTML <thead>タグ
❮テーブルオブジェクト