Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31750

Replacing javascript line break (\n) with HTML line break (<br/>)

Newsgroups comp.lang.javascript
Date 2016-11-30 19:15 -0800
Message-ID <dc07c4cd-7623-42e4-abe0-972601884ec3@googlegroups.com> (permalink)
Subject Replacing javascript line break (\n) with HTML line break (<br/>)
From justaguy <lichunshen84@gmail.com>

Show all headers | View raw


task:
 turn js line breaks inside HTML Textarea tag into HTML line breaks, <br/>

code:
// el stand for document id
	var lb = function(el) {
	var pa = document.getElementById(el).value;
	pa = pa.replace(/\n/g,'\n<br/>');
	document.getElementById(el).value = pa;
}

outcome:
(1) tested with Firefox 50 for Windows, the very first instance of the Textarea behaved as expected, however, the function added two line breaks for another Textarea element that I hit Enter only once.
(2) tested with Safari v5.1.7 for Windows, I got inconsistent results (my target users for this particular app won't use this browser), so, I can ignore it.
(3) would love to test with Chrome, however, Chrome keeps on crashing on my current laptop.

Another thing:
It's not elegant to bring the <br/> down to next line...

Thoughts?  Thanks as always.

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Replacing javascript line break (\n) with HTML line break (<br/>) justaguy <lichunshen84@gmail.com> - 2016-11-30 19:15 -0800
  Re: Replacing javascript line break (\n) with HTML line break (<br/>) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-01 10:51 +0100
    Re: Replacing javascript line break (\n) with HTML line break (<br/>) justaguy <lichunshen84@gmail.com> - 2016-12-01 05:55 -0800
      Re: Replacing javascript line break (\n) with HTML line break (<br/>) justaguy <lichunshen84@gmail.com> - 2016-12-01 05:59 -0800
      Re: Replacing javascript line break (\n) with HTML line break (<br/>) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-12-01 16:41 +0100
    Re: Replacing javascript line break (\n) with HTML line break (<br/>) Cybercode <lambda@dr.com> - 2016-12-01 17:49 +0000
      Re: Replacing javascript line break (\n) with HTML line break (<br/>) justaguy <lichunshen84@gmail.com> - 2016-12-01 13:09 -0800
      Re: Replacing javascript line break (\n) with HTML line break (<br/>) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-01 23:13 +0100
        Re: Replacing javascript line break (\n) with HTML line break (<br/>) rmmjr@rmmillerjr.com - 2016-12-11 07:10 -0800
          Re: Replacing javascript line break (\n) with HTML line break (<br/>) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-11 16:53 +0100
        Re: Replacing javascript line break (\n) with HTML line break (<br/>) rmmjr@rmmillerjr.com - 2016-12-11 07:10 -0800

csiph-web