As for the first img element on the page, set the title and alt

    1 answer 1

    Perhaps this option will suit you:

    var firstImage = document.getElementsByTagName("img")[0]; firstImage.setAttribute("title", "first"); firstImage.setAttribute("alt", "img"); console.log("id: " + firstImage.id + " title: " + firstImage.title + " alt: " + firstImage.alt) 
     <div> <img id="secongImg"> <img id="firstImg"> <img id="thirdImg"> </div>