The difference between attribute and property in JS

Simple understanding:

  • property is an attribute in the DOM, an object in JavaScript;
  • attribute is an attribute on an HTML tag, and its value can only be a string;
  • Simply understand, Attribute is the attribute that comes with the DOM node, such as id, class, title, align, etc. commonly used in html.

    And Property is this DOM element as an object, its additional content, such as childNodes, firstChild and so on.

  • Attributes is a subset of property , which saves the attributes defined on HTML tags

    • property can be synchronized from attribute;
    • attribute does not synchronize the value on the property;
    • The data binding between attribute and property is one-way, attribute->property;
    • Changing any value on property and attribute will reflect the update to the HTML page;


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324487145&siteId=291194637