⚖️attributes vs. properties
HTML attributes vs. DOM properties
🔸 HTML attributes ┊ DOM properties┊ attr-prop sync ┊
For element nodes, most standard HTML attributes automatically become properties of DOM objects. 📗 JS.info ⟩ Attributes and properties
HTML attributes
attribute name is case-insensitive.
attribute values are always strings.
element.attributes collection is iterable and has all the attributes as objects with name and value properties.
DOM properties
DOM properties are NOT always strings. for example:
input.checked (boolean)
div.style (CSSStyleDeclaration)
a.href is always a full URL. ( 👉🏻 See: 💈範例 )
property ⇔ attribute sync
standard attribute changes ⇒ auto-update property, and vice versa.
⭐️ with some exceptions ( 👉🏻 💈範例 )
Last updated