I gather from this post that almost always one wants to be accessing the DOM property, not the HTML attribute.
So what are the rare useful exceptions? In what situation is accessing the HTML attribute better than accessing the DOM property?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sometimes the attribute doesn’t map to changes in the property.
One example is the
checkedattribute/property of a checkbox.DEMO: http://jsfiddle.net/mxzL2/
…whereas an ID attribute/property will stay in sync:
DEMO: http://jsfiddle.net/mxzL2/1/
And custom properties generally don’t map at all. In those cases, you’ll need to get the attribute.
Perhaps a potentially more useful case would be a text input.
…where the attribute doesn’t change with changes from the DOM or the user.
As noted by @Matt McDonald, there are DOM properties that will give you the initial value that would reflect the original attribute value.