image - Replace part of filename with javascript -
i want load different images based on screensize, , thought replacing text in filename javascript trick elegantly, long i've got corresponding images named. i'm close this, close won't cut it.
javascript:
if ($(window).width() > 960) { $("div:contains(_small.jpg)").html(function (i, currentval) { return currentval.replace("_small.jpg", "_large.jpg"); }); }
html:
<img src="...test-image_small.jpg" />
as can see in fiddle, i've got working on text, not filename.
ps - don't want load images background-image in media-queried classes.
complete function:
if ($(window).width() > 960) { $("img[src$='_small.jpg']").each(function() { var new_src = $(this).attr("src").replace('_small', '_large'); $(this).attr("src", new_src); }); } else { alert('less 960'); }
Comments
Post a Comment