BILAL SURAWALA

BILAL SURAWALA

  • NA
  • 4
  • 484

i want to append button on dynamically generated classes

Apr 4 2018 2:51 AM
I am adding button into div by jQuery Selector,and open dialog on button click.
  1. $(".item-box .product-item .picture").each(function ()  
  2. {  
  3. var productId = $(this).closest(".product-item").data("productid")  
  4. $(this).append(" + productId + "' title='QuickView' class='button-2 quickView' onclick='javascript:void(0);return false;'>quickview");  
  5. });  
but this is not work in infinity scrolling, if new class added dynamically on scrolling then button not append on new added classes.
 
Then i am using jquery scroll event listener to append button on new added class on scroll.
  1. document.addEventListener('scroll'function (event)  
  2. {  
  3. $(".item-box .product-item .picture").each(function ()  
  4. {  
  5. if ($(this).children().hasClass("quickView") == false)  
  6. {  
  7. var productId = $(this).closest(".product-item").data("productid")  
  8. $(this).append(" + productId + "' title='QuickView' class='button-2 quickView' onclick='javascript:void(0);return false;'>quickview");  
  9. }  
  10. });  
  11. });  
it is work fine but this affect on performance due to many time call on every scroll event it decrease the speed, and dialog box is open very slowly.
 
So is there any other way to implement this feature.