Showing or hiding groups of three text fields &lt;div id="members"&gt;
    &lt;div id="inputRow0"&gt;
        &lt;input id="input0_0" class="input" type="text" /&gt;&lt;br/&gt;
        &lt;input id="input0_1" class="input" type="text" /&gt;&lt;br/&gt;
        &lt;input id="input0_2" class="input" type="text" /&gt;
    &lt;/div&gt;
    &lt;div id="inputRow1"&gt;
        &lt;input id="input1_0" class="input" type="text" /&gt;&lt;br/&gt;
        &lt;input id="input1_1" class="input" type="text" /&gt;&lt;br/&gt;
        &lt;input id="input1_2" class="input" type="text" /&gt;
    &lt;/div&gt;
    &lt;div id="inputRow2"&gt;
        &lt;input id="input2_0" class="input" type="text" /&gt;&lt;br/&gt;
        &lt;input id="input2_1" class="input" type="text" /&gt;&lt;br/&gt;
        &lt;input id="input2_2" class="input" type="text" /&gt;
    &lt;/div&gt;
&lt;/div&gt;  
&lt;br /&gt;&lt;a id="add-more" href="#"&gt;add-more&lt;/a&gt; &lt;a id="remove-last" href="#"&gt;remove-last&lt;/&gt;


js part that we need to deal with:

$("#inputRow1").hide();
$("#inputRow2").hide();
$("#remove-last").hide();

$("#add-more").click(function(){

    //count how many *direct children* elements are hidden.
    var hiddenElements = $('#members &gt;:hidden').length;

    $("#remove-last").show();    

    if (hiddenElements === 2) {
        $("#inputRow1").show();
    } else if(hiddenElements === 1) {
        $("#inputRow2").show();
        $(this).hide();
    }
});

$("#remove-last").click(function(){

    //count how many *direct children* elements are hidden.
    var hiddenElements = $('#members &gt;:hidden').length;
    $("#add-more").show();    

    if (hiddenElements === 0) {
        $("#inputRow"+2).hide();
    } else if (hiddenElements === 1) {
         $("#inputRow"+hiddenElements).hide();
        $(this).hide();
    }

});


Working example:
http://jsfiddle.net/URkuW/
What problem are you trying to solve? I've left your code doing the same things but rather than interrogate the DOM each time I've cached everything in local variables. 

// Execute code in an Immediately Invoked Function Expression (IIFE)
// This helps stop your variables polluting the global scope.
(function () { 

    // opt in to ECMAScript 5's strict mode 
    "use strict";

    // As we aren't changing the DOM just store all of the selectors in 
    // local variables - it's cheaper than hitting the DOM each time.
    var inputRow1 = $('#inputRow1').hide(), 
        inputRow2 = $('#inputRow2').hide(),
        addRowLink = $('#add-more'),
        removeRowLink = $("#remove-last").hide(),
        // rather than checking the DOM for number of hidden children,
        // just keep track of the last row visible (0, 1 or 2)
        lastRowVisible = 0; 


    addRowLink.click(function(event) {
        // stop the default action of the click event.
        event.preventDefault();

        // This is the initial state with only the first 3 input boxes showing
        // we need to show row 1 and the remove last link as well as increment the
        // last row visible to 1.
        if (lastRowVisible === 0) {
            removeRowLink.show();
            inputRow1.show();
            ++lastRowVisible;
        // The first two rows are visible. Show the last row and hide the add-more
        // link as well as increment the last row visible to 2.
        } else if (lastRowVisible === 1) {
            addRowLink.hide();
            inputRow2.show();
            ++lastRowVisible;
        }   
    });

    removeRowLink.click(function(event){
        // stop the default action of the click event.
        event.preventDefault();

        // All 3 rows currently visible: need to hide the last row, show
        // the add-more link and decrement the last row visible to 1.
        if (lastRowVisible === 2) {
            addRowLink.show();
            inputRow2.hide();
            --lastRowVisible;

        // 2 rows currently visible: need to hide the second row and the
        // remove-last link and decrement the last row visible to 0.
        } else if (lastRowVisible === 1) {
            removeRowLink.hide();
            inputRow1.hide();
            --lastRowVisible;
        }   
    });   
}());


Here's a working fiddle: http://jsfiddle.net/RobH/CDVBs/1/

Have you considered a solution that starts with only 3 inputs and then creates extra inputs instead of showing ones that are already declared but hidden?