jquery - function off () cancel click for all elements -


i have piece of code:

jquery(function($){     $(document).on("click", ".product-image-mobile .product-image", function (e) {         $(this).attr('data-num', 1);         e.preventdefault();         if ($(this).attr("data-num") == 1){              $(document).off("click", ".product-image-mobile .product-image");         }     }); }); 

first click on product image display image, click go product page. products loading via ajax. first product image code working, others not. think concerned $(document).off, cancel click "prevent" other elements.

please advice how can done. thanks.

you can use combination of :not() , attribute value selector bind event.

$(document).on("click", ".product-image-mobile .product-image:not([data-num='1'])", function (e) {     $(this).attr('data-num', 1);     e.preventdefault();         }); 

i not sure, think can using

    if ($(this).attr("data-num") == 1){          $(event.target).off("click");     } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -