finestra,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<a href="test.gif"></a>
<img src="next.gif" alt="">
<script>
var elems = document.querySelectorAll("[src$='.gif'], [href$='.gif']");
Array.prototype.forEach.call(elems, function( val ){
alert(val.getAttribute(val.tagName === 'A' ? 'href': 'src'));
});
</script>
</body>
</html>