Skip to content

Instantly share code, notes, and snippets.

@gsdevme
Created December 4, 2011 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsdevme/1428643 to your computer and use it in GitHub Desktop.
Save gsdevme/1428643 to your computer and use it in GitHub Desktop.
Tooltips from title="" attributes
(function(doc, undefined){
var e = doc.querySelectorAll('a.tooltip'), s;
if(e !== undefined){
for(i=0;i<e.length;++i){
s = document.createElement('span'),
s.className='tooltip',
s.innerHTML = e[i].getAttribute('title'),
s.style.padding = '0 15px';
e[i].appendChild(s);
s.style.margin = (((parseInt(s.offsetHeight) / 2) + (parseInt(e[i].offsetHeight) / 2))) +'px 0 0 -' + ((parseInt(s.offsetWidth) / 2) + (parseInt(e[i].offsetWidth) / 2)) +'px';
e[i].removeAttribute('title');
}
}
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment