← All examples

JavaScript Productivity search.google.com

Number the table rows

Prepends a running number to each table row so list positions are easy to reference.

Code to copy

(function () {
  function number() {
    var grid = document.querySelector('[role="grid"], [role="table"], table');
    if (!grid) return;
    var rows = grid.querySelectorAll('[role="row"]');
    var n = 0;
    rows.forEach(function (r) {
      if (r.querySelector('[role="columnheader"]')) return;
      var first = r.querySelector('[role="cell"], [role="gridcell"]');
      if (!first || first.dataset.jzNumbered) return;
      n += 1;
      first.dataset.jzNumbered = '1';
      var tag = document.createElement('span');
      tag.textContent = n + '. ';
      tag.style.cssText = 'color:#9aa0a6;font-variant-numeric:tabular-nums;';
      first.insertBefore(tag, first.firstChild);
    });
  }
  number();
  new MutationObserver(number).observe(document.body, { childList: true, subtree: true });
})();

How to use this example

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. Paste the code into the rule's JavaScript panel and save — it runs on every page visit.

Rate this example

No ratings yet — be the first.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases