Skip to content

Commit 2a4ca9e

Browse files
bis closet
1 parent 3808ba9 commit 2a4ca9e

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

  • 2-ui/1-document/04-searching-elements-dom

2-ui/1-document/04-searching-elements-dom/article.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,19 @@ pseudo-classها در css selector مثل `:hover` و `:active` `document.query
111111

112112
## querySelector [#querySelector]
113113

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` فقط به دنبال یکی است. پس هم سریع‌تر است و هم برای نوشتن کوتاه‌تر است.
115118

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.
117119

118120
## matches
119121

120-
Previous methods were searching the DOM.
122+
روش‌های قبلی در DOM جستجو می‌کردند.
121123

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` برمی‌گرداند.
123125

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 کنیم و آن‌هایی که مطلوب هستند را فیلتر کنیم.
125127

126128
For instance:
127129

@@ -130,12 +132,14 @@ For instance:
130132
<a href="http://ya.ru">...</a>
131133

132134
<script>
133-
// can be any collection instead of document.body.children
135+
// باشد document.body.children می‌تواند هر مجموعه‌ای به جای
134136
for (let elem of document.body.children) {
135137
*!*
136138
if (elem.matches('a[href$="zip"]')) {
137139
*/!*
138140
alert("The archive reference: " + elem.href );
141+
alert("این آرشیو ارجاع می‌دهد به : " + elem.href );
142+
139143
}
140144
}
141145
</script>

0 commit comments

Comments
 (0)