I’m creating jQuery plugin:
$.fn.myGrid = function () {
return ???;
}
I want the return value of myGrid to include an add function, so that I can use it in the following way;
var grid = $(".myGrid").myGrid();
grid.add();
How can I do this? How I have to declare the add function? And what do I have to return in myGrid plugin?
I’d also be happy to have something that works like this;
$.myGrid.add();
Is it possible?
One approach you could use is this;
It’s important to capture the
thisvariable, because otherwise the methods on the object youreturnfrom yourmyGrid()function will not be able to access the jQuery object you invokedmyGrid()on.See the code in operation here; http://jsfiddle.net/HpeS8/