I am attempting to load images using javascript. First, I retrieve the URL of wide size images and then when the user opens the modal, I intend to load the wide size images.
Here is my approach:
try {
images
}
catch(err) {
if (err.name == "ReferenceError"){
let images = [];
let nodes = tab.childNodes[1].children;
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].firstElementChild.className === "slider") {
images.push(nodes[i].firstElementChild.src)
}
}
Images:load(images)
}
}
However, it seems like this method is not working as it loads images every time.
I have also tried placing these codes inside the if statement, but unfortunately none of them worked either. They resulted in an error message
Uncaught ReferenceError: images is not defined at HTMLElement.<anonymous>
if (typeof images == 'undefined')
if (typeof images === undefined)
if (typeof images == 'undefined' || images.lenth === 0 )
Is there a way to check if the images variable has been declared before?