How to insert a row in a table in JavaScript

In this article I have described about table insertRow() method used in JavaScript.
  • 1508

Table insertRow() method in JavaScript

  • As we know that a table object represents a table in HTML.
  • If want to insert the row in a table then we can use table insertRow() method

Browser support

Following are the main browsers which support the table insertRow() method

  • Internet Explorer.
  • Firefox.
  • Opera.
  • Google Chrome.
  • Safari.


The syntax of table insertRow() method as follows


Lets take an example

<!DOCTYPE html>



<script type="text/javascript">

    function displayResult()


        var table = document.getElementById("Table");

        var row = table.insertRow(0);

        var cell1 = row.insertCell(0);

        var cell2 = row.insertCell(1);

        cell1.innerHTML = "NEW ROW";

        cell2.innerHTML = "NEW ROW";




<body style ="background-color:YELLOW">

<table id="Table" border="1">










<br />

<button type="button" onclick="displayResult()">NEW ROW</button>







when we click on button



Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2018 DotNetHeaven. All rights reserved.