A common example: Bootstrap Tooltips
Imagine a list with a tooltip. As soon as we loaded the page, all the tooltips in this list are working. Oh yeah, we also have a file with this code in the <head> page:
$(function () { $('[data-toggle="tooltip"]').tooltip(); }) Now add a duplicate element to this list using Ajax. No matter how exactly the Ajax request is implemented - the total is one.
The new item will not work tooltip. I correct the situation as follows: along with the html code (in this example, the html code of the list item), I also send this:
<script>$('[data-toggle="tooltip"]').tooltip();</script> Added 10 items to the list, gathered 10 identical script lines under it. But everything works.
But there was a need to implement the functionality is not just a list. Now I have a lot of components on the page, each of which works on Ajax - pagination, the same list with elements, in which there is something else with Ajax. All that stuff.
And “curing” it the way I described it above is impossible.
Is there really no normal way for the "new elements from ajax" to interact with the JS environment of the page?
<script>$('[data-toggle="tooltip"]').tooltip();</script>markup if you can call this function yourself immediately after receiving it directly? - Grundy