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/07-modifying-document/article.md
+9-87Lines changed: 9 additions & 87 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,11 +28,7 @@ DOM التعديل هو مفتاح إنشاء صفحات "حية".
28
28
*/!*
29
29
```
30
30
31
-
<<<<<<< HEAD
32
31
كان هذا مثال HTML. الآن دعنا ننشئ نفس `div` باستخدام JavaScript (على افتراض أن الأنماط موجودة في HTML أو ملف CSS خارجي).
33
-
=======
34
-
That was the HTML example. Now let's create the same `div` with JavaScript (assuming that the styles are in the HTML/CSS already).
35
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
36
32
37
33
## إنشاء عنصر
38
34
@@ -52,17 +48,11 @@ That was the HTML example. Now let's create the same `div` with JavaScript (assu
52
48
let textNode = document.createTextNode('Here I am');
53
49
```
54
50
55
-
<<<<<<< HEAD
56
-
### إنشاء الرسالة
57
-
58
-
في حالتنا ، تكون الرسالة `div` مع فئة` تنبيه 'و HTML فيها:
59
-
=======
60
-
Most of the time we need to create element nodes, such as the `div` for the message.
51
+
في حالتنا، تكون الرسالة `div` مع فئة` تنبيه 'و HTML فيها:
61
52
62
-
### Creating the message
53
+
### إنشاء الرسالة
63
54
64
-
Creating the message div takes 3 steps:
65
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
55
+
في حالتنا، إنشاء `div` الرسالة ينطلب 3 مراحل:
66
56
67
57
```js
68
58
// 1. Create <div> element
@@ -75,73 +65,21 @@ div.className = "alert";
75
65
div.innerHTML="<strong>Hi there!</strong> You've read an important message.";
76
66
```
77
67
78
-
<<<<<<< HEAD
79
-
لقد أنشأنا العنصر ، ولكن حتى الآن إنه متغير فقط. لا يمكننا رؤية العنصر على الصفحة ، لأنه ليس جزءًا من المستند حتى الآن.
80
-
=======
81
-
We've created the element. But as of now it's only in a variable named `div`, not in the page yet. So we can't see it.
82
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
68
+
لقد أنشأنا العنصر ، ولكن حتى الآن إنه متغير فقط. لا يمكننا رؤية العنصر على الصفحة ، لأنه ليس جزءًا من المستند حتى الآن
83
69
84
70
## طرق الإدراج
85
71
86
-
<<<<<<< HEAD
87
-
لعرض "div" ، نحتاج إلى إدراجه في مكان ما في "المستند". على سبيل المثال ، في `document.body`.
88
-
=======
89
-
To make the `div` show up, we need to insert it somewhere into `document`. For instance, into `<body>` element, referenced by `document.body`.
90
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
91
-
92
-
هناك طريقة خاصة `append` لذلك:` document.body.append (div) `.
93
-
94
-
إليك الكود الكامل:
95
-
96
-
```html run height="80"
97
-
<style>
98
-
.alert {
99
-
padding: 15px;
100
-
border: 1pxsolid#d6e9c6;
101
-
border-radius: 4px;
102
-
color: #3c763d;
103
-
background-color: #dff0d8;
104
-
}
105
-
</style>
72
+
لعرض "div" ، نحتاج إلى إدراجه في مكان ما في "المستند". على سبيل المثال ، في `document.body`. هناك طريقة خاصة `append` لذلك:` document.body.append (div) `.
106
73
107
-
<script>
108
-
let div =document.createElement('div');
109
-
div.className="alert";
110
-
div.innerHTML="<strong>Hi there!</strong> You've read an important message.";
111
-
112
-
*!*
113
-
document.body.append(div);
114
-
*/!*
115
-
</script>
116
-
```
117
-
118
-
<<<<<<< HEAD
119
74
توفر هذه المجموعة من الطرق المزيد من الطرق لإدراج:
120
75
121
76
-`node.append (... nodes or strings)` - إلحاق عقد أو سلاسل في نهاية `node` ،
122
77
-`node.prepend (... العقد أو السلاسل)` - إدراج العقد أو السلاسل في بداية `العقدة` ،
123
78
-`node.before (... nodes or strings)` –- أدخل العقد أو السلاسل قبل `node` ،
124
-
-`العقدة بعد (... العقد أو السلاسل)` - - إدراج العقد أو السلاسل بعد `العقدة` ،
79
+
-`node.after(...nodes or strings)` - إدراج العقد أو السلاسل بعد `العقدة` ،
125
80
-`node.replaceWith (... العقد أو السلاسل)` - - يستبدل `العقدة` بالعقد أو السلاسل المعطاة.
126
81
127
82
فيما يلي مثال على استخدام هذه الأساليب لإضافة عناصر إلى قائمة والنص قبلها / بعدها:
128
-
=======
129
-
Here we called `append` on `document.body`, but we can call `append` method on any other element, to put another element into it. For instance, we can append something to `<div>` by calling `div.append(anotherElement)`.
130
-
131
-
Here are more insertion methods, they specify different places where to insert:
132
-
133
-
-`node.append(...nodes or strings)` -- append nodes or strings *at the end* of `node`,
134
-
-`node.prepend(...nodes or strings)` -- insert nodes or strings *at the beginning* of `node`,
135
-
-`node.before(...nodes or strings)` –- insert nodes or strings *before*`node`,
136
-
-`node.after(...nodes or strings)` –- insert nodes or strings *after*`node`,
137
-
-`node.replaceWith(...nodes or strings)` –- replaces `node` with the given nodes or strings.
138
-
139
-
Arguments of these methods are an arbitrary list of DOM nodes to insert, or text strings (that become text nodes automatically).
140
-
141
-
Let's see them in action.
142
-
143
-
Here's an example of using these methods to add items to a list and the text before/after it:
144
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
145
83
146
84
```html autorun
147
85
<olid="ol">
@@ -164,11 +102,7 @@ Here's an example of using these methods to add items to a list and the text bef
164
102
</script>
165
103
```
166
104
167
-
<<<<<<< HEAD
168
105
هذه صورة بصرية عن الأساليب التي تفعلها:
169
-
=======
170
-
Here's a visual picture of what the methods do:
171
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
172
106
173
107

