Skip to content

Instantly share code, notes, and snippets.

@Raz0rwire
Last active September 30, 2015 09:41
Show Gist options
  • Save Raz0rwire/838b918424c24dd5e592 to your computer and use it in GitHub Desktop.
Save Raz0rwire/838b918424c24dd5e592 to your computer and use it in GitHub Desktop.
Replace all empty HTML Elements from string with Javascript, matching elements only :)
//Nested empty elements will need some iterating to clear those out
function removeEmtpyElements(str, iterations){
var re = /<([A-z]+)([^>^/]*)>\s*<\/\1>/gim;
var subst = '';
for(var i = 0; i < iterations; i++){
str = str.replace(re, subst);
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment