Here is my question,
I have a text file and I am reading the file using jquery.
the code is here
$(function() {
    $.get('files/james.txt', function(data) {
        $('.disease-details').html(data);
    }, 'text');
});
but I am getting only plain text and all formatting is disappearing.
I want to convert all the enter in to p tag.  is it possible?
You can do this :
$(function() {
     $.get('files/james.txt', function(data) {
        data = data.split("\n");
        var html;
        for (var i=0;i<data.length;i++) {
            html+='<p>'+data[i]+'</p>';
        }
        $('.disease-details').html(html);
    }, 'text');
});
The above splits up the text by new line (the text-"formatting") and wraps each chunk into a <p> .. </p> .. Exactly as requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With