Check if elem is not null
xx4159 opened this issue · comments
https://github.com/desandro/imagesloaded/blob/master/imagesloaded.js#L136
Check if elem is not null
if ( elem && elem.nodeName == 'IMG' ) {
Thanks for this contribution. Could you provide the use case where this error occurs? Tracing back the code. addElementImages
is applied to this.elements
. this.elements
is set to an array of queryElem
. If queryElem
is falsey, imagesloaded should return in its constructor. So there's an edge case I'm not accounting for.
@desandro queryElem
can any array. in my case, I guess... it was imagesLoaded([undefined])
.
more details,
html
<div class="feed"></div>
javascript
// ...
const images = Array.prototype.slice.call(document.querySelectorAll('.feed')).map((feed) => feed.getElementsByTagName('img')[0]);
const loaded = imagesLoaded(images);
// ...
and I think I have to fix my code filtering empty feed... 😅
You could just do imagesLoaded('.feed')
rather than querying, slicing and mapping individual images.