I want to replace src
from data-src
and I have the script but it's not working properly. Please modify this given script.
This is the script which I want to load before loading images but it's not working properly so please fix this.
var region = document.getElementsByClassName("content");
if (region) {
var img = region.getElementsByTagName("img");
for (var i = 0; i < imgEl.length; i++) {
if (imgEl[i].getAttribute('src')) {
imgEl[i].setAttribute('data-src', imgEl[i].getAttribute('src'));
imgEl[i].removeAttribute('src');
}
}
}
<div class='content'> <img src="img.jpg" alt="img"> </div>