r/programming • • Mar 09 '25

Introducing command And commandfor In HTML

https://developer.chrome.com/blog/command-and-commandfor
92 Upvotes

33 comments sorted by

View all comments

Show parent comment

-16

u/KerrickLong Mar 09 '25

It's often the case that your repeated elements for which you'd prefer relative selectors are repeated because each of them represents an entity stored in a database. For those, you can use the primary key and entity type to generate an ID and use it in both places. For example, id="comment-4321".

11

u/SnS_Taylor Mar 09 '25

Exposing the primary key in HTML is a bad idea. Also, this is less often the case than you might think.

I agree with the general sentiment. The overhead of creating an actually unique ID is quite high. JS and frameworks are much more straightforward and compartmentalized.