Developing plugin that isn't altering existing elements
Hi all
I am new to jQuery plugin dev (but have been coding in JS and using jQuery for years).
I read the primer on developing plugins (http://docs.jquery.com/Plugins/Authoring). It's a great intro, and got the basics across well.
The problem I am having is that the plugin I want to develop is not centered around an existing element in the DOM. For the most part, it will be creating new elements on the fly for the user to interact with.
So, onto the question: What is the best way of setting up the plugin and calling it? Right now I am doing like the example -
- (function( $ ){
- $.fn.myPlugin = function(foo) {
- //my plugin code
- }
- })(jQuery);
And then calling it like -
- $(document).myPlugin({foo: 'bar'});
It seems silly to call it part of the document, when my plugin will never need the selector.
Any thoughts?