Exos Exos - 9 days ago 5
Javascript Question

jQuery plugin access

I'm doing a youtube player in jQuery, and I make this as a jQuery plugin, ex:

$.fn.extend({

uplayList: {},

CreateUplayList: function (options) {
this.each(function () {
$(this).uplayList = new $.playList(this, options);
});
}
});


But, if I do:

$('#playlist').CreateUplayList({....});


And I want access at the instance:

$('#playlist').uplayList.play();


This not work, that make sense, because $('#playlist') is a selector. I see in others plugins something like that:

$('#playlist').pluginname('play');


How can I apply this??

Answer

See the "Adding Methods to a Widget" section of the "Stateful Plugins" section of the jQuery Plugin Authoring Guide.

Comments