Archived topic
onclick for GB button
3 replies · Started by Dominik on June 29, 2021
Hi there,
I am using GenerateBlocks buttons for several sticky buttons (with help of elements) and want to add an onclick event triggering a javascript function to one of the buttons. How can I add the onclick to the button? I didn't find a solution yet.
Thanks and best wishes,
Dominik
Hi there,
you cannot ( currently - not sure if we will add it either ) add the onClick attribute to a GB Button. It would either require the button to be created using HTML or - use an eventListener in your JS eg.
document.getElementById("my_button_ID").addEventListener("click", function() {
// Do stuff here
});
Nice example here for passing Event parameters to your function:
Hi David,
THANKS – we used the EventListener method and worked :)
Best regards,
Dominik
Glad to be of help