I have a block of XML sample code that is all on one line, inside a <pre>
tag. I want to programmatically break it up into multiple lines and then add indentation.
The sample code is already formatted with HTML special characters replacing the left and right angle brackets for each tag.
I plan to manipulate the code using jQuery by loading as a jQuery object. But how can I go about entering a line break after each tag? Both \n
and <br>
end up printing as text, because, well, it's <pre>
. I basically want to simulate what happens in an IDE when you enter a newline with the return key. Any thoughts?
UPDATE:
Using .html() and \n
I got it to work, shown in this updated jsfiddle: http://jsfiddle.net/SPms3/17/
Neither of those should print as text. Use jQuery.html
, not jQuery.text
.