Implement DOM node manipulation methods and property access from JavaScript. Builds on the DOM-JS bridge architecture from issue 2.
Scope#
Tree Manipulation Methods#
On element/node wrapper objects:
node.appendChild(child)— append child node, return the childnode.removeChild(child)— remove child from parent, return removed childnode.insertBefore(newNode, referenceNode)— insert before referencenode.replaceChild(newChild, oldChild)— replace old with new, return oldnode.cloneNode(deep)— clone node (optionally with subtree)node.hasChildNodes()— returns boolean
Content Properties#
node.textContent— get: concatenate all descendant text; set: replace children with text nodeelement.innerHTML— get: serialize subtree to HTML string; set: parse HTML and replace childrenelement.outerHTML— get: serialize element and subtree to HTML string
Attribute Methods#
element.getAttribute(name)— return attribute value or nullelement.setAttribute(name, value)— set attributeelement.removeAttribute(name)— remove attributeelement.hasAttribute(name)— return booleanelement.attributes— return NamedNodeMap-like object (simplified: array of {name, value})
Navigation Properties#
node.parentNode— parent wrapper or nullnode.parentElement— parent if element, else nullnode.childNodes— array-like NodeList of childrennode.children— array-like HTMLCollection of element children onlynode.firstChild/node.lastChildnode.firstElementChild/node.lastElementChildnode.nextSibling/node.previousSiblingnode.nextElementSibling/node.previousElementSibling
Style Property#
element.style— object with CSS property access (e.g.,element.style.color = "red")- Properties use camelCase (backgroundColor, not background-color)
- Setting a style property updates the element's inline
styleattribute
classList#
element.classList.add(className)— add classelement.classList.remove(className)— remove classelement.classList.toggle(className)— toggle classelement.classList.contains(className)— check class presence
Acceptance Criteria#
-
parent.appendChild(child)moves nodes in the DOM tree -
node.textContentreads concatenated text and can set text -
element.innerHTMLserializes and parses HTML -
element.getAttribute/setAttributework correctly - Navigation properties (parentNode, childNodes, etc.) traverse the tree
-
element.style.color = "red"updates inline styles -
element.classList.add("foo")modifies the class attribute - Removed nodes are properly detached from the tree
Phase 11 — DOM-JS Bindings (issue 3 of 8). Depends on: issue 2 (DOM-JS bridge architecture).