2575Suggestion for whitespace exception when building an HTML string
var html = '<div><div><img src="http://example.com/image.gif" /></div</div>';
I like to do this (in case the indention isn't preserved with this post, imagine each line being indented as if to show a hierarchy like in an HTML document):
var html =
'<img src="http://example.com/image.gif" />' +
This makes maintenance much easier since I can see the HTML in a familiar structure which lets me ensure each tag is properly closed, etc. Since I use YUI Compressor which uses constant folding when minifying the HTML, I still end up with just one string being created at runtime. Right now JSLint gives a warning when my code is formatted this way, forcing me to specify the sloppy whitespace option which means that all the other whitespace in the document no longer gets validated. It seems like JSLint could easily detect string concatenation and not enforce its whitespace rules on those lines.
- Next post in topic >>