[Fixed]-AJAX jQuery on click dynamically created only works first time

1πŸ‘

βœ…

I really don’t know what do you mean with parent[0] in

removeNotification(parent[0], urlDelete);

I think you can simply try $(this)

removeNotification($(this), urlDelete);

but to be honest I find to put

$( document ).ready(function() {
   $( document ).on("click", "#notification" + i, function() {
      console.log("onclick " + slug);
      removeNotification(parent[0], urlDelete);
   });
});

inside a loop .. its bad thing try to put it outside a function and use it like

$( document ).ready(function() {
       setInterval(refreshNotifications, 1000);
       $( document ).on("click", "[id^='notification']", function() {
          console.log("onclick " + slug);
          removeNotification($(this), urlDelete);
       });
 });

and try to find a way to pass a urlDelete which I think it will be just one url

Leave a comment