Using proper JavaScript, you can use querySelectorAll and addEventListener as shown here:
You do not necessarily have to give each button class “binder”, but if buttons have class “binder” then you could use document.querySelectorAll(".binder")
Even if I don’t understand for 100% what you want to achieve, what is the problem with my solution?
$('.binder').on('click', (event) =>
{
const button = $(event.currentTarget);
button.attr('thisFunc')(parameter);
buildUrl(button.attr('thisUrl');
... as I said you can do what you want with the button here...
})
You do have to use the data keyword instead of attr, though. I corrected that but it still doesn’t work.
$(‘.binder’).on(‘click’, (event) =>
{
const button = $(event.currentTarget);
button.data(‘thisFunc’)(parameter);
buildUrl(button.data(‘thisUrl’);
… as I said you can do what you want with the button here…
})
Apologies, I rejected using jQuery because I found it too restricting.
I thought that $(event.currentTarget) would return a html element and based my post on that assumption.
But I assume that jQuery requires a closing bracket for east opening bracket and not
There are no errors in the console and adding in console.log alerts doesn’t show anything either, like the code is not seeing the buttons at all. By “not work” I mean that the buttons don’t produce any action in the console or the browser.
You cannot add the handler before the elements are added to the Dom. So if your buttons are part of a jquery datatable Ajax call you need to add the handler in the draw callback
var table = $('#tableId').DataTable();
table.on( 'draw', function () {
// your add handler code here
});