3

i'm trying to load (via Ajax Call) a tooltip whose title is in HTML tags. In the first page load when it is loaded by the include_once function, the tooltip works fine, but not when i trigger the page load with Ajax Call. Here are my files :

loadTable.php

    <?php
        $content = "<a data-toggle='tooltip' data-html='true' title='<strong>ok</strong>'
<span class='glyphicon glyphicon-align-left'></span></a>";

        echo $content;
    ?>

mypage.php

<button type="button" class="btn btn-primary" onclick="loadPage()">Load</button>
<div id="tableData">
    <?php include_once('loadTable.php');?>
</div>

myjavascriptfile.js

function loadPage(){
    $.ajax({
        type: "POST",
        url: "loadTable.php",
        data:{
            cache: false,
            success: function(result){
                $("#tableData").html(result);
            }
        });
    }
}

NB: of course i have simplified the example at the extreme, just for understanding and simplicity purposes.

codeless
  • 145
  • 5
  • 14

1 Answers1

7

Thanks to DelightedD0D, the solution is to re-initialize the tooltips after Ajax Call.

In my case, i added this line : $('[data-toggle="tooltip"]').tooltip();

function loadPage(){
    $.ajax({
        type: "POST",
        url: "loadTable.php",
        data:{
            cache: false,
            success: function(result){
                $("#tableData").html(result);
                $('[data-toggle="tooltip"]').tooltip();
            }
        });
    }
}

I hope it helps others who have the same problem.

codeless
  • 145
  • 5
  • 14