November 28, 2000 - Tag Extraction | WebReference

November 28, 2000 - Tag Extraction

Yehuda Shiran November 28, 2000
Tag Extraction
Tips: November 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

There are several ways to extract an array of elements of the same tag type. Internet Explorer supports both the document.all.tags() method and the document.getElementsByTagName() method. On the other hand, Netscape 6 supports only the official W3C's standard document.getElementsByTagName() method. The following handleAllTags() function extracts all FONT tags and print their total count. We use the document.all.tags() method in Internet Explorer, and the getElementsByTagName() in Netscape 6:

function handleAllTags() {
var arrayOfFonts;
  if (document.all) {
    arrayOfFonts = document.all.tags("font");
  else if (document.getElementById) {
    arrayOfFonts = document.getElementsByTagName("font");
  else {
    document.write("Unrecognized Browser Detected");
  document.write("Number of font tags is " + arrayOfFonts.length);
// -->