Javascript - Detect Mobile width, Add lazy loading attr to a set of images

//Lazy Load Sidebar images on mobile
if(window.innerWidth <650){
console.log("mobile!");
const collection = document.querySelectorAll("#FeaturedProductsCombined img");
for (let i = 0; i < collection.length; i++) {
collection[i].setAttribute("loading", "lazy");
}

}

Index Previous