You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2-ui/1-document/02-dom-nodes/article.md
+29-29Lines changed: 29 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,33 +6,33 @@ libs:
6
6
7
7
# DOM tree
8
8
9
-
The backbone of an HTML document is tags.
9
+
Tulang punggung dari dokumen HTML adalah tag.
10
10
11
-
According to the Document Object Model (DOM), every HTML tag is an object. Nested tags are "children" of the enclosing one. The text inside a tag is an object as well.
11
+
Berdasarkan Document Object Model (DOM), setiap tag HTML merupakan sebuah objek. Tag berlapis adalah "anak" dari tag yang melampirkan. Teks di dalam sebuah tag merupakan sebuah objek juga.
12
12
13
-
All these objects are accessible using JavaScript, and we can use them to modify the page.
13
+
Semua objek ini dapat diakses menggunakan JavaScript, dan kita bisa menggunakannya untuk memodifikasi halaman.
14
14
15
-
For example, `document.body`is the object representing the`<body>` tag.
15
+
Misalnya, `document.body`merupakan objek yang merepresentasikan tag`<body>`.
16
16
17
-
Running this code will make the `<body>`red for 3 seconds:
17
+
Menjalankan kode ini akan membuat `<body>`menjadi merah selama 3 detik.
18
18
19
19
```js run
20
-
document.body.style.background='red'; //make the background red
20
+
document.body.style.background='red'; //buat background menjadi merah
21
21
22
-
setTimeout(() =>document.body.style.background='', 3000); //return back
22
+
setTimeout(() =>document.body.style.background='', 3000); //kembalikan seperti semula
23
23
```
24
24
25
-
Here we used`style.background`to change the background color of `document.body`, but there are many other properties, such as:
25
+
Disini kita menggunakan`style.background`untuk mengubah warna background `document.body`, tetapi ada banyak properti lain, seperti:
26
26
27
-
-`innerHTML` -- HTML contents of the node.
28
-
-`offsetWidth` -- the node width (in pixels)
29
-
- ...and so on.
27
+
-`innerHTML` -- Konten HTML dari node.
28
+
-`offsetWidth` -- lebar node (dalam piksel)
29
+
- ...dan seterusnya.
30
30
31
-
Soon we'll learn more ways to manipulate the DOM, but first we need to know about its structure.
31
+
Kita akan segera mempelajari lebih banyak cara untuk memanipulasi DOM, tetapi pertama-tama kita perlu mengetahui tentang strukturnya.
32
32
33
-
## An example of the DOM
33
+
## Contoh dari DOM
34
34
35
-
Let's start with the following simple document:
35
+
Mari kita mulai dengan dokumen sederhana berikut:
36
36
37
37
```html run no-beautify
38
38
<!DOCTYPE HTML>
@@ -46,7 +46,7 @@ Let's start with the following simple document:
46
46
</html>
47
47
```
48
48
49
-
The DOM represents HTML as a tree structure of tags. Here's how it looks:
49
+
DOM menggambarkan HTML seperti struktur pohon pada tag. Begini tampilannya:
On the picture above, you can click on element nodes and their children will open/collapse.
60
+
Pada gambar di atas, Anda dapat mengklik node elemen dan anaknya akan membuka/menutup.
61
61
```
62
62
63
-
Every tree node is an object.
63
+
Setiap node pohon merupakan sebuah objek.
64
64
65
-
Tags are *element nodes* (or just elements) and form the tree structure: `<html>`is at the root, then`<head>`and`<body>`are its children, etc.
65
+
Tag-tag merupakan *node elemen* (atau hanya elemen) dan membentuk struktur pohon: `<html>`merupakan root, kemudian`<head>`dan`<body>`adalah anak-anaknya, dll.
66
66
67
-
The text inside elements forms *text nodes*, labelled as`#text`. A text node contains only a string. It may not have children and is always a leaf of the tree.
67
+
Teks di dalam elemen-elemen membentuk *node teks*, dilabeli sebagai`#text`. Sebuah node teks hanya berisi string. Ia mungkin tidak memiliki anak-anak dan selalu menjadi daun pohon.
68
68
69
-
For instance, the`<title>`tag has the text `"About elk"`.
69
+
Misalnya, tag`<title>`memiliki teks `"About elk"`
70
70
71
-
Please note the special characters in text nodes:
71
+
Harap perhatikan karakter khusus dalam node teks:
72
72
73
-
-a newline: `↵` (in JavaScript known as`\n`)
74
-
-a space: `␣`
73
+
-baris baru: `↵` (di dalam JavaScript seperti`\n`)
74
+
-spasi: `␣`
75
75
76
-
Spaces and newlines are totally valid characters, like letters and digits. They form text nodes and become a part of the DOM. So, for instance, in the example above the`<head>`tag contains some spaces before `<title>`, and that text becomes a`#text` node (it contains a newline and some spaces only).
76
+
Spasi dan baris baru adalah karakter yang benar-benar valid, seperti huruf-huruf dan angka-angka. Mereka membentuk node teks dan menjadi bagian dari DOM. Jadi, misalnya, pada contoh di atas, tag`<head>`berisi beberapa spasi sebelum `<title>`, dan teks tersebut menjadi node`#teks` (ini berisi baris baru dan hanya beberapa spasi).
77
77
78
-
There are only two top-level exclusions:
79
-
1.Spaces and newlines before `<head>`are ignored for historical reasons.
80
-
2.If we put something after`</body>`, then that is automatically moved inside the `body`, at the end, as the HTML spec requires that all content must be inside `<body>`. So there can't be any spaces after`</body>`.
78
+
Hanya ada dua pengecualian top-level:
79
+
1.Spasi dan baris baru sebelum `<head>`diabaikan karena alasan historis.
80
+
2.Jika kita meletakkan sesuatu setelah`</body>`, maka secara otomatis dipindahkan ke dalam `body`, di bagian bawah, karena spesifikasi HTML mengharuskan semua konten harus berada di dalam `<body>`. Jadi tidak boleh ada spasi setelah`</body>`.
81
81
82
-
In other cases everything's straightforward -- if there are spaces (just like any character) in the document, then they become text nodes in the DOM, and if we remove them, then there won't be any.
82
+
Dalam kasus lain semuanya mudah -- Jika ada spasi-spasi (seperti karakter lainnya) di dalam dokumen, maka mereka menjadi node teks di DOM tersebut, dan jika kita menghapusnya, maka tidak akan ada.
0 commit comments