Last active
September 30, 2015 09:41
-
-
Save Raz0rwire/838b918424c24dd5e592 to your computer and use it in GitHub Desktop.
Replace all empty HTML Elements from string with Javascript, matching elements only :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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