I have a system receiving an html document as an array of lines, an am inserting this into a div using .append().
If an html tag is opened in 1 line (array element) of the string, and not closed within the same line, .append() automatically closes the tag on the same line, though there is already a corresponding close tag later in the html string.
Minimal test code:
- $(document).ready(function() {
var testString = [ "<pre>Test line 1\n", "line 2\n", "line 3</pre>" ];
for (var i in testString) {
$('.replace').append(testString[i]);
}
}); Produces as output
-
<pre>Test line 1 </pre>line 2 line 3
Is there an append alternative without this behaviour?