I have a file named index.php, which in I include another file named file1.php (in index.php I include all necessary files for jQuery, js etc.).
In file1.php I have a table with buttons which each opens a modal. the information in the modal is from an ajax call for file2.php. in file2.php I create a table. In the table I have the cell :
<button class='btn btn-default tooltip-default' data-toggle='tooltip' data-trigger='hover' data-placement='top' data-content='content' data-original-title='Twitter Bootstrap Popover'>AAA</button>
and, well, the tooltip doesn’t work.
but, when I copy this and get it to file1.php, bellow the table, the tooltip does work.
Can anyone help me fix the tooltip ?
Thx.
7
Answers
I think you need to initialize the tooltip on the newly arrived data, e.g.
Place this code to your AJAX success handler, after the DOM manipulation.
I set up my tool tip by placement like so:
initialize this with a document ready call:
This way I can determine the placement of the tool tip, and I only have to assign the tip with using a class and title:
Then I call, “setUpToolTipHelpers()” inside my success ajax function. Or you can call it on the complete function as well. This seems to work well for me.
You will have to put the tooltip initialization in Ajax callback function:
-OR-
instead of putting the initialization code in every Ajax callback function
you can implement it globally using the ajaxComplete event:
This code will initialize the tooltip for every node which has the data-toggle=”tooltip” attribute defined but do not have the attribute “data-original-title” (i.e tooltip not initialized).
You can do this in one of these two ways:
ajaxComplete
function so that every time after an ajax call completed it reinitialize the tooltip over and over again. This is useful when in most of your pages you have datatables and want to initialize the tooltip after every ajax datatable call:I’ve tried everything and nothing worked for me.
So I took a closer look at tooltip when click* and found out that each time the shown.bs.tooltip is fired a aria-describedby property appears and its value changes every time.
So, my approach (and it works) is to change the content of this dynamic element.
I got this code:
In my case my tooltip has a data-url attribute to take the data for the title.
The original title is ‘-‘, and I don’t want an ajax call every time I click* the element, just the first time.
To me it’s not useful to make an ajax every time because I don’t expect the data to change that fast.
The dynamic created element has an element with the class .tooltip-inner, so we just need to replace its content.
Hope this might help.
*click: I chose the click event because the default hover sometimes make the system turn crazy and the show.bs.tooltip was fired forever, switching its between the default and new value.
Use selector on exist element like body
run
after the ajax where
#ding_me_tooltip
is your selector