Skip to content

Instantly share code, notes, and snippets.

@mreidsma
Created March 26, 2012 17:47
Show Gist options
  • Save mreidsma/2207510 to your computer and use it in GitHub Desktop.
Save mreidsma/2207510 to your computer and use it in GitHub Desktop.
A simple jQuery tooltip function that creates tooltips based on title attributes
// Tooltip
function tooltip(obj) {
// Check if tooltip is open already
var tipText = $(obj).attr("title");
if(tipText==undefined) { // No title
// Tooltip is open
// Remove span and add text as title to span again
tipText = $(obj).next("span.tooltip").text();
$(obj).attr("title", tipText);
$(obj).next('span.tooltip').remove();
} else {
// Append tooltip as new span after clicked item, then remove the title to avoid duplicate tooltips
$(obj).parent("li").append('<span class="tooltip">' + tipText + '</span>');
$(obj).removeAttr("title");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment