Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML concept: dom-versus-source

HTML source is the parser’s input sequence, whereas the DOM is the current mutable object model; after parsing, the two representations need not be identical.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

source text → parsed DOM → live state and mutations

Bytes are decoded to code points, and the text/html parser creates nodes, inserts implied elements, and repairs misnesting. DOMParser performs that kind of parsing into a separate document, but it does not retain original quoting, attribute order, or omitted tags as metadata.

IDL properties can describe live state that differs from a content attribute. For a text control, the value attribute supplies defaultValue, but the current value can change after editing; serialization through outerHTML still shows the attribute, not necessarily the control state.

Script operations mutate nodes without rewriting the network response or file. innerHTML and outerHTML serialize the current DOM fragment using new syntax, so they cannot faithfully recover the source; developer tools displaying the tree can likewise expose repairs and mutations.

The example parses a string with DOMParser, changes the live value property, and appends text to a node. Its output shows the new property state, the value absent from outerHTML, unchanged source, and changed DOM text.

Examples

<!doctype html>
<meta charset="utf-8">
<output id="result"></output>
<script>
const source = "<input id=course value=source><p id=note>initial</p>";
const parsed = new DOMParser().parseFromString(source, "text/html");
const course = parsed.querySelector("#course");
const note = parsed.querySelector("#note");
course.value = "live";
note.append(" + DOM");
result.textContent = `attribute=${course.getAttribute("value")}; property=${course.value}; serializedLive=${course.outerHTML.includes("value=\"live\"")}; sourceHasDOM=${source.includes("DOM")}; domText=${note.textContent}`;
</script>

Result

attribute=source; property=live; serializedLive=false; sourceHasDOM=false; domText=initial + DOM

The executed example verifies the boundary among input, attribute, property, and serialization; it does not imply that every form property follows the same reflection rules.

Sources