-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOM.js
More file actions
32 lines (26 loc) · 928 Bytes
/
DOM.js
File metadata and controls
32 lines (26 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Documents Object Model
console.dir(window.document);// -> print properties and methods
// DOM manupulation
//Access Elements
// by ID
let heading = document.getElementById("heading")//h1
console.dir(heading);// -> print heading
// by class
let headings = document.getElementsByClassName("white")
console.dir(headings); // print html collection Similar to Array.
// by tags
let tags = document.getElementsByTagName("p")
console.dir(tags); // print html collection Similar to Array.
// by Query selector
// by tags
let firstEl = document.querySelector("p"); // First element
console.dir(firstEl);
let allEl = document.querySelectorAll("p"); // All element
console.dir(allEl);
// by class
let firstCl = document.querySelector(".white"); // First element
console.dir(firstCl);
let allCl = document.querySelectorAll(".white"); // All element
console.dir(allCl);
// by ID
let firstId = document.querySelector("#heading")