MadLittleMods
7/24/2015 - 9:02 PM

Wrap some content with a tag without having to deal with the concat hell :P

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;
}