Solved

Changing add to cart class for animation

  • 6 October 2022
  • 1 reply
  • 9 views

Badge
There the class is not static maybe this why add cart is not working. please help me
 

 

icon

Best answer by Dov 6 October 2022, 20:07

View original

1 reply

Userlevel 7
Badge +61

Hi@proecom,

Thanks for sharing this with us.

As a first step, since your buttons have multiple classes, I recommend targeting one of the “common denominator classes” in your added to cart snippet that is consistent for all buttons that isn’t changing i.e. btn--add-to-cart

If that doesn’t work, you can try targeting the parent class telling it to find any nested buttons.  This would require a query selector as oppose to getElementByClassname:

<script type="text/javascript">
var _learnq = _learnq || [];
document.querySelector(".INSERT_CLASS_HERE").addEventListener('click',function (){
_learnq.push(['track', 'Added to Cart', item]);
});
</script>

Let’s say this is your set-up: 

<div class="parent-div">
<button class="btn--add-to-cart">Add To Cart</button>
</div>

 You could adapt the querySelector portion to something like:

document.querySelector('div.parent-div > button')

I hope that’s helpful.

Reply