In JS, a handler is written for the button *удалить сообщение* (minimized). After updating messages (together with buttons) via ajax, the handler stops working.

How to solve a problem?

Closed due to the fact that off-topic participants Streletz , D-side , zRrr , ReinRaus , Nick Volynkin Jun 8 '16 at 0:52 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Streletz, zRrr, Nick Volynkin
If the question can be reformulated according to the rules set out in the certificate , edit it .

    3 answers 3

    Do delegated event handling:

     $(document).on('click', '.delete-msg-btn', function(e){ /* code*/ }) 

      I offer two options

      1. After AJAX hang handlers on new buttons.
      2. Hang one handler per parent element containing all messages with these buttons and check e.target. If the target is a button, then perform the desired function. Determining whether a button is or not is possible, for example, by the presence of a class (say, .button).

        onClick no longer quoted? We make the function and insert it into onClick and it will work under any conditions.