79366189

Date: 2025-01-17 22:01:01
Score: 2.5
Natty:
Report link

Improving great answer by @dmackerman a bit (I cannot comment yet) by preventing to delete if there is only one row

HTML:

<form>
    <p class="form_field">
        <label>Name:</label> <input type="text">
        <label>Age:</label> <input type="text">
        <span class="remove">Remove</span>
    </p>
    <p>
        <span class="add">Add fields</span>
    </p>
</form>

and JS:

$(".add").click(function() {
    $("form > p:first-child").clone(true).insertBefore("form > p:last-child");
    return false;
});

$(".remove").click(function() {
     if ($(".form_field").length > 1) {
        $(this).parent().remove();
    }
});
Reasons:
  • Blacklisted phrase (0.5): I cannot
  • RegEx Blacklisted phrase (1): cannot comment
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @dmackerman
  • Low reputation (1):
Posted by: Piotr PaƂucki