Add tooltip to button that came straight from Php via Ajax

0

In my PHP server I return some data between them a button

$HTML = " <button id=\"btnExcluir\"  style=\" width: 55px !important;\" onclick=\"Excluir();\" type=\"button \"  data-toggle=\"tooltip\" data-placement=\"top\" title=\"     Excluir itens selecionados\" class=\"btn   btn-danger botaoExcluir\"> " ;

echo $HTML;

In my HTML / JS file I have my Ajax request that fetches this data from the Php server, and includes them in a div with the Data Id ... Until then it appears normally and in my Jquery file I have the following function

$(function () {
       $('[data-toggle="tooltip"]').tooltip()
    })

In order to stylize the tooltip of my buttom, it does not change the type. How can I add this style to the button?

    
asked by anonymous 30.07.2017 / 16:35

1 answer

1

This happens because every html element that enters dynamically is not part of the DOM has been loaded in the current document. In order to be able to select these elements you should use some jquery methods specific to this.

You can search a little more about these methods in the jquery documentation:

Delegate and on , good studies! ;)

Ex with 'on'.

$(document).on('change', '[data-toggle="tooltip"]', function() {
    $(this).tooltip();
});

Ex with delegate with click event:

$(".divpai").delegate( "elementofilho", "click", function() {
    $(this).css({display:"none"});
});
    
23.08.2017 / 18:03