HTML DOM Interfaces: Properties, Attributes and Methods
Elements become DOM objects
The DOM is the browser’s object representation of a document. An interface defines the properties and methods available on an object. HTMLInputElement extends HTMLElement; its value property exposes the current input value. getElementById returns the matching element or null.
<label for="topic">Topic</label><input id="topic" value="HTML"><output id="result"></output><script> const field = document.getElementById("topic"); document.getElementById("result").textContent = field.value;</script>The output shows HTML. The input is an HTMLInputElement.
Current value versus default value
For a text input, the value content attribute defines the initial/default value; defaultValue reflects that attribute. The live value property can diverge after editing or script assignment. Setting the property does not itself dispatch an input event.
<label> Topic <input id="topic" value="HTML"></label><output id="result"></output><script> const field = document.getElementById("topic"); field.value = "CSS"; document.getElementById("result").textContent = field.value + " / " + field.defaultValue;</script>The result is CSS / HTML. Current and default values differ.
Call a native method
A method is a function associated with an object. HTMLFormElement.reset restores controls to their defaults, unless the reset event is canceled. The example uses a button to call reset on a form; parentheses invoke the method.
<form id="prefs"> <label> Topic <input value="HTML"> </label> <button id="restore" type="button">Restore</button></form><script> document.getElementById("restore").addEventListener("click", () => { document.getElementById("prefs").reset(); });</script>Edit the field and activate Restore. The field returns to HTML.
Common mistakes and practice
Not every property reflects an attribute: inspect the interface documentation. Avoid naming a form control reset or submit when you need to call those methods, because named form controls can mask methods. Guard lookups when an element may be absent. Prefer safe textContent updates for plain text.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML DOM Interfaces: Properties, Attributes and Methods — Knowledge Check
Apply the integration concepts taught in this lesson.
Which interface represents an input element?
Which property gives a text input’s current value?
Which property reflects the text input value attribute?
What does form.reset() normally do?
What does getElementById return if no match exists?