html - how to add a line break in javascript that works with paragraph -


i wrote function format string :

var desc = document.getelementbyid('desc');             var parcontent = desc.textcontent.trim();             var temppar = "";             var j = 0;             var k = 0;             var built_val = "";              (var = 0; < parcontent.length ; i++)             {                 if (j == 19 || == parcontent.length-1)                 {                     temppar = parcontent.substring(k, i);                     temppar = temppar.concat("- \n");                     built_val = built_val.concat(temppar);                      temppar = "";                     //restart j                     j = 0;                     //update k                     k = i;                     continue;                 }                 j++;             }             desc.textcontent = built_val; 

desc dynamic paragraph empty @ first filled (its data composed after page loads), j number of characters desired in 1 line.

though have problem , \n doesn't work ; tried br
. how can insert new linebreak within javascript string such "built_val" ? please note how it's assigned html

after everything.

the textcontent property sets literal text of element (by adding text node), , not parse tags html. instead, should this:

desc.innerhtml = built_val;


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -