<textarea></textarea> <div></div> <script> var str = 'asdf\\nasdf\\nasdf\\nasdf'; document.body.children[0].value = str; document.body.children[1].innerHTML = str.replace(/\n/g, '<br>'); </script>