0

I have a form which does a small calculation and display data in table rows. I have also added a button to remove each row at the end. But when I do the calculation couple of times the button gets duplicated. Please refer to the image below.

Image

JS Fiddle

Following is how I append the button

    $(document).ready(function () {
    $('#calculate').click(function () {
    var removeBtn = $('<button class="removeBtn" id="removeBtn">Remove</button>');
                    $('.row-time').append(removeBtn);

        });
    });

I don't understand why the button gets duplicated everytime I add a new row.

2
  • You don't specify the specific row to add the button to so its adding it to all rows because you use a class as selector i.e. a group of rows Commented Feb 7, 2018 at 11:12
  • @ Reopen Reviewers - The duplicate target question, which is by the same author, has been deleted. Commented Mar 12, 2018 at 0:14

1 Answer 1

2

Use last for last class.

$('.row-time:last').append(removeBtn);

Working Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.