Community News

getElementsByTagName() - Compact Implementation of the Method

martin_ivanov 16 Jan, 2009

Delicious StumbleUpon Reddit Subscribe

The method returns a list of elements with the given tag name. Here is a compact crossbrowser implementation that will reduce your code immensely.

Visit this link

Need more? Read these posts:

View All Community News

Comments

  1. aNieto2k 16 Jan, 2009

    Another more useful.

    function $tag(tagName, from) {
    return (from || document).getElementsByTagName(tagName);
    }

    // $tag("li");
    // $tag("li", document.getElementById("ULID"));

  2. Dwight 16 Jan, 2009

    "compact crossbrowser implementation"

    Whooo, you've just discovered aliases. Next time please try harder.
  3. wow 16 Jan, 2009

    how did this post from the past get featured? ive also got a killer javascript function:

    function $hello() {
    document.writeln("Hello world! I suck!");
    }
  4. Gizmo 16 Jan, 2009

    Not only this post is a waste of time and his author presumptuous, but he also manages to get it wrong.

    When making an alias you DO NOT wrap it in a function ! It introduce unnecessary overhead, just keep it simple :

    var $tag = document.getElementsByTagName;

    This will do the trick and his much better than your "cross-browser implementation" of a function which as always worked everywhere...
  5. Jamp Mark 17 Jan, 2009

    i find this post so amusing especially with this snippet by wow

    function $hello() {
    document.writeln("Hello world! I suck!");
    }

    it is cross browser too! LOL :D

Sorry, further comments are disabled for this post.

CSS Globe is a web design magazine brought to you by Alen Grakalic and kept fresh with member contributed news and exlusive articles.

CSSG Ads

Useful Links

Friends