Placing a counter incrementing and decrementing when items are added and removed using jquery
<p>Please find the code below</p>

<pre><code>&lt;script type="text/javascript"&gt;
    $(function(){
    var c=1;
        $("#i1").toggle(function(){
            $("#e1").appendTo("#i2");
            $('#counter').attr('value',c);

        },
        function(){
            $("#e1").appendTo($(this));
           $('#counter').attr('value',c);
        });
    c++; 
    });
    &lt;/script&gt;
    &lt;div id=i1&gt;&lt;span id="e1"&gt;Item 1&lt;/span&gt;&lt;/div&gt;
    &lt;div id=i2&gt;&lt;span id="e2"&gt;Item 2&lt;/span&gt;&lt;/div&gt;

    &lt;input type=text value='' id=counter&gt;
</code></pre>

<p>When the counter is placed, it does increment and decrement, but the value goes up by +2 each time I click on add, and -1 on remove.</p>

<p>What exactly is wrong</p>

<p>Thanks
Jean</p>
