-1

I am adding rows with a button that is working now, but I have another button to delete and is not working. This is my code in JS:

jQuery(document).ready(function () {

    var collectionCount = 0;

    jQuery('#add-another-collection').click(function (e) {
        e.preventDefault();

        var collectionList = jQuery('#collection-fields-list');

        var newWidget = collectionList.attr('data-prototype');

        newWidget = newWidget.replace(/__name__/g, collectionCount);
        collectionCount++;


        var newTr = jQuery('<tr></tr>').html(newWidget);
        newTr.appendTo(collectionList);

    });

    $('.remove-collection').click(function (e) {

        console.log('fdsffdsfds');
        e.preventDefault();
        $(this).parent().remove();

        return false;
    });
})

I put a console.log to check if a I am going through there but Not.

This is the button:

<button type="button" class="btn btn-danger remove-collection">Delete</button>

1 Answers1

0

If your button is added to the DOM dynamically you must use the following click handler:

$(document).on('click', '.remove-collection', function () {

});
DNKROZ
  • 2,634
  • 4
  • 25
  • 43