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(); 

​ jsfiddle demo

please read writing jquery plugins additional guidelines.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -