Is there a script that can stop displaying alt = "text" as a hint in IE 6 and 7?

is there a script that can stop displaying alt = "text" as a hint in IE 6 and 7?

+4
source share
8 answers
<!--[if IE]><script>for(i =0;i<document.images.length;i++){document.images[i].alt='';}</script><![endif]--> 

at the end of the page should do it.

+2
source

I would not worry too much about it. This is a known bug, and it is fixed in IE8.

+3
source
 $('img').each(function (i, el) { if (!el.hasAttribute('title')) { el.setAttribute('title', ''); } }); 

This should give all images without the title attribute blank. I am not sure if this will fix the problem for IE6 and IE7, but I think they support title , and that can undo it.

+3
source

In IE prior to IE8, the only way to prevent the browser from viewing the alt text image as a hint:

  • do not use the alt attribute (which is not very good because it is invalid HTML, and it is not very good even for Google SEO and text readers who cannot see your images).

  • put an empty attribute in each image a title="" .

To execute point (2) using simple Javascript without jQuery, you must put this small piece of code before the BODY tag ends, for example:

  <!--[if lt IE 8]> <script> for(var i = 0, imgs = document.images, len = imgs.length; i < len; ++i) if(!imgs[i].title) imgs[i].title = ""; </script> <![endif]--> </body> 

You can write it on one line if you want.

The advantage of this code is that it does not spoil the alt tag attributes of your images, it simply sets the title attribute to an empty string if the title attribute is not already defined in this latter case. I suppose the title attribute was because you want to show everything that you wrote in the title attribute as a tooltip (which is cross-browser behavior).

+2
source
 $$('img').set('alt', ''); 

There is no other way than setting the title attribute.

+1
source

You could do the following, but that would be very intrusive (and a bit slow):

 $('*').attr('alt', ''); 
0
source

Presumably for the alt attribute, you just mean image elements?

 $('img').removeAttr('alt'); 

You may also consider removing the title attribute from elements in the DOM

 $('*').removeAttr('title'); 
0
source

Screan reader run javascript? If not, why bother with this mod?

Setting alt to "hide alt" hint "in IE <8, which seems to be all you need. Plus it should be done anyway for the whole image, or screen readers have a habit of rendering default placeholder speech" If you set it to blank, it will not bother and skip it, ideal for images that are just used for design and not for content.

Unfortunately, there is no special flag or switch that you can scroll through JS or any other method to say that IE behaves differently in this regard, which I believe you are asking.

An alternative is to switch any alt that you find in the images to be headers, but this does not eliminate the tooltips, you just make them appear in all browsers, not just IE.

So, the last fix is ​​to just clear all the alt attributes in the images (and there are scripts in the other answers that do just that). You asked a question, but I think you should think about what exactly are you trying to achieve, and more importantly, why is this important?

0
source

All Articles