- Tree structure with
document.documentElement
serving as root.-
Element nodes representing HTML tags e.g.
document.body
-
Leaf nodes such as pieces of text or comment nodes.
-
Each node has
nodeType
property -Node.ELEMENT_NODE, Node.TEXT_NODE, Node.COMMENT_NODE
-
Element node has
childNodes
alsofirstChild
,lastChild
,previousSibling
,nextSibling
,parentNode
-
Finding elements
getElementsByTagName
getElementById
getElementsByClassName
-
Changing document
appendChild
insertBefore
replaceChild
-
Creating nodes
createTextNode
createElement
-
Attributes
getAttribute, setAttribute
- most common attributes can be accessed through property of same name on the element's DOM object e.g.
href, className
(since class is a keyword in JS)
-
Layout
- block elements span whole width of document e.g.
<p> or <h1>
- inline elements are rendered on the same line with surrounding text e.g.
<a> or <strong>
offsetWidth, offsetHeight
- space element takes up in pixels.clientWidth, clientHeight
- space inside the element ignoring border widthgetBoundingClientRect
- returns object withtop, bottom, left, right
indicating pixel positions of the sides of the elemtn relative to the top left of the screen.pageXOffset, pageYOffset
- current scroll position
- block elements span whole width of document e.g.
-
Styling
-
Using the
style
property (<p id="para" style="color: purple">Nice</p>
) -node.style.color = "magenta"
style ="display: block"
- display as block,style="display: none"
- prevents an element from showing up on screen.- for property names with hyphens e.g. font-family, in JS it is
style.fontFamily
-
Cascading Style Sheets
- set of rules for how to style elements in a document. Cascading refers to the fact that multiple rules are combined to produce the final style for an element.
- it can be given inside
<style>
tag. <style> strong { font-style: italic; color: gray; } </style>
.abc
- applies to all elements with "abc" in their class attribute#xyz
- applies to the element with an id attribute of "xyz"p#main.a.b
- p elements with id main and with classes a and b- more specific rule takes precedence -
p.a
>p or a
p > a
- applies to all a tags that are direct children of p tagsp a
- applies to all a tags inside p tags, whether they are direct or indirect children.
-
-
Query Selectors
- selector syntax - used in style sheets can be used also to find DOM elements.
querySelectorAll
- takes a selector string and returns aNodeList
containing all the matching elements.querySelector
- return first matching elementp .animal
- Animal inside of<p>
p > .animal
- direct child of<p>
-
Positioning
position
- can be one of static, relative, absolute.requestAnimationFrame
- request browser for animation update by passing ananimate
function
-
Last active
May 17, 2023 13:33
-
-
Save mkmohangb/c1167d884535aaa8e8b8ed80fdfa17fb to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment