Table insertRow() method

Definition and Usage

insertRow() method creates an empty <tr> element and add it to the table.

insertRow() The method inserts a new row at the specified index in the table.

Note:<tr> element must contain <th> or <td> elements.

Tip:Use deleteRow() method Delete a row.

See also:

HTML Reference Manual:HTML <tr> ট্যাগ

Example

Example 1

Insert a new row at the first position of the table (and insert a <td> element with content):

// Find the <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <tr> element and add it to the first position of the table:
var row = table.insertRow(0);
// Insert new cells (<td> elements) at the first and second positions of the "new" <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
// Add text to new cells:
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";

Try it yourself

Example 2

Create and delete rows:

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);
}

Try it yourself

Syntax

tableObject.insertRow(index)
Parameter Description
index

ফায়ারফক্স এবং ওপেরা তে এটি অত্যাবশ্যক, আইই, চ্রোম এবং স্যাফারি তে এটি বাছাইযোগ্য

সংখ্যা বা মান, যা যোগ করতে হলে কোন লাইনের স্থানকে নির্দেশ করে (0 থেকে শুরু করে)। 0 মান দেওয়ার ফলে নতুন লাইন প্রথম স্থানে যোগ করা হবে。

আপনি -1 এর মান ব্যবহার করতেও পারেন যা শেষ স্থানে একটি নতুন লাইন যোগ করতে ব্যবহৃত হবে。

এই প্যারামিটারটি সংক্ষেপিত হলে, insertRow() Chrome, IE, Firefox এবং Opera-তে শেষ স্থানে এবং Safari-তে প্রথম স্থানে নতুন রেকর্ড যোগ করে।

কারিগরি বিবরণ

ফলাফল: এইমেন্টেড <tr> ইলেকট্রন

ব্রাউজার সমর্থন

চ্রোম এজ ফায়ারফক্স স্যাফারি ওপেরা
চ্রোম এজ ফায়ারফক্স স্যাফারি ওপেরা
সমর্থন সমর্থন সমর্থন সমর্থন সমর্থন