I want to use the Javascript below capturing the alt attribute of an image when user click on it, but the result I can get is always null. I want to extract the "Youtube" alt attribute.
<a href="http://www.youtube.com/" title="Youtube" target="_blank">
<img src="/example" class="example" alt="Youtube">
</a>
function() {
var elem = {{element}},
attr = "alt", // change to corresponding attributes
result = (elem.getAttribute && elem.getAttribute(attr)) || null;
if( !result ) {
var attrs = elem.attributes,
l = attrs.length;
for(var i = 0; i < l; i++) {
if(attrs[i].nodeName === attr)
result = attrs[i].nodeValue;
}
}
return result;
}