Below is the potential code. "Potential" – because I am able to display floating add to cart button when mouse hovers over a product. Issue is when I try to click that floating add to cart button, it is not receiving click event even if i have captured its click event via some other javascript.If someone can suggest some improvement to this, we would have working , floating add to cart button. Thanks
const productCardWrappers = document.querySelectorAll('.product-card-wrapper');
// Loop through each instance and add event listeners
productCardWrappers.forEach((productCardWrapper) => {
// Get the Add to Cart button element within the current instance
const addToCartButton = productCardWrapper.querySelector('.variant-button');
// Add a mouseover event listener to the current instance
productCardWrapper.addEventListener('mouseover', () => {
// Show the Add to Cart button when the mouse is over the current product card
addToCartButton.style.display = 'block';
});
// Add a mouseout event listener to the current instance to hide the button
productCardWrapper.addEventListener('mouseout', () => {
// Hide the Add to Cart button when the mouse leaves the current product card
addToCartButton.style.display = 'none';
});
});'''
2
Answers
Below is the potential code. "Potential" – because I am able to display floating
add to cart
button when mouse hovers over a product. Issue is when I try to click that floatingadd to cart
button, it is not receiving click event even if i have captured its click event via some other javascript.If someone can suggest some improvement to this, we would have working , floating add to cart button. Thanks