So I am trying to set attributes (width and height) of my all images on page. So i do something like that:
const images = document.querySelectorAll('img');
const setImagesAttributes = () => {
images.forEach(img => {
img.setAttribute('width', img.clientWidth);
img.setAttribute('height', img.clientHeight);
})
}
window.onload = () => {
setImagesAttributes();
window.addEventListener('resize', debounce(setImagesAttributes));
}
And now something weird happen. So I think 90% of images work correct, the behave in same way like before adding script. But some images have very low height, idk what happend. Why one image behave normally, others not.
But as i sad over 90% of images works correct. After adding script they have W & H attributes and work fine