web developer toolbox

Home » JavaScript » DOM
Published: 2011 Mar. 01 Updated: 2011 Mar. 23

Company Name

getElementsByTagName

Read from the DOM using getElementsByTagName

Comments:

getElementsByTagName
syntax: document.getElementsByTagName("TAG_NAME");
returns: an array of tags requested if found, otherwise: undefined
tag name: use upper-case when requesting tag
length: use length property to know how many elements in array
limit search: use getElementById first to search only part of the DOM

Results:

Form:

  1. Name
  2. Address
  3. Phone
  4. no
  5. ...

Valid?

  • yes
  • yes
  • no
  • yes
  • No
  • NO
  • yes

Generated html:

Original html:

JavaScript:

Embedded css: