Call JS function on each recommendation item
How do I call a JS function for each recommendation item with parameters inside the Dynamic Yield Editor?
Info - I have a recommendation slider which shows a set of products. I need to calculate the discount percentage for each item using the “original price” and “current price” What is the best way to do this?
-
Hi Dennis,
I usually do something similar to this logic:<div class="dy_widget"> ${#Recommendation} <div class="dy-item"> <!--some html here'--> <div class="price" data-price="${price}" data-sale-price="${sale price}"> </div> </div> ${/Recommendation} </div> var itemPrices = document.querySelectorAll('.dy_widget .price'); for(var i=0; i<itemPrices.length; i++){ var price = itemPrices[i].getAttribute('data-price'); var salePrice = itemPrices[i].getAttribute('data-sale-price'); //price calculation and html change code here }
Please sign in to leave a comment.
Comments
1 comment