At the moment, I am developing a Chrome extension that allows users to click on a node in order to access its content. While acquiring inner text using textContent
is straightforward, extracting the URL of an image within a clicked div
presents some challenges...
I attempted to employ this function to locate the img
node and retrieve its href
/src
:
function getimgtag(elem) //elem represents 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];
}
}
However, it appears to run indefinitely without completion and the reason behind this behavior eludes me. Shouldn't it iterate through all the div
elements and store the last found img
in localStorage['fus_imgtag']
?