Skip to content

Instantly share code, notes, and snippets.

@MadLittleMods
Created July 24, 2015 21:02
Show Gist options
  • Save MadLittleMods/e9d58b1c363bdc816267 to your computer and use it in GitHub Desktop.
Save MadLittleMods/e9d58b1c363bdc816267 to your computer and use it in GitHub Desktop.
Wrap some content with a tag without having to deal with the concat hell :P
// tag: '<a href="foo.html">'
//
// ex. usage: `wrapWithHtmlIf('<a href="foo.html">', 'Hello World', function() { return true });`
// output: '<a href="foo.html">Hello World</a>'
var wrapWithHtmlIf = function(tag, content, testCb) {
if(testCb()) {
return tag + content + '</' + tag.match(/<(\w*?)(?:\s|\>)/)[1] + '>';
}
return content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment