Bootstrap Popover and Tooltip not working with AJAX content

Popover and Tooltip in Twitter Bootstrap are used to display small overlay of content on hover, focus or click events. For performance reasons, the Tooltip and Popover data-apis are opt-in, meaning we must initialize them ourselves manually. With already present elements in HTML these Bootstrap JavaScript Plugins work fine but not with dynamically loading AJAX content. This article here explains the reason behind Bootstrap Popover and Tooltip not working with AJAX content and the way to let them work.

Bootstrap Popover and Tooltip with AJAX content

If we initialize either of them as per described in Bootstrap documentation:

Any function inside of $() is run when the document is first finished loading and when the “document ready” event is fired. When the code is pasted inside of the original HTML, Bootstrap Popver and Tooltip work because HTML code is present when the document finishes loading.

When it’s the response from an AJAX call, it won’t run inside of $(), because the “document ready” event already fired some time ago. So the correct way to call Popover or Tooltip when content are loaded dynamically with AJAX is:

Or

A Note:

Some older versions of Bootstrap had issue while displaying Popover/Tooltip in modal because the modal had greater z-index than that of the Popover or Tooltip. To deal with this issue you can assign higher z-index to these components using custom CSS rule as below:

But the current version of Bootstrap (v3.3.4) has already overcome this issue so Bootstrap Popover and Tooltip not working with AJAX content might be due to issue already explained earlier.

Like this Post? Share
  • Steve patel

    Good post .
    We are magento profesional
    Please hire us http://www.wireinfotech.com

  • Thanks for this post — saved me some time trying to figure out why tooltips weren’t loading on ajax content