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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint