22 Dec '14

Anupa Manipal

A professional Software Developer in VB.NET - SQL Server and learner of PHP. Expertise in implementation of various projects including designing, development, coding and implementation of software applications.

0 Shares

HTML and JavaScript auto increment number for Table

HTML and JavaScript auto increment number for Table:
 
<table>
  <tr>
    <td>Raj</td>
  </tr>
  <tr>
    <td>Kiran</td>
  </tr>
  <tr>
    <td>Peter</td>
  </tr>
  <tr>
    <td>Mahesh</td>
  </tr>
</table>
<script>
    var tables = document.getElementsByTagName(‘table’);
    var table = tables[tables.length -1];
    var rows = table.rows;
    for(var i = 0, td; i < rows.length; i++){
        td = document.createElement(‘td’);
        td.appendChild(document.createTextNode(i + 1));
        rows[i].insertBefore(td, rows[i].firstChild);
    }
</script>

About Anupa Manipal

A professional Software Developer in VB.NET - SQL Server and learner of PHP. Expertise in implementation of various projects including designing, development, coding and implementation of software applications.

Related Posts

Leave a Reply