-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2_manipulation.js
54 lines (37 loc) · 1.36 KB
/
2_manipulation.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// DOM Manipulation Method
// 1. manipulasi Element
// element.innerHTML
// element.style.<property>
// element.setAttribute()
// element.classList
// 2. manipulasi Node
// 1.1 element.innerHTML
// const judul = document.getElementById('judul');
// judul.innerHTML = '<em>Wandy Azami</em>';
// 1.2 element.style.<property>
// const judul = document.querySelector('h1')
// judul.style.color = 'lightblue';
// judul.style.backgroundColor = 'red';
// 1.3 element.setAttribute()
// const judul = document.getElementsByTagName('h1')[0];
// judul.setAttribute('name', 'wandy');
// const a = document.querySelector('section a');
// a.setAttribute('id', 'link');
// console.log(a.getAttribute('id'));
// console.log(a.getAttribute('href'));
// 1.4 element.classList
const p2 = document.querySelector('.p2');
// 1.4.1 untuk menambahkan kelas pada element
p2.classList.add('label');
// 1.4.2 untuk menghapus kelas pada element
p2.classList.remove('label');
// 1.4.3 untuk menambahkan / menghapus kelas secara otomatis
p2.classList.toggle('label');
// 1.4.3 untuk mengetahui kelas apa yang ada pada urutan ke
p2.classList.item('2');
// 1.4.3 untuk mengetahui kelas sesuai nama yang diminta
p2.classList.contains('label');
// 1.4.3 untuk mengganti nama kelas dengan nama yang baru
p2.classList.replace('label', 'lukis');
// manipulasi body
document.body.style.backgroundColor = 'lightblue';