Skip to content

Instantly share code, notes, and snippets.

@daylik
Last active April 7, 2017 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daylik/5a8263c4c0f0a02308c2e386a379086c to your computer and use it in GitHub Desktop.
Save daylik/5a8263c4c0f0a02308c2e386a379086c to your computer and use it in GitHub Desktop.
function find_replace(selector, attr, find, replace, v){
v = {};
$(selector).each(function(){
v.img_src = $(this).attr(attr);
v.out = v.img_src.replace(find, replace);
$(this).attr(attr, v.out);
});
}
find_replace('img', 'src', /site.ru/i, '127.0.0.1');
//<img src="http://site.ru/img.jpg" />
//to
//<img src="http://127.0.0.1/img.jpg" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment