तालिका सम्मिलित करेंरो () विधि
उदाहरण
तालिका के पहले स्थान पर नई पंक्तियाँ डालें (और इसमें कुछ सामग्री के साथ एक <td> तत्व डालें):
// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(0);
// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
// Add some text to the new cells:
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
परिभाषा और उपयोग
insertRow() विधि एक खाली <tr> तत्व बनाता है और इसे एक तालिका में जोड़ता है।
insertRow() विधि तालिका में निर्दिष्ट अनुक्रमणिका पर नई पंक्ति (पंक्तियों) को सम्मिलित करती है।
नोट: एक <tr> तत्व में एक या अधिक <th> या <td> तत्व होने चाहिए।
युक्ति: किसी पंक्ति को हटाने के लिए deleteRow() विधि का उपयोग करें ।
ब्राउज़र समर्थन
Method | |||||
---|---|---|---|---|---|
insertRow() | Yes | Yes | Yes | Yes | Yes |
वाक्य - विन्यास
tableObject.insertRow(index)
पैरामीटर मान
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. A number that specifies the position of the row to insert (starts at 0). The value of 0 results in that the new row will be inserted at the first position. The value of -1 can also be used, this results in a new row being inserted at the last position. This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari.If this parameter is omitted, insertRow() inserts a new row at the last position in Chrome, IE, Firefox and Opera, and at the first position in Safari. |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | डाला गया <tr> तत्व |
---|
और ज्यादा उदाहरण
उदाहरण
पंक्तियाँ बनाएँ और हटाएं:
function myCreateFunction() {
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteRow(0);
}
संबंधित पृष्ठ
HTML संदर्भ: HTML <tr> टैग
टेबल ऑब्जेक्ट