spacer
Yehuda Shiran December 2, 2000
Extended Tag Extraction
Tips: December 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Both Internet Explorer 5 and Netscape 6 claim to be W3C-standard compliant. One supporting evidence is their support of the getElementsByTagName() method, which extracts an array of elements of the same tag type. This method applies to any element. You can extract all tags in a whole document, or in any other elements such a DIV, or a P. The following handleAllTags() function extracts all FONT tags in this tip as well as all tags in the DIV container that wraps the following code listing. It prints these two counts:

<SCRIPT LANGUAGE="JavaScript">
<!--
function handleAllTags() {
var arrayOfDocFonts, arrayOfDivFonts;
  if (document.all || document.getElementById) {
    arrayOfDivFonts = foo.getElementsByTagName("font");
    arrayOfDocFonts = document.getElementsByTagName("font");
  }
  else {
    document.write("Unrecognized Browser Detected");
  }
  alert("Number of font tags in document and DIV are " + arrayOfDocFonts.length + " and " + 
      arrayOfDivFonts.length + ", respectively.");
}
// -->
</SCRIPT>

Notice that the tags extracted from the DIV with ID="foo" are found by foo.getElementsByTagName("font"). All this tip's tags are extracted by document.getElementsByTagName("font"). This tip has been contributed by Thomas Ashe.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business