JS6 ClassNotes
JS6 ClassNotes
HTML CSS JS
(structure) (style) (logic)
lege
Col
pna
A
Starter Code
<style> tag connects HTML with CSS
lege
Col
pna
A
<html>
<head>
<title> Website Name </title>
</head>
<body>
<!-- Content Tags -->
lege
</body>
Col
na
</html>
Ap
Window Object
ge
The window object represents an open window in a browser. It is browser’s object (not JavaScript’s)
lle
& is automatically created by browser.
a Co
n
It is a global object with lots of properties & methods.
Ap
What is DOM?
lege
l
When a web page is loaded, the browser creates a Document Object Model (DOM) of the page
a Co
Apn
DOM Manipulation
Selecting with id
ge
document.getElementById(“myId”)
olle
Selecting with class
na C
Ap
document.getElementsByClassName(“myClass”)
document.getElementsByTagName(“p”)
DOM Manipulation
Query Selector
lege
ol
document.querySelector(“#myId / .myClass / tag”)
C
//returns first element
pna
A
document.querySelectorAll(“#myId / .myClass / tag”)
//returns a NodeList
DOM Manipulation
Properties
lege
l
tagName : returns tag for element nodes
a Co
innerText : returns the text content of the element and all its children
Apn
innerHTML : returns the plain text or HTML contents in the element
lege
Col
pna
A
Qs. Create 3 divs with common class name - “box”. Access them & add some unique text to each
of them.
DOM Manipulation
Attributes
lege
l
getAttribute( attr ) //to get the attribute value
a Co
pn
setAttribute( attr, value ) //to set the attribute value
Style A
node.style
DOM Manipulation
Insert Elements let el = document.createElement(“div“)
ge
node.append( el ) //adds at the end of node (inside)
le
Col
node.prepend( el ) //adds at the start of node (inside)
pna
A
node.before( el ) //adds before the node (outside)
Delete Element
lege
l
Insert the button as the first element inside the body tag.
a Co
Apn
Qs. Create a <p> tag in html, give it a class & some styling.
Now create a new class in CSS and try to append this class to the <p> element.
Did you notice, how you overwrite the class name when you add a new one?
Solve this problem using classList.