I have these 2 buttons on Divi builder. My aim: when I click on "button 2", this one becomes in orange and "button 1" becomes in grey, and the opposite.
On Button setup (from the builder), I set empty Link field for these 2 buttons. BUT when I click, my current web page is reloaded…
I’ve added this script into Divi Theme Option > Integration > header, just to catch the click on the first button:
jQuery(function ($) {
$( document ).ready(function() {
$(".button1").on("click", function(){
event.preventDefault();
alert("Button clicked");
});
});
});
And for this Button 1, I set the CSS Class:
The result: no click is catched…
Could you help me guys to do my final aim please?
3
Answers
I've added this script:
And this custom CSS:
The click on buttons works fine ("price" text is updated successfuly), BUT the button apparence doesn't change...
Please try this instead,
I created two class orange and gray for border style
Then, button click event add class gray and remove it class orange and also add siblings to orange color and remove it’s gray color.
You can try this one out. Ignore the CSS, the main part is jQuery code.
The variable
buttons
contains the group of elements on which you want to add this feature.The "click" event handler is added, and rest is easy to understand.