-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path29.Element ID Classes Using Console.js
37 lines (29 loc) · 1.22 KB
/
29.Element ID Classes Using Console.js
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
33
34
35
36
37
// div.container > div.box*6 > 1,2,2.5#dhai,3,4,5
// Element ID Classes
console.log("Divyam")
let boxes=document.getElementsByClassName("box") //elementS
console.log(boxes)
boxes[3].style.backgroundColor="red"
let col=document.getElementById("dhai") //element
col.style.backgroundColor="pink"
document.querySelectorAll(".box").forEach(e=>{
e.style.backgroundColor="green"
})
document.querySelector(".box").style.backgroundColor="red" //only 1st element
console.log(e=document.getElementsByTagName("div"));
// matches
e[2].matches("#dhai") //false
e[3].matches("#dhai") //true
//closest
e[0].closest(".container") //show container
// contains
console.log(document.querySelector(".container").contains(e[2])); //true //checks if container contains certain element e[2] or not
console.log(document.querySelector(".container").contains(document.querySelector("body"))); //false
//exerxise
let box=document.getElementsByClassName("box")
document.querySelectorAll(".box").forEach(e=>{
e.style.backgroundColor="pink"
e.style.color="blue"
})
document.querySelector("#dhai").style.backgroundColor="wheat"
document.querySelector("#dhai").style.color="red"