Table createTHead() Méthode
Exemple
Créez un élément <thead> (et insérez-y un élément <tr> et <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>";
Définition et utilisation
La méthode createTHead() crée un élément <thead> vide et l'ajoute au tableau.
Remarque : Si un élément <thead> existe déjà sur la table, la méthode createTHead() renvoie l'élément existant et n'en crée pas de nouveau.
Remarque : L'élément <thead> doit contenir une ou plusieurs balises <tr>.
Astuce : Pour supprimer l'élément <thead> d'un tableau, utilisez la méthode deleteTHead() .
Prise en charge du navigateur
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Syntaxe
tableObject.createTHead()
Paramètres
Rien |
Détails techniques
Valeur de retour : | L'élément <thead> nouvellement créé (ou existant) |
---|
Plus d'exemples
Exemple
Créez et supprimez un élément <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();
}
Pages connexes
Référence HTML : balise HTML <thead>
❮ Objet tableau