After the changes made in jQuery 1.6.1, I have been trying to define the difference between properties and attributes in HTML.
Looking at the list on the jQuery 1.6.
After reading Sime Vidas's answer, I searched more and found a very straight-forward and easy-to-understand explanation in the angular docs.
HTML attribute vs. DOM property
-------------------------------
Attributes are defined by HTML. Properties are defined by the DOM (Document Object Model).
A few HTML attributes have 1:1 mapping to properties.
idis one example.Some HTML attributes don't have corresponding properties.
colspanis one example.Some DOM properties don't have corresponding attributes.
textContentis one example.Many HTML attributes appear to map to properties ... but not in the way you might think!
That last category is confusing until you grasp this general rule:
Attributes initialize DOM properties and then they are done. Property values can change; attribute values can't.
For example, when the browser renders
, it creates a corresponding DOM node with avalueproperty initialized to "Bob".When the user enters "Sally" into the input box, the DOM element
valueproperty becomes "Sally". But the HTMLvalueattribute remains unchanged as you discover if you ask the input element about that attribute:input.getAttribute('value')returns "Bob".The HTML attribute
valuespecifies the initial value; the DOMvalueproperty is the current value.
The
disabledattribute is another peculiar example. A button'sdisabledproperty isfalseby default so the button is enabled. When you add thedisabledattribute, its presence alone initializes the button'sdisabledproperty totrueso the button is disabled.Adding and removing the
disabledattribute disables and enables the button. The value of the attribute is irrelevant, which is why you cannot enable a button by writing.Setting the button's
disabledproperty disables or enables the button. The value of the property matters.The HTML attribute and the DOM property are not the same thing, even when they have the same name.