Support Forums

Support Offline : Mon - Fri / 10am - 6pm (GMT +6)

Your Time: Our Time:

How to add onClick() and other attributes to buttons?

Featured Lock Resolved Task
Hi I want to be able to have an onclick method attached to a button in a button group for Analytics event tracking. Is there a way to do it currently or can you add a section in the Advanced tab to do this in a future update?

At the very least please make it so you can assign an id to any of the elements in SP Page Builder, that way I can target the button using JQuery.

4 Answers

Sifat - Staff

More than a month ago #Permalink
Hi,
Thanks for your query. You can add your custom js code here https://prnt.sc/imy2bu
Please add a button group https://prnt.sc/imy2uo to check this demo code.

let buttons = document.querySelectorAll(".sppb-addon-button-group a");
buttons = Array.from(buttons);
buttons.forEach(function(e){
e.onclick = function() {
alert(this.innerText);
}
})



-Best Regards

Kamron Brooks

More than a month ago #Permalink
Hi,
Thanks for your query. You can add your custom js code here https://prnt.sc/imy2bu
Please add a button group https://prnt.sc/imy2uo to check this demo code.

let buttons = document.querySelectorAll(".sppb-addon-button-group a");
buttons = Array.from(buttons);
buttons.forEach(function(e){
e.onclick = function() {
alert(this.innerText);
}
})



-Best Regards


That's fine if I want to add the same onClick to every button on the page, I was hoping for an easier way to add a single onClick to a single button.

In a future update it'd be great if you could have an advanced tab on each object that would let us enter in things like onclick, target, or any other custom attributes to an item (such as data-event[] and such).

Sifat - Staff

More than a month ago #Permalink
Hi,
Thanks for your valuable suggestion. I'll add this into our feature requests. That's what i can do for you.

-Best Regards


There are no replies made for this post yet.
Be one of the first to reply to this post!

Leaderboard (30 days)

Paul Frankowski

Paul Frankowski

Total Accepted Answers: 127
Sifat

Sifat

Total Accepted Answers: 83
Toufiq

Toufiq

Total Accepted Answers: 71
Pavel

Pavel

Total Accepted Answers: 6
Rifat Wahid Alif

Rifat Wahid Alif

Total Accepted Answers: 5

114

Templates

293293

Community Users

Newsletter

Don’t miss any updates of our new templates and extensions and all the astonishing offers we bring for you.
We never spam

Joomla! ® name is used under a limited license from Open Source Matters in the United States and other countries. JoomShaper.com is not affiliated with or endorsed by Open Source Matters or the Joomla! Project.

Connect Us