Add tooltip to button that came straight from Php via Ajax

Asked

Viewed 163 times

0

On 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 searches 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()
    })

To be able to style my buttom tooltip, but it does not change the type. How is it possible to add this style to the button?

1 answer

1


This is because every html element that enters dynamically is not part of GIFT which was loaded into the current document. In order to be able to select these elements you must 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 com delegate com evento click:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.