Objective
When my button is clicked, I want to add a class name to a different element.
My button code:
<a href="#" class="elementor-button-link elementor-button elementor-size-lg" role="button" id="explorebuttonid">
Class before button is clicked. This is not the same class as the button:
<div class="elementor-menu-cart__container elementor-lightbox">
Desired class after button is clicked. This is not the same class as the button:
<div class="elementor-menu-cart__container elementor-lightbox elementor-menu-cart--shown">
Problem
When I try the below, nothing happens when the button is clicked.
What I have tried
I have tried implementing these two together:
1) Add a click listener: Link
2) Insert a function to alter the class name: Link
<script>
document.getElementById("explorebuttonid").addEventListener("click", clicky1);
function clicky1() {
var clicky2 = document.getElementsByClassName("elementor-menu-cart__container elementor-lightbox");
clicky2.className += "elementor-menu-cart--shown";
}
</script>