How to index html table rows or how to Auto-number table rows?

Auto number table rows with CSS and JS

1. CSS Method

table {   
counter-reset: rowNumber;
table tr {
 counter-increment: rowNumber;
table tr td:first-child::before {   
content: counter(rowNumber);   
min-width: 1em;   
margin-right: 0.5em;

2. JS method – append with a new td

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

3. JS method – append with in first td

var table = document.getElementsByTagName(‘table’)[0],   
rows = table.getElementsByTagName(‘tr’),    text = ‘textContent’ in document ? ‘textContent’ : ‘innerText’;
for (var i = 0, len = rows.length; i < len; i++)
rows[i].children[0][text] = i + ‘: ‘ + rows[i].children[0][text];

Post a comment

Your email address will not be published.


  1. Jasbir singh

    sir you are great !

  2. Yesterday I asked the manager, “Can you write my paper for me?” Well, I received my paper four hours later. This is a great result!

  3. Santossep

    https://zithromaxproff.com/# buy zithromax no prescription
    how to get zithromax over the counter

  4. BillyBom

    minocin online: buy minocin online
    panmycin online

  5. The main goal of a critical essay is to analyze a book or a film and to support an argument with a pile of relevant details. Only knowledgeable students will cope with this task.

  6. MichaelDiund

    india pharmacies online: cheap online pharmacies from india ordering medicine from india

  7. MichaelDiund

    order prescription drugs from india: buy prescriptions from india pharmacy overseas pharmacies shipping to usa

  8. I am sure that hiring professional academic writers was the best idea in my life! I was completely satisfied with my essay on History, so I will definitely come back one day.

  9. MichaelDiund

    india pharmacy without dr prescriptions: india pharmacy without dr prescriptions ordering medicine from india

  10. Robertcooto

    cialis pills: https://edpillsonline24.com/# cialis ed pills

  11. Michaelgox

    viagra discount: viagra without a doctor prescription usa viagra without a doctor prescription canada

  12. Michaelgox

    cheap viagra online canadian pharmacy: viagra without a doctor prescription canada buy viagra without prescription

  13. Claudaluck

    doxycycline mono: doxycycline – where to get doxycycline

  14. Claudaluck

    buy doxycycline online 270 tabs: doxycycline generic – doxycycline 100mg

  15. Claudaluck

    amoxicillin tablets in india: over counter antibiotics pills amoxicillin – buy amoxil

  16. Claudaluck

    doxycycline 200 mg: doxycycline generic – doxycycline online

  17. Claudaluck

    can we buy amoxcillin 500mg on ebay without prescription: generic amoxil – amoxicillin discount coupon