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

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -