Hi, I would like to know whether I need a comparison operator in the loop. As I want the script to feed the same image with an id of img_a to both a 320px width and a 568px width ?
var mqls = [
window.matchMedia("(min-width: 320px)") || window.matchMedia("(min-width:568px)"),
window.matchMedia("(min-width: 568px)"),
window.matchMedia("(min-width: 80em)")
]
function mediaqueryresponse(mql){
if (mqls[0].matches){
document.getElementById("img_a").src = "http://blog.wppionline.com/wp-content/uploads/2014/01/Rock-Camera-2.jpg";
}
if (mqls[1].matches){
document.getElementById("img_b").src = "http://www.gardenclassics.co.nz/img/product/rock-long-rock-large.gif";
}
if (mqls[2].matches){
document.getElementById("1").src = "http://placehold.it/400x300/000000/eeeeee?text=Large";
}
}
for (var i=0; i<mqls.length; i++){
mediaqueryresponse(mqls[i])
mqls[i].addListener(mediaqueryresponse)
}