Double loop in JQuery Statement
<p>I have this following Jquery code in my website, </p>

<pre><code>    $("#nav-tabs").on("click", "a", function(e) {
            e.preventDefault();
            $(this).tab('show');
        });

        var counter = 1;

        $('.plus').click(function(e) {

            if(counter &lt;= 3){
            $('#nav-tabs').append('&lt;a href="#tab' +&lt;/button&gt;&lt;/a&gt;&lt;/li&gt;');
            } else { alert("Only 3 Tabs Allowed!")};

            $('.tab-content').append('&lt;div class="tab-pane" id="tab' + counter + '"&gt;&lt;/div&gt;');
            if (counter &lt;= 3) {
                counter++;
            } else {};


        $('.close').click(function(e) {

            var panelId = $(this).closest("li").remove().attr("aria-controls");
            $("#tab" + panelId).remove();
            if(counter &lt; 1){
                counter = 1
                }else if (counter &gt;= 1) {
                    counter--;
                } else if (counter == 0) {
                    counter = 1
                };

        })

    });
</code></pre>

<p>My question is once i click .close instead of going once in the function, it again repeats itself an decrements my counter...</p>
