Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Thank you. For others that are still confused (why would you care about attributes anyway?!) - I found this enlightening (and a little sad wrt how convoluted Dom/browsers still are):

https://javascript.info/dom-attributes-and-properties

In particular:

> So, if an attribute is non-standard, there won’t be a DOM-property for it. Is there a way to access such attributes?

> Sure. All attributes are accessible by using the following methods:

> elem.hasAttribute(name) – checks for existence.

> elem.getAttribute(name) – gets the value.

> elem.setAttribute(name, value) – sets the value.

> elem.removeAttribute(name) – removes the attribute.

> These methods operate exactly with what’s written in HTML.



And web components complicate this further because they can expose both attributes and properties, and have code that reacts to change in both (`attributeChangedCallback` is a lifecycle method).




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: