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.

http://jsfiddle.net/b7qhz/2/

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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -