First things first! What is an HTML attribute?
The html attributes provide additional information about or to the element. For instance value is an attribute below:
<input id="inpt" type="text" value="Roy"/>
Of-course id and type are attributes too, but lets stick to value for the sake of this post.
Without beating the bushes now, lets get to the point!
"An html attribute may or may not have a corresponding DOM property. Similarly the DOM properties may or may not have the corresponding html attribute". For example, the html attribute "value" has a corresponding DOM property "value".
The key point is that attribute values do not change but their corresponding DOM properties do. Consider the following input element:
The attribute "value" is initialized with the value "Roy". Now let's assume that the user changes the value of the input by typing something. Let's observe the values of the attribute and the DOM property.
As can be seen in the grab above, the user changes the value of the input field, the attribute has however not changed and still contains the old value, "Roy", whereas the DOM property is updated to new value "Amjad".
Can you name an attribute, that does not have a corresponding DOM property and vice versa?


No comments:
Post a Comment