jQuery plug-in with additional methods.
Posted
by Kieron
on Stack Overflow
See other posts from Stack Overflow
or by Kieron
Published on 2009-09-08T13:28:11Z
Indexed on
2010/03/31
16:03 UTC
Read the original article
Hit count: 447
I've a jQuery plug-in that operates on some ULs, adding and removing classes etc.
During the life-cycle of the page, I'll need to add/ remove some classes in code, and as my plug-in needs to perform some additional operations when this happens I came up with the following:
// This is the initialiser method...
$.fn.objectBuilder = function (options) {...};
// These are the two new methods I need.
$.fn.objectBuilder.setSelected(element) {...};
$.fn.objectBuilder.removeSelected() {...};
I'd then like to call them like this:
$("#ob1").objectbuilder.removeSelected();
Any thoughts?
Thanks, Kieron
edit
I suppose what I'm asking is, whats the best way of adding additional methods to a jQuery plug-in where it'll have access to the root object, in this case #obj when the method is called.
© Stack Overflow or respective owner