Site logo

Archived topic

onclick for GB button

3 replies · Started by Dominik on June 29, 2021

Viewing posts 1–4 of 4

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:

https://forum.freecodecamp.org/t/pass-the-event-to-the-callback-within-the-event-listener-that-triggered-it/258259/2

Hi David,

THANKS – we used the EventListener method and worked :)

Best regards,
Dominik

Glad to be of help

This archived topic is closed to new replies.