ylinks = '' links = document.querySelectorAll('#results > div > a > div > img') for (x=0; x<links.length;x++){ ylinks+=(x+1+") https://www.youtube.com/watch?v="+links[x].getAttribute('src').split('/')[4]+" ") } console.log(ylinks)