Properties and Attributes are treated similar by IE 8 and below.
Do they mean same?
Properties and Attributes are treated similar by IE 8 and below.
Do they mean same?
What is the difference between attribute and property? has quite a discussion about the semantics ... and different language uses of the terms ...
@all who believes that they are same:
NO.
Properties and Attributes of an HTML element are not the same.
From DOM point of view: Properties are private variables and Attributes are stored in a NamedNodeMap stored as the childNode of the HTML elements
From JavaScript point of view (Implementation): var elem = document.getElementById("ID");
elem.prop = somevalue; //accessing properties
elem.getAttribute("attributeName"); //accessing attributes : getters elem.setAttribute("attributeName","value"); //accessing attributes : setters
Refer to my other answer for implementation details.
Properties and Attributes are not same in DOM. However, treated similar in IE 8 and below.
I faced an issue in cross-browser compatibility.
Issue: Custom Attributes being accessed as properties in an HTML4/JavaScript for IE8. Needed to make the HTML compatible for Chrome, Safari and IE9.
Solution: elements can be iterated to check for the custom-attributes and added those as properties.
Sample Code:
var propertyName = obj.attributes[index].nodeName; //(Attribute names are not case sensitive) obj[propertyName] = value; //(Check for the implementation of the obj.customAttribute)
Tip: Unlike IE 8 and below, IE 9 and above has resolved the issue and treats attributes and properties differently.