Skip to content

Instantly share code, notes, and snippets.

@bignimbus
Created January 4, 2016 20:09
Show Gist options
  • Save bignimbus/9a2661b147ce89ad34a0 to your computer and use it in GitHub Desktop.
Save bignimbus/9a2661b147ce89ad34a0 to your computer and use it in GitHub Desktop.
Parsing img tags in markup for jquery lazyload at runtime
function replaceSrc (html) {
// matches img tags, captures src
var imgSrcRegex = /\<img(.*)src\s?=\s?"(.*)"(.*)\>/gi;
// replaces src with data-original to ensure compatibility
// with jquery lazyload api
return html.replace(imgSrcRegex, '<img$1data-original="$2"$3>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment