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


Groups > comp.lang.javascript > #31752

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

Newsgroups comp.lang.javascript
Date 2016-12-01 05:55 -0800
References <dc07c4cd-7623-42e4-abe0-972601884ec3@googlegroups.com> <XnsA6D16E788D90Eeejj99@194.109.6.166>
Message-ID <ec8aab6f-eddb-4859-86b8-876bd2d3ebec@googlegroups.com> (permalink)
Subject Re: Replacing javascript line break (\n) with HTML line break (<br/>)
From justaguy <lichunshen84@gmail.com>

Show all headers | View raw


On Thursday, December 1, 2016 at 4:51:37 AM UTC-5, Evertjan. wrote:
> justaguy <> wrote on 01 Dec 2016 in 
> comp.lang.javascript:
> 
> >  turn js line breaks inside HTML Textarea tag into HTML line breaks, <br/>
> 
> <br/> is NOT HTML, but XML. Why should you use that?????????
> 
> <br> is HTML.
> 
> ==================
> 
> The below works fine here in Chrome,
> no reason why it should not work in all other modern browsers:
> 
> ======
> <script type='text/javascript'> 
> 'use strict'
> 
> function changeBr() {
> 	let pa = document.getElementById('txa');
> 	pa.value = pa.value.replace(/\n/g,'\n<br>');
> 	toDiv();
> };
> 
> function toDiv() {
> 	let pa = document.getElementById('txa');
> 	let div1 = document.getElementById('div1');
> 	div1.innerHTML = pa.value;
> };
> 
> window.onload = toDiv;
> 
> </script>
> 
> <textarea id='txa' style='height:80px;'>
> one
> two
> three
> </textarea>
> <br><br>
> <button onclick='changeBr()'>
> change \n to \n&lt;br>
> </button>
> <br><br>
> <div id='div1' style='border:solid red 3px;float:left;'>
> ???
> </div>
> =====
> 

Good catch on the XML and HTML part for the line break!
But both of them should work for this purpose.

Probably I wasn't clear. The page has about 5 elements using Textarea and all of them references the same js function.  So, for instance, a Textarea element with id of 'legalStuff', I'll call up the js function of lb with lb('legalStuff') and another Textarea element of id of 'shortDesc' with lb('shortDesc').  Firefox ver 50 is a modern browser, isn't it?

Thanks. 

Back to comp.lang.javascript | Previous | Next — Previous in thread | 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