getElementsByTagNames

Just like getElementsByClassNames, this is one of those useful tags that you wish was built-in to Javascript. It returns an array of all elements with the specified tags, ordered by position in the page.

<script>
var elements = widget.getElementsByTagNames(tags,object);
</script>

tags is a comma-delimited string of all the tags to return.
object is the element to search in. Default is document.

You might use it like so:

<div id="results"><!--A CONTAINER FOR INFO--></div>

<script>
function getAllHeadings() {
   var main = document.getElementById('displaycontent');
   var headings = widget.getElementsByTagNames('h1,h2,h3',main);
   var code = '';
   for (var i=0; i<headings.length; i++) {
      code += headings.innerHTML + '<br />';
   }

widget.onDocLoad(getAllHeadings);
</script>

This uses onDocLoad to call the function when the page is loaded completely.


Page Information

  • 1 year ago [history]
  • View page source
  • You're not logged in
  • No tags yet learn more

Wiki Information

Recent PBwiki Blog Posts