Attributes in the DOM
You'll learn how HTML attributes become accessible properties in the DOM that you can read and manipulate with JavaScript.
Core Concept
When your browser parses HTML into the DOM, it doesn't just create elements—it also converts attributes (like id, class, src, href) into properties on those element objects. Think of it like this: if an element is a filing cabinet, attributes are the labels and properties are the actual drawers you can open and access.
How Attributes Map to Properties
HTML attributes written in your markup become accessible as properties on element objects:
<img id="logo" src="image.jpg" alt="Company Logo">
When this becomes a DOM element node, you can access these attributes as properties on the element object. The browser creates a JavaScript object representation where each attribute becomes accessible through dot notation.
The Connection
Most common HTML attributes have corresponding DOM properties with the same or similar names. For example:
idattribute →.idpropertyclassattribute →.classNamepropertysrcattribute →.srcpropertyhrefattribute →.hrefproperty
The DOM keeps attributes and properties in sync in most cases—changing one updates the other. However, they're not always identical; some properties return processed values (like a full URL instead of a relative path).
Why This Matters
Understanding that attributes become properties is fundamental to DOM manipulation. When you want to read or change an element's characteristics with JavaScript, you're working with these property representations of the original HTML attributes.
Key Takeaway: HTML attributes are converted into DOM element properties that you can access and modify, creating a bridge between your static markup and dynamic JavaScript code.