Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative text for images #5

Open
dominykas opened this issue Jun 1, 2014 · 6 comments
Open

Alternative text for images #5

dominykas opened this issue Jun 1, 2014 · 6 comments

Comments

@dominykas
Copy link
Member

From alg4net on April 12, 2011 19:32:26

The following snippet

<h1><img src=logo.png alt="My Website"></h1>

Results in a "No text content inside H1", but the alt attribute shouldn't be used in that case?

Great tool by the way, helps me a lot!

Original issue: http://code.google.com/p/h5o/issues/detail?id=5

@dominykas
Copy link
Member Author

From Paolo.Pr...@gmail.com on March 01, 2012 03:26:25

Definitely this should be fixed. gsnedders' tool gets it right, and so do screen readers and search engines I suppose.

@dominykas
Copy link
Member Author

From rumor...@gmail.com on March 19, 2012 08:38:55

Hi,

You can add this function to the script, and replace "a.textContent" with getText(a). This function extracts the text from the elements and alt attributes from img, area and input type image.

getText=function(element) {
    if (element.nodeType == 3) return element.nodeValue;
    if(element.tagName.toLowerCase() == 'img' || element.tagName.toLowerCase() == 'area' || (element.tagName.toLowerCase() == 'input' && element.getAttribute('type').toLowerCase() == 'image')) {
        var alternativas = '';
        if(element.getAttribute('alt')) alternativas += element.getAttribute('alt');
        return alternativas;
    }
    var texto = new Array();
    if(element.childNodes[0]){
        if(element.childNodes[0].nodeType != 8)
            texto[0] = getText(element.childNodes[0]);
    }
    var i = 1;
    if(element.childNodes[i]){
        while(element.childNodes[i]) {
            if(element.childNodes[i]){
                if(element.childNodes[i].nodeType != 8)
                    texto[texto.length] = getText(element.childNodes[i]);
                i++;
            }
        }
    }
    return texto.join('');
}

Regards,
Jorge Rumoroso

@dominykas
Copy link
Member Author

@King2500
Copy link

Will this ever get fixed?

@dominykas
Copy link
Member Author

PRs welcome.

@King2500
Copy link

There you go :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants