A script is supposed to read an image URL from a div data-src attribute:
(function() {
var jalObj = document.querySelector('.c-jalousie');
var imgSrc = jalObj.getAttribute('data-img-src');
console.log("imgSrc =", imgSrc);
})();
So far, that works. But as soon as I try to get into the native Image() API with img.onload, that part seems to never reached nor executed:
// Load the image
var loadImg = new Image();
loadImg.onload = function() {
// this part is never executed. Why?
console.log('checking onload status');
}
loadImg.src = imgSrc;
Can’t find out why that doesn’t work. Does anyone else here have a hint for me?
I also made a Pen: http://codepen.io/rowild/pen/vyVmYN?editors=1111
Thanks!!