user3074956
user3074956

Reputation: 111

loading external text from .txt to a html file

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

Upvotes: 4

Views: 26961

Answers (1)

Ganesh Jadhav
Ganesh Jadhav

Reputation: 2848

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);

Upvotes: 8

Related Questions