Get first child node of specific type - JavaScript
Try this
var firstIMG = document.getElementById('mylink').getElementsByTagName('img')[0];
You can also use querySelector
:
var firstImg = document.querySelector("#mylink > img:first-of-type");
var anchor = document.getElementById('mylink');
var images = anchor.getElementsByTagName('img');
var image = images.length ? images[0] : null;