When using bootstrap popovers you have to initialize them in your javascript code like this $('#element').popover();
. Usually you would use a $(document).ready();
function for that. But what if the element the popover gets bound to is loaded by ajax itself?
Being not fully confident with javascript, the current issue I'm facing is with having a page that's loading a huge part of its content via multiple ajax calls. One of these elements are:
<span class="infolink" style="vertical-align:bottom;" data-title="some title" data-placement="bottom" data-delay="500" data-content="some content">
Trigger Popover
</span>
One solution that came to my mind, after each ajax call cycle through all elements and initialize the popover (e.g.: $('.infolink').each(function(i,e){e.popover();});
). I don't want to this, since this would hurt performance, given the number of ajax calls and the size of the page. Is there any other way?
Another idea was having a function (e.g. function initializePopover(element){...}
) and calling it after the element has been loaded <span class="infolink" [...] onload="initializePopover(this)"></span>
. But this did not work either.
Is there a best-practice to how to initialize popovers where the trigger-element itself is to be loaded by ajax?