Below is a portion of code I'm using to get the href or src of an image of known class or id. The console.log() returns null, even though it is in an if statement checking that the attribute later used isn't null. Of course, trying to get href or src of null doesn't end well.
for(var i = 0 ; (i < sitelist[site].img_id.length) && (img === undefined) ; i++)
{
if(document.getElementById(sitelist[site].img_id[i]) !== undefined)
{
if(document.getElementById(sitelist[site].img_id[i]) !== null)
{
console.log(document.getElementById(sitelist[site].img_class[i]));
if(document.getElementById(sitelist[site].img_class[i]).href !== undefined)
{
img = document.getElementById(sitelist[site].img_class[i]).href;
}
if(document.getElementById(sitelist[site].img_class[i]).src !== undefined)
{
img = document.getElementById(sitelist[site].img_class[i]).src;
}
}
}
}
Is there a specific way of checking if something is null, or is the problem elsewhere?