1

I am implementing comments section using ajax. Comments have options reply and delete. When they are clicked, reply form or delete confirm options are shown.

enter image description here

After clicking delete, it expands :

enter image description here

The problem is that after a new comment is posted through ajax, jquery for the new comments aren't loaded and so these buttons don't work.

How do I reload the jquery of the page without page refresh and get these new comments to work? Any solution? Thanks !

sagar_jeevan
  • 761
  • 5
  • 16
  • 34
  • 1
    Two words: event delegation. – Dave Newton May 19 '17 at 17:56
  • 2
    Without seeing any actual logic, the only thing i can think of is you are directly binding on the buttons on page load, so the new elements will not be bound to. If this is true, instead of doing direct bindings use delegate bindings which will work with all future child elements as well. `$(parentSelector).on(event, childSelector, eventHandler)` The parentSelector should find a parent object that exists on page load that will always exist and is a parent of all the elements in quesiton. – Taplar May 19 '17 at 17:56
  • 1
    http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – Alexander Staroselsky May 19 '17 at 17:59
  • Yup.. I was doing direct bindings. I was unaware of the concepts. Learned a lot. The link helped. It works. Thanks ! – sagar_jeevan May 19 '17 at 18:31

0 Answers0