javascript - How to add new methods to the jQuery object? -
is there way add methods jquery's objects?
for example, have jquery object
a = $('div') i'd every object assigned that, have particular method (dosomething()) invoke
a = $('.foo') a.dosomething() b = $('.bar') b.dosomething()
you have add function $.fn namespace. please note inside function, this refer jquery object, not dom object.
$.fn.dosomething = function () { this.css('color', 'red'); }; $('#retk').dosomething(); please read writing jquery plugins additional guidelines.
Comments
Post a Comment