There is a certain problem, very weighty for me. There is a table that is updated by a poll request every 5 seconds, and it works fine. But this table also has a button. If I write a separate script file, it stops responding after the first poll-update, but if you write <script> in the HTML itself, it works. How to understand this?

  • probably, you do not correctly attach the click handler to the dynamically generated content. You understand what I am talking about, they have already googled and tried to solve the problem on their own, right? - teran
  • To be honest, I didn’t know where to start, since I use Jsf framework (primefaces) - elik
  • one
    thanks teran found one solution with event on place onclick - elik
  • I will try with him) - elik
  • but even so, I 'll accept the answer - elik

2 answers 2

In simple terms, DOM updates occur. New data replaces old ones and, accordingly, the event also disappears. 3 solutions:

  1. on the hang up button onclick
  2. after updating the DOM re-hanging the event on the button
  3. The best:

If your table is not fully updated, i.e. only rows change, and the table remains untouched:

 $('.table').on('click','button',function(){ /* твой код */}); 

If the entire table is replaced, then the table is wrapped in a div.

 $('div').on('click','button',function(){ /* твой код */}); 
  • I did it yes yu - elik

If #content corrupted (new elements were added to it) then do it ... Checks on adding new elements

 $("body").on('DOMSubtreeModified', "#content", function() { //Сюда код после измения });