Working together for standards The Web Standards Project


getElementsByTagNames()

By Peter-Paul Koch | January 30th, 2006 | Filed in DOM, DOM Scripting TF, W3C/Standards Documentation

getElementsByTagNames() returns elements with several tag names in the order they appear in the document.

Skip to comment form

One of my fondest W3C DOM wishes is a getElementsByTagNames() method (note the plural “names”) that returns elements with several tag names in the order they appear in the document. This is extremely useful in for instance my ToC script which needs all h3s and h4s in the order they appear in the source code.

When I discovered the compareDocumentPosition() method in Level 3 Core, I could finally write a custom script that works in most browsers.

Therefore I now proudly present my new getElementsByTagNames() script. It requires either sourceIndex or compareDocumentPosition to work fully, and since Safari 1.3.2 supports neither the script doesn’t sort the elements in this browser.

Return to top

Post a Reply

Comments are closed.


All of the entries posted in WaSP Buzz express the opinions of their individual authors. They do not necessarily reflect the plans or positions of the Web Standards Project as a group.

This site is valid XHTML 1.0 Strict, CSS | Get Buzz via RSS or Atom | Colophon | Legal