From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/htmltableelement/insertrow/index.html | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 files/fr/web/api/htmltableelement/insertrow/index.html (limited to 'files/fr/web/api/htmltableelement/insertrow/index.html') diff --git a/files/fr/web/api/htmltableelement/insertrow/index.html b/files/fr/web/api/htmltableelement/insertrow/index.html new file mode 100644 index 0000000000..737195cf29 --- /dev/null +++ b/files/fr/web/api/htmltableelement/insertrow/index.html @@ -0,0 +1,152 @@ +--- +title: table.insertRow +slug: Web/API/HTMLTableElement/insertRow +tags: + - API + - DOM HTML + - HTMLTableElement + - Méthode + - NeedsMobileBrowserCompatibility + - Reference +translation_of: Web/API/HTMLTableElement/insertRow +--- +
+

{{APIRef("HTML DOM")}}

+ +

La méthode HTMLTableElement.insertRow() insère une nouvelle ligne dans la table et retourne une référence à la nouvelle ligne.

+
+ +

Syntaxe

+ +
var ligne = HTMLTableElement.insertRow(optionnel indice = -1);
+ + + +

Exemple

+ +
<table id="TableA">
+<tr>
+<td>Ancienne ligne supérieure</td>
+</tr>
+</table>
+<script type="text/javascript">
+
+function ajouteLigne(tableID) {
+  // Récupération d'une référence à la table
+  var refTable = document.getElementById(tableID);
+
+  // Insère une ligne dans la table à l'indice de ligne 0
+  var nouvelleLigne = refTable.insertRow(0);
+
+  // Insère une cellule dans la ligne à l'indice 0
+  var nouvelleCellule = nouvelleLigne.insertCell(0);
+
+  // Ajoute un nœud texte à la cellule
+  var nouveauTexte = document.createTextNode('Nouvelle ligne supérieure')
+  nouvelleCellule.appendChild(nouveauTexte);
+}
+
+// Appelle ajouteLigne() avec l'ID d'une table
+ajouteLigne('TableA');
+
+</script>
+ +

Pour être valide dans un document HTML, un élément TR doit avoir au moins un élément TD.

+ +

Remarquez que insertRow insère directement la ligne dans la table et renvoie une référence à la nouvelle ligne. La ligne n'a pas besoin d'être ajoutée séparement comme cela aurait été le cas si document.createElement() avait été utilisé pour créer un nouvel élement TR.

+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName("HTML WHATWG", "tables.html#dom-table-insertrow", "HTMLTableElement.insertRow()")}}{{Spec2("HTML WHATWG")}} 
{{SpecName("DOM2 HTML", "html.html#ID-93995626", "HTMLTableElement.insertRow()")}}{{Spec2("DOM2 HTML")}}Spécifie plus en détail où la ligne est insérée.
{{SpecName("DOM1", "level-one-html.html#ID-39872903", "HTMLTableElement.insertRow()")}}{{Spec2("DOM1")}}Définition initiale.
+ +

 

+ +

Compatibilité des navigateurs

+ +
+

{{CompatibilityTable}}

+ + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Support de base4{{CompatVersionUnknown}}3[1]5.5104
+ + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Support de base{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+ +

[1] A partir de Gecko 20.0 {{geckoRelease("20.0")}}, l'argument indice a été rendu optionnel et a -1 comme valeur par défaut d'après la spécification HTML.

+
+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf