Just defining a function within the closure (function) you pass into $()
doesn't do anything to put it on the jQuery fn
object. To do that, you have to do it explicitly:
$.fn.someFunc = someFunc;
Typically, you wouldn't do this within a callback on $()
, you'd do it earlier. Plug-ins do this to add functionality, which should already be present prior to DOM ready.
By way of example, here's a silly little plug-in that turns text green:
(function($) {
$.fn.green = green;
function green() {
return this.css("color", "green");
}
})(jQuery);
...which you might use from DOM ready:
jQuery(function($) {
$(".foo").green();
});
Live example | Live source
Note that the call to it is from a jQuery instance, not directly from $.fn
.