Skip to content

Instantly share code, notes, and snippets.

@bl4de
Created May 27, 2013 21:00
Show Gist options
  • Save bl4de/5659066 to your computer and use it in GitHub Desktop.
Save bl4de/5659066 to your computer and use it in GitHub Desktop.
While I work on my new project, VirtualAssistant, I created simple code, which allows to add tooltip to any DOM element on page. Of course, I should pass as second argument some kind of callback, which draws tooltip baloon with text, because for now, it's simple 'title' HTML attribute added 'on the fly' :)
var VAEngine = VAEngine || ( function() {
function addTooltip(_element, _tooltipText) {
var _elem = document.querySelector(_element);
console.log("_elem: ", _elem);
_elem.addEventListener('mouseover', function() {
_elem.title = _tooltipText;
});
}
return {
addTooltip: addTooltip
};
})();
// usage:
// VAEngine.addTooltip("#sample1", "This is sample tooltip number one");
// where:
// #sample1 - ID of DOM element
// secon argument - content of tooltip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment