Community News

getElementsByTagName() - Compact Implementation of the Method

posted by martin_ivanov on 16 Jan, 2009

Delicious Digg StumbleUpon Reddit Subscribe to RSS Feed

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

Go visit

Need more? Read these posts:

View All Community News

Comments

  1. aNieto2k on 16 Jan, 2009 wrote:

    Another more useful.

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

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

  2. Dwight on 16 Jan, 2009 wrote:

    "compact crossbrowser implementation"

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

    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 on 16 Jan, 2009 wrote:

    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 on 17 Jan, 2009 wrote:

    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.

Need help with your website?
Hire a CSS/JavaScript expert!

Hey, you are not logged in!
Apply for a membership or login here.

Subscribe to CSSG Feed

Want to join?

If you wish to contribute with your own articles, updates or gallery entries you can apply for a membership and even become our editor.

Apply here

Become a friend