Is it possible to get a title from an image using "GetElementsByTagName"?

1

If yes, how? If not, is there any way I can get the title value, then print? For now it's like this (Inside a function. In the image it has an onClick calling it).

var imagens = document.getElementsByTagName('img');
        document.getElementById('legenda').innerHTML = imagens;

I have already tried for a getAttribute too and nothing

    
asked by anonymous 26.05.2015 / 03:38

1 answer

2

This here shows the title of all images on the page:

var imagens = document.getElementsByTagName('img');
for(var i=0; i<imagens.length; i++) {
    alert(imagens[i].title)
}

Considering the code that you included in the question, maybe this is what you want:

var imagens = document.getElementsByTagName('img');
// Joga A PRIMEIRA imagem encontrada na página para dentro da legenda
document.getElementById('legenda').appendChild(imagens[0]);
    
26.05.2015 / 03:45