Programmatically show tooltip after an ajax call

Here is an example of how to show a 'tooltip' or a popup dialog after some event. No ajax here, but just using the click action of the link.

$(document).ready(function() {

    $("#vote").click(function(evt) {
        evt.preventDefault();

        // Do your ajax
        // Show the popup
        $("#tooltip").show();
    });

    $("#tooltip").click(function() {
        $(this).hide();
    });

});

http://jsfiddle.net/Tm8Lr/1/

Hope this helps you get started.

Bob


Does it not work to simply trigger the mouseover event after binding the tooltip?

$('#myElement').tooltip().mouseover();

Have a look at the tooltip documentation (especially the scripting API) and the how their API works.

So it should work with:

if (response.result == "success") {
    $('#myElement').data('tooltip').show();
} 
else {
    // don't know which other tooltip you want to show here
}

You can also specify at which events the tooltip should be shown (so you probably can exclude mouseover or change it to something that you know is never triggered on that element (like change)).

Tags:

Jquery