Difference between .on('click') vs .click()

后端 未结 12 2502
礼貌的吻别
礼貌的吻别 2020-11-21 05:22

Is there any difference between the following code?

$(\'#whatever\').on(\'click\', function() {
     /* your code here */
});

and

12条回答
  •  粉色の甜心
    2020-11-21 05:33

    $('.UPDATE').click(function(){ }); **V/S**    
    $(document).on('click','.UPDATE',function(){ });
    
    $(document).on('click','.UPDATE',function(){ });
    
    1. it is more effective then $('.UPDATE').click(function(){ });
    2. it can use less memory and work for dynamically added elements.
    3. some time dynamic fetched data with edit and delete button not generate JQuery event at time of EDIT OR DELETE DATA of row data in form, that time $(document).on('click','.UPDATE',function(){ }); is effectively work like same fetched data by using jquery. button not working at time of update or delete:

提交回复
热议问题