#45EasyQuiz
45. What's the difference between an "attribute" and a "property" in the DOM?
Web APIsJavaScriptHTML
Attributes are defined in HTML and provide initial values; properties live on the DOM node and reflect the current live state.
Example 1:
const el = createElementState("hello");
el.getAttribute("value"); // "hello"
el.setValueProperty("world");
el.value; // "world"
el.getAttribute("value"); // "hello"solution.js
Initial attribute and property match
(() => {
const el = createElementState("hello");
expect(el.getAttribute("value")).toBe("hello");
expect(el.value).toBe("hello");
})()