Community News
getElementsByTagName() - Compact Implementation of the Method
martin_ivanov 16 Jan, 2009
Share on Facebook Tweet this 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.
Need more? Read these posts:
- 5 CSS Methods to Style a Block with Background
- The Seven Deadly Sins Of JavaScript Implementation
- CSS Specificity Coding Method
- A methodic approach to CSS coding: Four Bubbles Model
- Four Methods to Create Equal Height Columns
Comments
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.
aNieto2k 16 Jan, 2009
function $tag(tagName, from) {
return (from || document).getElementsByTagName(tagName);
}
// $tag("li");
// $tag("li", document.getElementById("ULID"));
Dwight 16 Jan, 2009
Whooo, you've just discovered aliases. Next time please try harder.
wow 16 Jan, 2009
function $hello() {
document.writeln("Hello world! I suck!");
}
Gizmo 16 Jan, 2009
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...
Jamp Mark 17 Jan, 2009
function $hello() {
document.writeln("Hello world! I suck!");
}
it is cross browser too! LOL :D