Skip to content

Searching: getElement*, querySelector* #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
There are many ways to do it.
هناك العديد من الطرق للقيام بذلك.

Here are some of them:
إليك بعضاً منها:

```js
// 1. The table with `id="age-table"`.
let table = document.getElementById('age-table')
let table = document.getElementById("age-table");

// 2. All label elements inside that table
table.getElementsByTagName('label')
table.getElementsByTagName("label");
// or
document.querySelectorAll('#age-table label')
document.querySelectorAll("#age-table label");

// 3. The first td in that table (with the word "Age")
table.rows[0].cells[0]
table.rows[0].cells[0];
// or
table.getElementsByTagName('td')[0]
table.getElementsByTagName("td")[0];
// or
table.querySelector('td')
table.querySelector("td");

// 4. The form with the name "search"
// assuming there's only one element with name="search" in the document
let form = document.getElementsByName('search')[0]
let form = document.getElementsByName("search")[0];
// or, form specifically
document.querySelector('form[name="search"]')
document.querySelector('form[name="search"]');

// 5. The first input in that form.
form.getElementsByTagName('input')[0]
form.getElementsByTagName("input")[0];
// or
form.querySelector('input')
form.querySelector("input");

// 6. The last input in that form
let inputs = form.querySelectorAll('input') // find all inputs
inputs[inputs.length-1] // take the last one
let inputs = form.querySelectorAll("input"); // find all inputs
inputs[inputs.length - 1]; // take the last one
```
20 changes: 10 additions & 10 deletions 2-ui/1-document/04-searching-elements-dom/1-find-elements/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ importance: 4

---

# Search for elements
# البحث عن العناصر

Here's the document with the table and form.
إليك مستند يحتوي على جدول table ونموذج form.

How to find?...
كيف يمكننا إيجاد؟...

1. The table with `id="age-table"`.
2. All `label` elements inside that table (there should be 3 of them).
3. The first `td` in that table (with the word "Age").
4. The `form` with `name="search"`.
5. The first `input` in that form.
6. The last `input` in that form.
1. الجدول الذي يحتوي على "id="age-table"..
2. جميع عناصر ال `label` داخل هذا الجدول (يجب أن يكون هناك 3 منها).
3. أول `td` في هذا الجدول (مع كلمة "العمر").
4. ال form ذو السمة `name="search"`.
5. أول `input` في تلك ال form.
6. أخر `input`في تلك ال form.

Open the page [table.html](table.html) in a separate window and make use of browser tools for that.
افتح الصفحة [table.html](table.html) في نافذة منفصلة واستخدم أدوات المتصفح لذلك.
Loading