Live data from Hacker News

Do you know that there is an HTML tables API?

christianheilmann.com

111–120 of 206 posts

Re: Do you know that there is an HTML tables API?

#111
post #15

Interesting, but the JavaScript examples hurt: let table = [ ['one','two','three'], ['four','five','six'] ]; let b = document.body; let t = document.createElement('table'); b.appendChild(t); table.forEach((row,ri) => { let r = t.insertRow(ri); row.forEach((l,i) => { let c = r.insertCell(i); c.innerText = l; }) }); Use full words for variable names!

> let b = document.body; This one hurts the most. Save a few bytes for an ungodly amount of mental friction.

It doesn't save any bytes, that variable is used once.

Re: Do you know that there is an HTML tables API?

#112

Earlier quoted context omitted.

People often use declarative UI frameworks such as React, Svelte etc. when they want to build things dynamically in JS like that now, so imperative DOM manipulation APIs have unsurprisingly become a little more niche.

If by “Niche” you mean “not hype” then yes, but the PHP+jQuery combo is still very widely used in 2025 (likely more than React, given WordPress market share alone).

Sure! But if you render server side (as with PHP), you'd likely just build up your table on the server rather than dynamically on the client, so you would also not use these imperative table element specific APIs.

Even if, for some reason, you were filling in the table content dynamically via jQuery, I think the fashion there was also to just pass in whole HTML markup snippets as strings to be injected into the DOM, so you'd also more likely use plain elements than this table-specific API, same as with a 'hype' framework of now.

Re: Do you know that there is an HTML tables API?

#114
Sure!

And there is way more to it.

This kind of code was common and also the starting point of every modern language innovation we have today in JavaScript - even TypeScript, and maybe any modern web development on the server as well.

Tables were the only way to create browser independent layouts dynamically. Or put another way: adding interactivity to websites. And simply because hacking is fun and browsers were experimenting with APIs accessible by JavaScript.

CSS was still bleeding from ACID tests, Netscape was forgotten, Mozilla build Phoenix out of the ashes of the bursting bubble and called their effort Firefox.

In Germany there was and still is the infamous selfHTML project. I remember vividly reading and testing Stefans Münz tutorials on this topic. The content is untouched, only the layout changed, so go back in time for more table fun:

https://wiki.selfhtml.org/wiki/Beispiel:JS-Anwendung-Tabelle...

https://wiki.selfhtml.org/wiki/JavaScript/Tutorials/Tabellen...

It was pretty common to have large one file websites: php and html with css and javascript mixed.

There was no git, no VisualStudio Code, Claude Sonnet - no, Notepad and later Notepad++

(Even the DOOM guys had no version control system in the early stages.)

For me John Resig shines out here. Epic genius behind jQuery. The source code was pure magic, and his book "Secrets of the JavaScript Ninja" is for me the all time climax in programming excellence.

If you never utilised the prototype property, you will never understand any of the most basic structures and inner workings JavaScript has to this day and why Classes are "syntactical sugar" for functions and nothing else.

Function.toString in combination with New Function made me enter 10 matrices in parallel at the time. What a revelation. :D

Nicholas Zakas comes close with his seminal Web Development book, in which he featured every Browser API available at the time with examples on roughly 1000 pages. To this day, exercising most of it and understanding the DOM and Windows object was the best investment ever, because and this fact 15 years later paved the way for the success of a financial SaaS platform. Lost wisdom, not covered by any modern framework like Angular or ReacJS.

Re: Do you know that there is an HTML tables API?

#115
post #15

Interesting, but the JavaScript examples hurt: let table = [ ['one','two','three'], ['four','five','six'] ]; let b = document.body; let t = document.createElement('table'); b.appendChild(t); table.forEach((row,ri) => { let r = t.insertRow(ri); row.forEach((l,i) => { let c = r.insertCell(i); c.innerText = l; }) }); Use full words for variable names!

> Use full words for variable names! that's like saying in spoken language "don't ever use pronouns, or even first or nicknames, use full given names"

you are being intentionally dense, they are saying "don't use a single initial to identify someone, use their firstname instead"

Re: Do you know that there is an HTML tables API?

#116
post #47

Earlier quoted context omitted.

Personally I'd make everything const instead of let and use for of instead of forEach, but it's like 10 lines of code it doesn't really matter.

Are you sure this old API does the right thing with for…of?

Should work just fine:

    > document.createElement("table").rows[Symbol.iterator]()
    // Array Iterator { constructor: Iterator() }
HTMLTableElement.prototype.rows actually just returns a HTMLCollection, so same as document.forms, or document.getElementsByClassName. HTMLCollection implements Symbol.iterator as you would expect.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableEl...

Re: Do you know that there is an HTML tables API?

#117
post #28
post #15

Interesting, but the JavaScript examples hurt: let table = [ ['one','two','three'], ['four','five','six'] ]; let b = document.body; let t = document.createElement('table'); b.appendChild(t); table.forEach((row,ri) => { let r = t.insertRow(ri); row.forEach((l,i) => { let c = r.insertCell(i); c.innerText = l; }) }); Use full words for variable names!

A bike-shedding thread on top as usual.

It's hard to read, especially in the lambdas.

It's a small critique, I'm sorry it got upvoted by other people.

Re: Do you know that there is an HTML tables API?

#118

Phew, this post single handedly made me feel old this morning. I started dabbling with the web just over 20 years ago but have mainly been working on the backend the past 10-15 years. I had no clue that nowadays programmers don’t know about this, so I assume it’s supplanted by modern frameworks or modern JS/CSS

I feel like I used this when I built a red-light, green-light dashboard for Windows servers at a bank for my first job out of college (in 2009).

Re: Do you know that there is an HTML tables API?

#119
post #42

Phew, this post single handedly made me feel old this morning. I started dabbling with the web just over 20 years ago but have mainly been working on the backend the past 10-15 years. I had no clue that nowadays programmers don’t know about this, so I assume it’s supplanted by modern frameworks or modern JS/CSS

Yep, didn’t realize this was unknown by enough web developers to warrant an article.

I knew it existed but I figured it was only really useful for extremely data-table centric applications so I've never used it.
Post reply on HN