I am trying to pull the first image I can get from a URL and display it in a div.
I can successfully pull things such as title and headers from the URL but images will not work.
var html = httpRequest.responseText; var DOMparser = new DOMParser(); var xmlDocument = parser.parseFromString (html, "text/xml"); title = xmlDocument.getElementsByTagName('title'); image = xmlDocument.getElementsByTagName('img');
When I view
title.innerHTML I can get the title. However, doing the same for image, it always comes up as undefined. Even when i do image.src
How can I do this?
<img /> does not have inner HTML, you have to access its attributes.