Created
March 26, 2012 17:47
-
-
Save mreidsma/2207510 to your computer and use it in GitHub Desktop.
A simple jQuery tooltip function that creates tooltips based on title attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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