Trying to remove pesky alt text from lightbox gallery

半世苍凉 提交于 2019-12-11 10:08:33

问题


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>

回答1:


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);
 }
};



回答2:


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.



来源:https://stackoverflow.com/questions/13794891/trying-to-remove-pesky-alt-text-from-lightbox-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!