1

response.text contains the html source of google.com.
How come the html source is not wrapping inside my <pre>?
Current solution creates a huge side scrolling area, I'd like any text that goes beyond the window width to wrap.
I want to avoid use of innerHTML in this solution.

var pre = document.createElement('pre');
pre.appendChild(document.createTextNode(response.text));
document.getElementById("body").appendChild(pre);

css for <pre> ..

pre {
    outline: 1px solid #ccc; 
    padding: 5px; 
    margin: 5px; 
    white-space: -moz-pre-wrap; 
}
bobbyrne01
  • 6,295
  • 19
  • 80
  • 150

1 Answers1

3

Use like below,

pre {
    outline: 1px solid #ccc; 
    padding: 5px; 
    margin: 5px; 
    white-space: pre-wrap;       
    white-space: -moz-pre-wrap;  
    white-space: -pre-wrap;      
    white-space: -o-pre-wrap;    
    word-wrap: break-word;       
}
Anto king
  • 1,222
  • 1
  • 13
  • 26