-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomSelection.js
More file actions
47 lines (31 loc) · 1.48 KB
/
domSelection.js
File metadata and controls
47 lines (31 loc) · 1.48 KB
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
38
39
40
41
42
43
44
// ! DOM SELECTION
// * 1. document.getElementByID() : mengembalikan element
// const judul = document.getElementById('judul'); // ? menangkap element dengan id : judul
// judul.style.color = 'blue';
// judul.style.fontFamily = 'georgia';
// judul.style.backgroundColor = 'gray';
// judul.innerHTML = 'Klaz WEB'; // ? mengganti tulisan menjadi klaz web
// * 2. document.getElementsByTagName() : mengembalikan HTMLCollection / array
// const p = document.getElementsByTagName('p');
// p[2].style.backgroundColor = 'lightblue'; // ? harus menggunakan index
// ? untuk semua bisa menggunakan looping
// for(let i = 0; i < p.length; i++){
// p[i].style.backgroundColor = 'lightblue';
// }
// ? bisa juga seperti ini
// const h1 = document.getElementsByTagName('h1')[0];
// h1.style.fontSize = '50px';
// * 3. document.getElementsByClassName : mengembalikan HTMLCollection / array
// const p1 = document.getElementsByClassName('p1');
// p1[0].innerHTML = 'Ini diubah dari javascript'; // ? mengubah isi text/tulisan pada html
// * 4. document.querySelector() : mengembalikan element
// const p4 = document.querySelector('#b p');
// p4.style.color = 'green';
// p4.style.fontSize = '30px';
// const li2 = document.querySelector("section#b ul li:nth-child(2)");
// li2.style.backgroundColor = 'orange';
// * 5. document.querySelectorAll() : mengembalikan nodeList
// const p = document.querySelectorAll('p');
// for(let i = 0; i < p.length; i++){
// p[i].style.backgroundColor = 'lightblue';
// }