174
108
@@ -186,11 +120,7 @@ before
186
120
after
187
121
```
188
122
189
-
<<<<<<< HEAD
190
123
يمكن لهذه الطرق إدراج قوائم متعددة للعقد والقطع النصية في مكالمة واحدة.
191
-
=======
192
-
As said, these methods can insert multiple nodes and text pieces in a single call.
193
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
194
124
195
125
على سبيل المثال ، هنا يتم إدراج سلسلة وعنصر:
196
126
@@ -201,11 +131,7 @@ As said, these methods can insert multiple nodes and text pieces in a single cal
201
131
</script>
202
132
```
203
133
204
-
<<<<<<< HEAD
205
-
يتم إدراج كل النص * كنص *.
206
-
=======
207
-
Please note: the text is inserted "as text", not "as HTML", with proper escaping of characters such as `<`, `>`.
208
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
134
+
يتم إدراج كل النص * كنص *.
209
135
210
136
إذن HTML النهائي هو:
211
137
@@ -221,11 +147,7 @@ Please note: the text is inserted "as text", not "as HTML", with proper escaping
221
147
222
148
لذلك ، لا يمكن استخدام هذه الطرق إلا لإدراج عقد DOM أو أجزاء نصية.
223
149
224
-
<<<<<<< HEAD
225
-
ولكن ماذا لو أردنا إدراج HTML "كـ html" ، مع عمل جميع العلامات والأشياء ، مثل `elem.innerHTML`؟
226
-
=======
227
-
But what if we'd like to insert an HTML string "as html", with all tags and stuff working, in the same manner as `elem.innerHTML` does it?
228
-
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
150
+
ولكن ماذا لو أردنا إدراج HTML "كـ html" ، مع عمل جميع العلامات والأشياء ، مثل `elem.innerHTML`?
0 commit comments