I've tried a few different variations of this but for some reason, none of it seems to be working for me.
I issue an ajax get and loop through the response to print rows to the html. Each row has a button to delete that element from the row.
It's a little bit lengthy, but here is that ajax get with how I run through the response to append rows to the table.
function getIEXSymbolQuote(symbol) {
                $.ajax({
                    url: IEXurlBase + "/stock/" + symbol + "/quote",
                    method: "GET",
                    success: function (data) {
                        symbol = data.symbol;
                        companyName = data.companyName;
                        change = data.change;
                        changePercent = data.changePercent * 100;
                        changePercent = changePercent.toFixed(2);
                        iexRealtimePrice = data.iexRealtimePrice;
                        iexRealtimePrice = iexRealtimePrice.toLocaleString();
                        close = data.close;
                        close = close.toLocaleString();
                        if (iexRealtimePrice === null) {
                            if (change > 0) {
                                $('#watchListItems').append("<tr id='" + symbol + "'><td><small>" + symbol + "</small></td><td style='color: #ffc107'><small>$" + latestPrice + "</small></td><td class='positive-data'><small>$" + change + "</small></td><td class='positive-data'><small>+" + changePercent + "%</small></td><td><button id ='" + symbol + "' class='btn btn-danger btn-sm removeWatchListitem'><i class='fa fa-trash'></i></button></td></tr>");
                            } else {
                                $('#watchListItems').append("<tr id='" + symbol + "'><td><small>" + symbol + "</small></td><td style='color: #ffc107'><small>$" + latestPrice + "</small></td><td style='color: red'><small>$" + change + "</small></td><td style='color: red'><small>" + changePercent + "%</small></td><td><button id ='" + symbol + "' class='btn btn-danger btn-sm removeWatchListitem'><i class='fa fa-trash'></i></button></td></tr>");
                            }
                        } else {
                            if (change > 0) {
                                $('#watchListItems').append("<tr id='" + symbol + "'><td><small>" + symbol + "</small></td><td style='color: #ffc107'><small>$" + iexRealtimePrice + "</small></td><td class='positive-data'><small>$" + change + "</small></td><td class='positive-data'><small>+" + changePercent + "%</small></td><td><button id ='" + symbol + "' class='btn btn-danger btn-sm removeWatchListitem'><i class='fa fa-trash'></i></button></td></tr>");
                            } else {
                                $('#watchListItems').append("<tr id='" + symbol + "'><td><small>" + symbol + "</small></td><td style='color: #ffc107'><small >$" + iexRealtimePrice + "</small></td><td style='color: red'><small>$" + change + "</small></td><td style='color: red'><small>" + changePercent + "%</small></td><td><button id ='" + symbol + "' class='btn btn-danger btn-sm removeWatchListitem'><i class='fa fa-trash'></i></button></td></tr>");
                            }
                        }
                        $('#watchListTable').css('visibility', 'visible');
                        $('#watchListErrBox').css('visibility', 'hidden');
                    },
                    error: function (err) {
                        $('#watchListErrBox').css('visibility', 'visible');
                    }
                })
            }
I need to be able to click on one of the trash buttons and get the id of the button clicked.
I've tried:
$("button").on("click", "button.removeWatchListitem", function () {
    event.preventDefault();
    alert($(this.id));
});
And;
$(".removeWatchListitem").on("click", function () {
    event.preventDefault();
    alert($(this.id));
});
but neither fire. This should be simple but I don't know if I'm just having a massive brain fart.
 
    