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/04-searching-elements-dom/article.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,17 +111,19 @@ pseudo-classها در css selector مثل `:hover` و `:active` `document.query
111
111
112
112
## querySelector [#querySelector]
113
113
114
-
The call to `elem.querySelector(css)` returns the first element for the given CSS selector.
114
+
فراخوانی `elem.querySelector(css)` اولین element را برای css selector داده شده برمیگرداند.
115
+
116
+
117
+
به عبارت دیگر، نتیجه با `elem.querySelectorAll(css)[0]` یکسان است اما دومی به دنبال *تمام* elementها است و یکی را انتخاب میکند در حالی که `elem.querySelector` فقط به دنبال یکی است. پس هم سریعتر است و هم برای نوشتن کوتاهتر است.
115
118
116
-
In other words, the result is the same as `elem.querySelectorAll(css)[0]`, but the latter is looking for *all* elements and picking one, while `elem.querySelector` just looks for one. So it's faster and also shorter to write.
117
119
118
120
## matches
119
121
120
-
Previous methods were searching the DOM.
122
+
روشهای قبلی در DOM جستجو میکردند.
121
123
122
-
The[elem.matches(css)](https://dom.spec.whatwg.org/#dom-element-matches)does not look for anything, it merely checks if `elem` matches the given CSS-selector. It returns `true`or`false`.
124
+
عبارت[elem.matches(css)](https://dom.spec.whatwg.org/#dom-element-matches)در جستجوی چیزی نیست، فقط چک میکند که element با CSS-selector داده شده مطابقت دارد یا نه و `true`یا`false` برمیگرداند.
123
125
124
-
The method comes in handy when we are iterating over elements (like in an array or something) and trying to filter out those that interest us.
126
+
این روش زمانی به کار میآید که میخواهیم روی elementهایی (مثل آرایه یا همچین چیزی) iterate کنیم و آنهایی که مطلوب هستند را فیلتر کنیم.
125
127
126
128
For instance:
127
129
@@ -130,12 +132,14 @@ For instance:
130
132
<ahref="http://ya.ru">...</a>
131
133
132
134
<script>
133
-
//can be any collection instead of document.body.children
135
+
//باشد document.body.children میتواند هر مجموعهای به جای
0 commit comments