Stuck on structure of this jquery plugin
<p>I'm practicing jquery plugins and need help finishing this one, especially the outside skeleton. </p>

<p>Let's say I have this markup</p>

<pre><code>&lt;div class="tochange"&gt;&lt;/div&gt;
&lt;div class="tochange"&gt;&lt;/div&gt;
&lt;div class="tochange"&gt;&lt;/div&gt;
</code></pre>

<p>and I want the plugin to add to <code>div.tochange</code> this markup </p>

<pre><code>&lt;div class="root"&gt;Root&lt;/div&gt;
</code></pre>

<p>so that it's </p>

<pre><code>&lt;div class="tochange"&gt;
   &lt;div class="root"&gt;Root&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Then if the root is clicked, replace it with 2 divs so the markup looks like this</p>

<pre><code>&lt;div class="tochange"&gt;
   &lt;div class="child"&gt;Child&lt;/div&gt;
   &lt;div class="child"&gt;Child&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>If the child is clicked, it goes back to parent </p>

<pre><code>&lt;div class="tochange"&gt;
   &lt;div class="root"&gt;Root&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>I'm following <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">documentation</a> but I don't know if I need methods for this. My guess is that I do but I can't finalize the structure of this plugin in my head. This is my first plugin and I thought a practical idea of my own is the best way to learn, but I'm stuck. Can someone who's done this before set me on the right track. I'm a little lost on this.</p>

<pre><code>(function($){
    $.fn.sample = function(options) {

        var settings = {
            'possibleparam1' : 'value1',
        };

        var methods = {
            init: function( options ) { },
            tochildren : function( ) { },
            toparent : function( ) { },
        };


        return this.each(function() { /*(i) {*/
            // If options exist, merge them with our default settings
            if (options) { 
                $.extend(settings, options);
            }

            // plugin code goes here

        });

    };
})( jQuery );
</code></pre>
