javascript - loading external text from .txt to a html file - Stack Overflow

admin2025-04-03  0

I know how to load external text from a .txt file using

<div id="text"> <div> 

and javascript

 $("#text").load("pathtofile/content.txt"); // element's id should be in string form

but can this be done between two < p > tags instead of inserting into a div? if so how?

Thanks

I know how to load external text from a .txt file using

<div id="text"> <div> 

and javascript

 $("#text").load("pathtofile/content.txt"); // element's id should be in string form

but can this be done between two < p > tags instead of inserting into a div? if so how?

Thanks

Share edited Dec 13, 2013 at 5:02 robieee 3642 silver badges19 bronze badges asked Dec 12, 2013 at 12:56 user3074956user3074956 1112 gold badges5 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

To get the text from only a paragraph from the file, try this:
HTML:

<div id="tempDiv" style="display: none;"></div>
<p id="text"></p>

JQuery:

 var tempDiv = $('#tempDiv');
 tempDiv.load("pathToFile/content.txt");
 var html = tempDiv.find('#theParagraphId').html();
 $('#text').html(html);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1743682019a215320.html

最新回复(0)