Ok i have this code where i set $tooltip for 3 different items, wich just $tooltip is refreshed using ajax.. Works great, but after refresh in ajax i have to run
$('.tooltip').remove();
This is a problem cause after this ajax call, the $tooltip2 and $tooltip3 are lost, =(. Ive also tried this:
$tooltip = $('.tooltip').remove();
But im wrong obviously.
Here is the code where i set $tooltip
var $tooltip = null;
var $tooltip2 = null;
var $tooltip3 = null;
function ttp() {
$tooltip = $('.marcleidnot[title]').tooltip({
delay:100,
slideInSpeed: 300,
slideOutSpeed: 300,
bounce: false,
/*bounce: false*/
relative: false, // <-- Adding this should sort you out
effect: 'slide',
direction: 'down',
/*slideInSpeed: 300,
slideOutSpeed: 200,*/
position: 'top center',
offset: [-15, 0]
});
}
$( document ).ready(function() {
$tooltip2 = $('.fav[title]').tooltip({
delay:50,
slideInSpeed: 200,
slideOutSpeed: 200,
/*bounce: false,*/
relative: false, // <-- Adding this should sort you out
effect: 'slide',
direction: 'down',
/*slideInSpeed: 300,
slideOutSpeed: 200,*/
position: 'top center',
offset: [10, -2]
});
$tooltip3 = $('.nofav[title]').tooltip({
delay:50,
slideInSpeed: 200,
slideOutSpeed: 200,
/*bounce: true,*/
relative: false, // <-- Adding this should sort you out
effect: 'slide',
direction: 'down',
/*slideInSpeed: 300,
slideOutSpeed: 200,*/
position: 'top center',
offset: [10, -2]
});
});
And the Ajax call
function notifications() {
$.ajax(
{
type: "POST",
//data: dataparam,
url: "<?php echo $notifurl;?>",
success: function(msg)
{
if(msg !="")
{
$("#ajaxnotif").empty().html(msg);
//$('.tooltip').remove();
$tooltip = $('.tooltip').remove();
ttp();
//$("#suggestDiv").show();
}
else
{
$("#ajaxnotif").empty().html(msg);
$tooltip = $('.tooltip').remove();
ttp();
//$("#suggestDiv").hide();
}
}
});
}
UPDATE
After the answer i edit and do
function destroyTooltips($targets) {
$targets.removeData('tooltip').unbind().next('div.tooltip').remove();
}
var $destroyThis = $('.marcleidnot[title]');
function notifications() {
$.ajax(
{
type: "POST",
//data: dataparam,
url: "<?php echo $notifurl;?>",
success: function(msg)
{
if(msg !="")
{
$("#ajaxnotif").empty().html(msg);
//$('.tooltip').remove();
destroyTooltips($destroyThis);
ttp();
//$("#suggestDiv").show();
}
else
{
$("#ajaxnotif").empty().html(msg);
destroyTooltips($destroyThis);
ttp();
//$("#suggestDiv").hide();
}
}
});
}
The problem is now that the tooltip remain open forever, when the ajax call is made..
but now i am not losing $tooltip2, and $tooltip3
what am i doing wrong.
UPDATE2
After the 2nd Great Answer full of details, is not recreating the tooltip why?
function notifications() {
$.ajax(
{
type: "POST",
//data: dataparam,
url: "<?php echo $notifurl;?>",
success: function(msg)
{
if(msg !="")
{
$("#ajaxnotif").empty().html(msg);
//$('.tooltip').remove();
destroyTooltip($tooltip);
// If you update the title of the tooltip, it will be init correctly.
$tooltip.attr('title', msg);
initTooltip($tooltip, {
delay : 100,
slideInSpeed : 300,
slideOutSpeed: 300,
bounce : false,
offset : [-15, 0]
});
//$("#suggestDiv").show();
}
else
{
$("#ajaxnotif").empty().html(msg);
destroyTooltip($tooltip);
// If you update the title of the tooltip, it will be init correctly.
$tooltip.attr('title', msg);
initTooltip($tooltip, {
delay : 100,
slideInSpeed : 300,
slideOutSpeed: 300,
bounce : false,
offset : [-15, 0]
});
//$("#suggestDiv").hide();
}
}
});
}
First prepare the variables for each tooltip.
Create a function to initialize a tooltip.
In the document ready event, first look up the tooltips in the DOM and then initialize each one separately.
When the AJAX call finishes, just destroy the specific tooltip and then recreate it.