The true power of jQuery is its ability to quickly and easily select and use the DOM. Fortunately, we can expand this power by adding our wrapper methods that control the selected DOM elements, as we consider appropriate. By adding wrap-per methods, we automatically get the use of powerful jQuery selectors to select and choose which elements should work, without having to do all the work ourselves.
Given what we know about JavaScript, we could probably figure out how to add function functions to the $ namespace, but this is not necessarily true for the wrapper. Theres is concise jQuery-specific information that we need to know: to add shell methods to jQuery we must assign them as properties for an object named fn in the namespace. The general template for creating a wrapper function is
$.fn.wrapperFunctionName = function(params){function-body};
Lets you come up with a trivial wrapper method to set the color of matching DOM elements to blue:
(function($){ $.fn.makeItBlue = function() { return this.css('color','blue'); }; })(jQuery);
http://www.manning.com/bibeault2/
source share