D
drnicwilliams
[TUTORIAL]
The Prototype library gives us the $() operation for converting a DOM
element id into the DOM element: $('element-id'). It also appends a
bunch of functions to the resulting object.
Sometimes though, passing a string into the $() function doesn't read
well; and only makes Javascript code harder to read. For example:
$(window.button_list()[3]).hide()
Instead, it'd be nice to have normal chainability. I like the
following syntax: window.button_list()[3].$().hide().
That is, call the $() method on a string object, instead of passing the
string into the $() method.
Add this code into your application:
String.prototype.$ = function() {
return $(document.getElementById(this));
}
The Prototype library gives us the $() operation for converting a DOM
element id into the DOM element: $('element-id'). It also appends a
bunch of functions to the resulting object.
Sometimes though, passing a string into the $() function doesn't read
well; and only makes Javascript code harder to read. For example:
$(window.button_list()[3]).hide()
Instead, it'd be nice to have normal chainability. I like the
following syntax: window.button_list()[3].$().hide().
That is, call the $() method on a string object, instead of passing the
string into the $() method.
Add this code into your application:
String.prototype.$ = function() {
return $(document.getElementById(this));
}
http://drnicwilliams.com/2006/09/11/prototype-call-dollar-on-string/From article: