Found a good summary of HTML Attributes vs. DOM Properties in Angular documentation:
Attributes are defined by HTML. Properties are defined by the DOM (Document Object Model).
- A few HTML attributes have 1:1 mapping to properties.
id
is one example.- Some HTML attributes don't have corresponding properties.
colspan
is one example.- Some DOM properties don't have corresponding attributes.
textContent
is one example.- Many HTML attributes appear to map to properties ... but not in the way you might think! [such as
disabled
attribute]
Some more info on MDN's Content vs. IDL Attributes, and W3C Web IDL spec.
Additional notes:
- Attributes are initial values. I wonder if that's how HTML form's reset functionality was implemented.
- Aria attributes (used for accessibility) do not have corresponding properties.
disabled
attribute, doesn't have a value, so the mere presence of the attribute sets it disabled. However, the DOM property fordisabled
has a boolean value.- JavaScript/DOM has methods to specifically work on attributes, e.g.,
getAttribute()
.
No comments:
Post a Comment