GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing javascript.info — Search for elements

  • Tutorial
  • Browser: Document, Events, Interfaces
  • Document
  • Searching: getElement*, querySelector*
back to the lesson

Search for elements

importance: 4

Here’s the document with the table and 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.

Open the page table.html in a separate window and make use of browser tools for that.

There are many ways to do it.

Here are some of them:

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

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

// 3. The first td in that table (with the word "Age")
table.rows[0].cells[0]
// or
table.getElementsByTagName('td')[0]
// or
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]
// or, form specifically
document.querySelector('form[name="search"]')

// 5. The first input in that form.
form.getElementsByTagName('input')[0]
// or
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
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.