I've seen some jquery code where people extend the main object like:
$('someId').myCustomObject();
Is this possible or am I mistaken? (if yes, how?)
I've seen some jquery code where people extend the main object like:
$('someId').myCustomObject();
Is this possible or am I mistaken? (if yes, how?)
Yes it's easily possible. The standard pattern for building extensions is:
(function($) {
$.fn.myCustomObject = function(options) {
var defaults = { ... };
var opts = $.extend(defaults, options);
this.each(function(i) {
... // Act on each item, $(this).
... // Use opts.blah to read merged options.
});
};
})(jQuery);
This allows you to use '$' in the plug-in, yet allows compatibility mode.