search

Home  >  Q&A  >  body text

javascript - jquery selects one of the buttons of the same class to perform an operation.

                         $(".parButton").each(function() {  
                             
                             $(this).bind("click",function(){
                                 
                                alert(1111);

                            
                             })
                        });
                        

".parButton"There are multiple Buttons. This will determine whether the currently clicked one can be selected. Why when I execute this line of code, the first ".parButton" Button is always executed multiple times.

漂亮男人漂亮男人2776 days ago946

reply all(1)I'll reply

  • 三叔

    三叔2017-06-30 09:59:35

    I have no problem running your code,

    $(".parButton").each(function(index,item) {
        console.log(index);
        $(this).bind("click",function(){
            console.log(this);
             $(this).hide();
         })
    });

    I executed it like this, and one click disappears. Or is it a problem with the button? Can I try changing the button to p? Or you can print out the element you get every time you click to see if it is the element you clicked.

    reply
    0
  • Cancelreply