Search code examples
jqueryappendgetvalue

Delete button in append element is not working


My DELETE button doesn't work

Here is the code :

    $('.postGlobalWrap').on('click', '.delete', function(){
          removeNote();
    });

FULL PEN : https://codepen.io/Podgro/pen/xxxxPNR

I need your help guys 🤞


Solution

  • why don't you try using

    var parent = $(this).parent();
    

    instead of

    var parent = $(this).closest('li');
    

    and

    $('.postGlobalWrap').on('click', '.delete', function(){
         removeNote($(this));
     });
    
    function removeNote(del_btn) {
      console.log('test');
      var parent = del_btn.parent();
      console.log(parent);
      parent.fadeOut();
      parent.remove();
    }