Last updated 2 years ago
browser ⟩ DOM ⟩ type ⟩ Node
instance properties
parentNode (Node | null)
parentElement (Element | null)
childNodes (NodeList) - live NodeList include elements, text and comments.
firstChild (Node | null)
lastChild (Node | null)
nextSibling (Node | null)
previousSibling (Node | null)
nodeType (Integer) - Element (1), Text (3), Comment (8), Document (9).
nodeValue (String | null) - textual content of a node.
nodeName (String) - = Element.tagName if it's an HTML element.
$(), $all()
NodeList
Element - subclass.
MDN ⟩ EventTarget ⟩ Node
Filter or map nodelists in ES6
Node ⟩ .textContent - gets the content of all elements, including <script> and <style> elements. (prevent XSS attacks)
<script>
<style>
Element ⟩ .innerHTML - returns HTML.
HTMLElement ⟩ .innerText - innerText takes CSS styles into account.
innerText
前端筆記 ⟩ innerText、innerHTML、textContent、outerHTML 的差別
codepen ⟩ node.textContent vs. htmlElement.innerText