I'm currently working on a chrome extension that let the user click on a node to get its content. Getting the inner text is simple when using textContent, but getting the url of a picture in a clicked div...
I tried using this function to get the img node and thus being able to read its href/src:
function getimgtag(elem) //elem is the clicked div
{
for(i=0;elem.getElementsByTagName('div')[i];i++)
{
getimgtag(elem.getElementsByTagName('div')[i]);
}
if(elem.getElementsByTagName('img')[0])
{
localStorage['fus_imgtag']=elem.getElementsByTagName('img')[0];
}
}
But it doesn't seems to have an end and I really don't understand why. Shouldn't it check all the div elements and place the last img found in localStorage['fus_imgtag']?
ias invar i.elem.getElementsByTagName('div')andelem.getElementsByTagName('img'). Calling it over and over again is a waste of resources.