Live data from Hacker News

Do you know that there is an HTML tables API?

christianheilmann.com

91–100 of 206 posts

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

#91

Will Google remove this API then if it’s abandoned? Topic is reminiscent of a submission from yesterday about XSLT: https://news.ycombinator.com/item?id=45779261

XSLT requires hundreds of thousands (maybe millions?) of lines of security-sensitive code. That's why it's proposed for removal.

I doubt that's true for .insertCell() and .insertRow().

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

#92
post #42

Earlier quoted context omitted.

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

I see new frontend developers using for building buttons, and I've even seen people using for doing titles! Us greybeards don't know how much apparent knowledge we're sitting on, it seems.

Is that bad?

Seems to me that we have redundant mechanisms for specifying semantics: tags and attributes (and classes as a specific attribute). Seems to me that tags are really just syntactic sugar for things like roles. Tables in particular are easily abused.

Of course I use the tag names, because they're idiomatic. But I feel like a newbie who identifies divs as the only true structure builder has a proper developer's intuition for separating presentation from content.

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

#93
post #73

Earlier quoted context omitted.

Exactly like how `getElementById` replaced the direct use of the id as a JavaScript identifier.

I remember there being posts that explicitly discouraged using IDs directly, but I'm not sure of tge reasons anymore. Maybe browser incompatibilities or unclear scoping and confusion with other variables?

It was either Mozilla (Netscape, I think) or IE that it didn’t work on for the longest time.

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

#94
post #42

Earlier quoted context omitted.

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

I see new frontend developers using for building buttons, and I've even seen people using for doing titles! Us greybeards don't know how much apparent knowledge we're sitting on, it seems.

And spans for creating links…

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

#95
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!

It's the lets that bother me. The point is elderly JS, and the entire operation is fundamentally imperative. But this code is brimming with opportunities to make mistakes. JS deserved its reputation.

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

#96
post #77

Earlier quoted context omitted.

Thank you for confirming I am not... crazy, just old then. I was staring at the code for minutes, trying to spot something unusual that I missed. So, this really just about the ` ` element, or do I actually not see something?

It's about the insertRow() and insertCell() methods and rows[] and cells[] fields on the table element, not the table itself.

I figured that was the normal way to interact with tables, what would people do otherwise?

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

#97

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

HTML tables are cognitively if not officially deprecated these days. I made my 1996 resume in HTML using a table for layout and it was indistinguishable from the Word version when printed. Made by editing the HTML by hand too!

Tables are great. I don't doubt that CSS stuff is more capable, but the old ones are still useful.

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

#98
post #92

Earlier quoted context omitted.

I see new frontend developers using for building buttons, and I've even seen people using for doing titles! Us greybeards don't know how much apparent knowledge we're sitting on, it seems.

Is that bad? Seems to me that we have redundant mechanisms for specifying semantics: tags and attributes (and classes as a specific attribute). Seems to me that tags are really just syntactic sugar for things like roles. Tables in particular are easily abused. Of course I use the tag names, because they're idiomatic. But I feel like a newbie who identifies divs as the only true structure builder has a proper develope…

> Is that bad?

As long as you think about semantics and accessibility and does the extra work to add those things, then not really.

But why add those extra things when we already get those for free by doing and then customizing the style? Everything you'd need to manually add, automatically works fine then, so seems like a no-brainer to avoid putting more work on your table.

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

#99
post #96
post #77

Earlier quoted context omitted.

It's about the insertRow() and insertCell() methods and rows[] and cells[] fields on the table element, not the table itself.

I figured that was the normal way to interact with tables, what would people do otherwise?

Using the standard DOM APIs or - if they don't care about anything - innerHTML, I suppose.

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

#100

Earlier quoted context omitted.

Just make sure to pass a subscriber to useSyncExternalStore if you decide to venture outside React and use HTMLTable.insertRow, you see react is really smart and won’t let you use this piece of outdated code without punishing you with side effects. Thanks Vercel & Meta for protecting us.

> Just make sure to pass a subscriber to useSyncExternalStore if you decide to venture outside React and use HTMLTable.insertRow, you see react is really smart and won’t let you use this piece of outdated code without punishing you with side effects. Huh? Why'd you involve state in this or any imperative code? You render the rows/columns as you'd render any other DOM elements in React, pass in the data as props and i…

InsertRow updates the live DOM and React just wholesale replaces it. It’s a masterstroke footgun.
Post reply on HN