Text with newline inside a div element is not working
Add this css:
#testResult
{
white-space:pre-wrap;
}
Demo
You could try a simple css approach maybe?
#testResult {
white-space: pre-wrap;
}
This will preserve the \n in your output.