Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Top 10 Custom JavaScript Functions Of All Time

By Dustin Diaz
2006-08-22


Last but not least, a bonus function: The Prototype Dollar Function

This function straight up kicks so much ass. First of all, just look at it.

Prototype function $

function $() {

var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}

// Sample Usage:
var obj1 = document.getElementById('element1');
var obj2 = document.getElementById('element2');
function alertElements() {
var i;
var elements = $('a','b','c',obj1,obj2,'d','e');
for ( i=0;i

Tell me that’s not beautiful! Short not only by name, but by reference. It not only takes in strings, it takes objects too. You can pass it one argument, or pass it many! This by far is my favorite function of all time which will provide years and years of handiness.



Tutorial Pages:
» Top 10 custom JavaScript functions of all time
» 10) addEvent()
» 9) addLoadEvent()
» 8) getElementsByClass()
» 7) cssQuery()
» 6) toggle()
» 5) insertAfter()
» 4) inArray()
» 3, 2, & 1) getCookie(), setCookie(), deleteCookie()
» Last but not least, a bonus function: The Prototype Dollar Function
» And so will they all…


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources