Pyth PDF
Pyth PDF
parentNode
nodeName: P
nodeType: 1 (Element)
firstChild
las
parentNode
previousSibing previousSibing
nodeName: #text nodeName: B nodeN
nodeType: 3 (Text) nodeType: 1 nodeT
nodeValue: "Sample " nodeV
nextSibing nextSibing
firstChild
lastChild parentNode
nodeName: #text
nodeType: 3 (Text)
nodeValue: "bold"
element.className = "active";
element.style.color =
document.querySelector() and
document.querySelectorAll()
Changing the Node structure
● Create a new element (can also cloneNode() an
existing one)
element =
document.createEl
ement("P");
or element =
document.createTe
xtNode("My
Text");
window.location.href =
"newPage.html";
Note: Can result in JavaScript script execution
termination
console.log("Reached
confirm("OK?"); //
Popup dialog
div2
offsetLeft offsetTop offsetParent
offsetLeft div3
offsetHeight offsetParent
offsetWidth
Positioning elements
● Normally elements are positioned automatically by
the browser as part of the document
Positioning context
● Each element has an offsetParent (some
ancestor element).
Parent
top/offsetTop Parent
left/offsetLeft
Child margin
Child border
Element dimensions
● Reading dimensions: element.offsetWidth and
element.offsetHeight
<body>
<div id="div1">
<p>div1</p>
</div>
#div1 { width:
50px; height:
200px; background:
#ffe0e0;
}
Positioning
…
<div id="div2">
<p>div2</p>
<div id="div2-1">
<p>div2-1</p>
</div>
</div>
#div2 {width: 300px; height:
200px; position: relative;
background: #d0e0ff;}
Positioning
...
<div id="div3">
<p>div3</p>
<div id="div3-
1">
<p>div3-1</p>
</div>
</div>
#div3 {width: 300px;
height:
200px; background:
#ffffe0;}