I've got a piece of code that looks like this and works as expected
const $tableID = $('#edit_history_table');
$tableID.on('click', '.table-save', function() {
var currentRow = $(this).closest("tr");
var key = currentRow.find("td:eq(0)").text(); // get current row 1st TD value
...
});
If you click on the save icon in a table it gets that rows data. Now for integration in other parts I need to convert it to a named function so that (for example) a 'save all' button can just loop through the records and save each one of them.
I was expecting something like this to do the trick (where you pass the row as the parameter so you can use the function in the fore-mentioned use case)
$tableID.on('click', '.table-save', save_row($(this).closest("tr")));
function save_row(currentRow) {
alert(currentRow);
var key = currentRow.find("td:eq(0)").text(); // get current row 1st TD value
...
}
But when launching the page, I immediately see the alert box. And when clicking the button nothing happens.
I honestly don't really have a clue how to do it in another way...
No anonymous function can be used like in these answers.