Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Selectively Serving Images Using HTML5 “data-” attribute & Match Media for Responsive Site Re: Selectively Serving Images Using HTML5 “data-” attribute & Match Media for Responsive Site

#116689
robhawk
Member

Hi,

Firstly thanks for getting back to me so quickly with help. I’ve tried the above but the height and width are still shown in IE.

//images enhancement
if (window.matchMedia(“(min-width: 46.875em)”).matches) {
//load in the images

var lazy = Utils.q(‘[data-src]’);
for (var i = 0; i < lazy.length; i++) {
var source = lazy.getAttribute(‘data-src’);
//create the image
var img = new Image();
img.src = source;
//insert it inside of the link
img.removeAttribute(‘height’);
img.removeAttribute(‘width’);
lazy
.insertBefore(img, lazy.firstChild);
};

Perhaps I’ve done something wrong?!

Look forward to hearing from you.

Regards

Rob