javascript - The onclick remove affecting other button -


i have function delete button (to delete based on click) , working, when clicked on other button delete function not supposed do. how can prevent affecting other button?

function mydelete() {     $(document).on('click', '.item', function(){         $(this).remove();         var sum = 0;     }); } 

you better bind 'click' event particular dom object, rather document object.

please try code :

function mydelete() {     $('.item').on('click', function(){         $(this).remove();         var sum = 0;     }); } 

also, looks weird me have wrap in function. simple wrapper (equivalent of "on dom load") should enough in cases :

$(function(){   // code here such :   $('.item').on('click', function(){       $(this).remove();       var sum = 0;   }); }); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -