To do this you need to have "return this.each" and optionally change
the instance of "this" which is the name of the object you are apply
the plugin to, to "obj" using "var obj = $(this);".

Then when you call a selector, you'll need to add "$('#nav a', obj)"
note the ", obj".

This will keep it within the name space of what ever selector you
apply this to when the plugin is initialize.

(function($){
        $.fn.extend({
                plauginNameHere: function() {
                return this.each(function() {
                                var obj = $(this); // this just changes the use 
of 'this' to obj

                                $('#nav a', obj).click(function(){
                                        $('#someDiv').fadeIn();
                                });

                        })
                }
        });
})(jQuery);

On the page level you will then need to initialize the plugin on the
HTML page level.

<script type="text/javascript" charset="utf-8">
        $(function(){
                $('#divNameHere'). plauginNameHere(); // first instance
                $('#secondDivNameHere'). plauginNameHere(); // second instance
        });
</script>

So what ever the selector name is above, for example
"#secondDivNameHere", will then be the 'this' that we changed to 'obj'
using a var in plugin script. So in this example the plugin's "obj" is
"#secondDivNameHere".

Let me know if that helps.





On Apr 6, 1:44 pm, Spot <s...@napalmriot.com> wrote:
> How would one develop a plugin which can exist multiple times on the
> same page, without conflicting with each others namespaces?

Reply via email to