Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 528
user3074956 Avatar asked Feb 15 '23 09:02

user3074956


1 Answers

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);
like image 167
Ganesh Jadhav Avatar answered Feb 17 '23 03:02

Ganesh Jadhav