jQuery $(“.class”).click(); - multiple elements, click event once

前端 未结 18 1660
借酒劲吻你
借酒劲吻你 2020-11-29 00:01

I have multiple classes on a page of the same name. I then have a .click() event in my JS. What I want to happen is the click event only happen once, regardless of multiple

18条回答
  •  孤城傲影
    2020-11-29 00:37

    Simply enter code hereIn JQuery, ones event is triggered you just check number of occurrences of classes in file and use for loop for next logic. for identify number of occurrences of any class, tag or any DOM element through JQuery : var len = $(".addproduct").length;

     $(".addproduct").click(function(){
           var len = $(".addproduct").length; 
           for(var i=0;i

提交回复
热议问题