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.Need more? Read these posts:
- CSS Specificity Coding Method
- A methodic approach to CSS coding: Four Bubbles Model
- Four Methods to Create Equal Height Columns
- 10 Essential DOM Methods & Techniques for Practical JavaScript
- A New Image Replacement Technique: The State Scope Method
Comments
Sorry, further comments are disabled for this post.
Need help with your website?
Hire a CSS/JavaScript expert!
Hire a CSS/JavaScript expert!
Hey, you are not logged in!
Apply for a membership
or
login here.
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.
aNieto2k on 16 Jan, 2009 wrote:
function $tag(tagName, from) {
return (from || document).getElementsByTagName(tagName);
}
// $tag("li");
// $tag("li", document.getElementById("ULID"));
Dwight on 16 Jan, 2009 wrote:
Whooo, you've just discovered aliases. Next time please try harder.
wow on 16 Jan, 2009 wrote:
function $hello() {
document.writeln("Hello world! I suck!");
}
Gizmo on 16 Jan, 2009 wrote:
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 on 17 Jan, 2009 wrote:
function $hello() {
document.writeln("Hello world! I suck!");
}
it is cross browser too! LOL :D