JS onclick or jQuery .click in general and for delete button in particullar?

  • $(selector).click() event only works when element gets rendered and attached to elements loaded(when the DOM is ready).
  • $(selector).on(“click”) events are dynamically attached to DOM elements, which is helpful when you want to attach an event to DOM elements that are rendered on ajax request or something else (after the DOM is ready).

It is important to note that $(selector).on(“click”) differs from $(selector).click() in that jQuery on(“click”) has the ability to create delegated event handlers by passing a selector parameter, whereas $(selector).click() does not. When on(“click”) is called without a selector parameter, it behaves exactly the same as $(selector).click(). If you want event delegation, it is better to use $(selector).on(“click”).