Trying to remove pesky alt text from lightbox gall

2019-07-26 09:31发布

I have a gallery of my paintings at www.unlicensedeyesurgery.com which uses the famous Lightbox code. There is one problem with it: the Lightbox code uses the rel attribute of the anchor tag to display the description of the image in the pop-up "window." However, this somehow overrides the images' alt property and shows the ugly, HTML-code description in the mouse tooltip. Is there a way to disable to tooltip altogether—perhaps using JS?

Code Example:

<a href="#" rel="<em>lightbox html<span>styled</span> text in here<em>">
  <img src="photo.jpg" alt="this is overwritten" />
</a>

2条回答
时光不老,我们不散
2楼-- · 2019-07-26 10:06

Your title overrided by <a title="...."> as you have here image set it's title to alt content

you can do it with javascript:

window.onload=function() {
 var images=document.getElementsByTagName('img');
 for (var i in images) {
   images[i].title=images[i].alt ;delete(images[i].alt);
 }
};
查看更多
对你真心纯属浪费
3楼-- · 2019-07-26 10:11

The problem is the anchors rel is getting precedence over the images alt tag in the tooltip.

The solution is to add a title: title="photo title" to all your img tags and browsers will show that instead of the anchor's rel.

查看更多
登录 后发表回答