소프트웨어/HTML

txt파일 include하고 line break 나타내기

개발자_이훈규 2017. 10. 29. 20:43

include txt file on html


As MrN00b noted, I am assuming you have left out the inclusion of the jQuery js file itself? Please include it, if you have not already, as it is not implicitly part of a web page.

As your code precedes the item in the document it references (id="text"), you need to wait for the document to complete loading:

Use one of these so that your jQuery will wait for the DOM to finish loading:

Traditional:

     $(document).ready(function(){
         $('#text').load("/textdoc.txt");
     });

Shortcut:

     $(function(){
         $('#text').load("/textdoc.txt");
     });

Safe (locally scoped $):

     jQuery(function($){
         $('#text').load("/textdoc.txt");
     });




line break on html with txt file


Add white-space:pre-line; to your container:

#load-changelog {
    white-space: pre-line;
}

https://stackoverflow.com/questions/9726970/how-to-preserve-newlines-when-showing-a-text-file-with-jquery