Skip to content

Instantly share code, notes, and snippets.

@ajbogh
Created December 9, 2011 17:20
Show Gist options
  • Save ajbogh/1452455 to your computer and use it in GitHub Desktop.
Save ajbogh/1452455 to your computer and use it in GitHub Desktop.
Show All Alt Tags
/* Shows all image alt text or title tags for a specified time.
* Title is the preferred image attribute in this script, falls back to alt.
*
* USAGE:
* Create a bookmark in your browser.
* Add the url (note, type out 'javascript:' before pasting code.):
* javascript:[paste code below]
* Add the bookmark to your bookmark bar, if not done already.
* You can also paste the code in your address bar like so:
* javascript:[paste code below]
*/
var time=10000;
var bgColor='#ADD8E6';
var border='1px solid blue';
var maxWidth='300px';
var images=document.getElementsByTagName('img');
for(var i=0;i<images.length;i++){
div=document.createElement('div');
div.id='tagimg_'+i;
div.style.backgroundColor=bgColor;
div.style.border=border;
div.style.maxWidth=maxWidth;
div.style.position='absolute';
y = images.item(i).offsetTop;
x = images.item(i).offsetLeft;
offsetParent = images.item(i).offsetParent;
while(offsetParent != null){
y += offsetParent.offsetTop;
x += offsetParent.offsetLeft;
offsetParent = offsetParent.offsetParent;
}
div.style.top=y+10+'px';
div.style.left=x+10+'px';
if(images.item(i).title!=''){
div.innerHTML=images.item(i).title;
}else if(images.item(i).alt!=''){
div.innerHTML=images.item(i).alt;
}
document.body.appendChild(div);
setTimeout('removeTagImg('+i+');',time);
}
function removeTagImg(i){
el=document.getElementById('tagimg_'+i);
document.body.removeChild(el);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment