How to use in JavaScript Dom tr insertCell

In this article I have described about tr insertCell() method used in JavaScript.
  • 1816

tr insertCell() method in JavaScript

  • If we want to insert a particular cell within a table then we can use tr insertCell() method.

Browser support

Following are the main browsers which support the tr insertCell() method

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

Syntax

The syntax of tr insertCell() method as follows

trObject.insertCell(index)

Lets take an example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript">

    function displayResult()

    {

        var firstRow = document.getElementById("myTable").rows[0];

        var x = firstRow.insertCell(-1);

        x.innerHTML = "forth cell"

    }

</script>

</head>

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

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

  <tr>

    <td>TEA</td>

    <td>COFFEE</td>

    <td>COLDDRINK</td>

  </tr>

</table>

<br />

<button type="button" onclick="displayResult()">Insert cell</button>

</body>

</html>

 

Output

cellisrt1.jpg


When we click on button


ceeisert2.jpg

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

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.