Reputation: 111
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
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