javascript - display text in multiline using text area -


this question has answer here:

i using text area tag in html , have print ingredients in separate lines on using enter key coming in single line when pass value of text area variable , print it.

following code snippet :

<div data-role="fieldcontain">     <label for="name">ingredients</label>     <textarea rows="4" cols="50" id="new_ingredients">      </textarea> </div>  $( '#new_recipe' ).live( 'pagebeforeshow',function(event){     var temp1 = $("#new_ingredients").val();     $("#testing").text(temp1); });  <div data-role="page" id="new_recipe">     <div class="content" id="testing" ></div> </div> 

please me how data in different lines when user presses enter key.thank in advance.

use this:

$("#testing").html(temp1.replace(/\n\r?/g, "<br />")); 

the characters represented pressing "enter" key in textarea represented "\n" (sometimes \r well). when displaying in html, mean nothing more space, visually. display these newlines, need replaced html equivalent - <br /> elements.

since <br /> elements being added #testing element's contents, need use .html(), not .text(). otherwise, html escaped , won't display properly.

demo: http://jsfiddle.net/wkbrn/2/


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -