-2

Forgive my newbieness... Referencing this posit: jQuery convert line breaks to br (nl2br equivalent)

how do I marry

function nl2br (str, is_xhtml) {   
    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';    
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}

or

textAreaContent=textAreaContent.replace(/\n/g,"<br>");

into my existing function:

$(document).ready(function() {
    $.ajax({
        url : "Notes_copy.txt",
        dataType: "text",
        success : function (data) {
            $("#NotesTxtBx").html(data);
        }
    });
});

what is my textAreaContent in the above example for instance

Thanks so much

Community
  • 1
  • 1
Pawel
  • 25
  • 8

1 Answers1

0
$(document).ready(function() {
    $.ajax({
        url : "Notes_copy.txt",
        dataType: "text",
        success : function (data) {
            $("#NotesTxtBx").html(data.replace(/\\n/g,"<br>"));
        }
    });
});
Hugo Tostes
  • 412
  • 4
  • 13
  • Thanks Hugo, I actually expanded it to $("#NotesTxtBx").html(data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"
    ")); to actually catch the line breaks in the txt file
    – Pawel Oct 04 '13 at 21:11