Search code examples
javascriptdomhtml4

Does properties and Attributes mean same in JavaScript?


Properties and Attributes are treated similar by IE 8 and below.

Do they mean same?


Solution

  • @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.