โ๏ธ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