1

So I edited this a bunch of times but basically i want to insert paragraphs from a text file into div. So far I've been able to change the "its me" to "hello World using Jqquery BUT instead of hello world I want to get the paragraphs from within the text file.

Thank you

This is what I have so far

<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script>
$("#test").html("Hello world")
</script>
Zruty
  • 8,377
  • 1
  • 25
  • 31
crnnrc2003
  • 21
  • 3
  • `document.write` isn't usually considered a good modern practice. Do you have jQuery available? Ajax and DOM insertion are easy-peasy if you do. It's not that bad without, either. – isherwood Sep 25 '14 at 21:00
  • http://christianheilmann.com/2005/06/21/six-javascript-features-we-do-not-need-any-longer/ – isherwood Sep 25 '14 at 21:01
  • This answer is good if you don't won't to use any JS libraries: http://stackoverflow.com/questions/196498/how-do-i-load-the-contents-of-a-text-file-into-a-javascript-variable – Papa Sep 26 '14 at 00:52
  • @isherwood thanks for responding. do you have any examples? the article you sent is good but i got lost when he started talking about clicking to make the text appear or disappear. I just want the text to load from a text file that I can alter whenever I want to update the text in the webpage without having to had code it. – crnnrc2003 Sep 27 '14 at 20:57
  • That article was only in support of my statement about `document.write`. I asked a question that you haven't answered. – isherwood Sep 28 '14 at 01:09
  • @isherwood yes I have Jquery i'm running DW CS6, sorry i thought you were trying to direct me to an answer with that article. Thanks again – crnnrc2003 Sep 28 '14 at 18:57
  • Have a look at `ajax()` and `get()` in the jQuery docs. Give it a try and update your question when you've made some progress. – isherwood Sep 28 '14 at 19:40
  • I just reedited. I think this is the closest thing to what Im looking for but i just need to know how to call insert the contents into a div – crnnrc2003 Sep 29 '14 at 00:17
  • with JQuery? Give your div an id and then: `$('#DivId').html('Contents');` – Chase Rocker Sep 29 '14 at 00:22
  • ok that worked, now how do I change "contents" to a text file. I used "hello world" but I want to upload the contents of a text file. – crnnrc2003 Sep 29 '14 at 00:55

1 Answers1

1

It took me a while but here it goes. I created a new external text file called test.txt & this code allows me to pull the text from this .txt file directly into my div tags. Now I can update my site without any hard coding. Here's the code.

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    $(document).ready(function(){
    $("#test").load("test.txt");//load the text from your text file
});
</script>
</head>

<body> 
    <div id="test">
        <p>its mer</p>
    </div>
</body>

I hope someone finds this useful and thanks to everyone that helped me figure this out.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
crnnrc2003
  • 21
  • 3