Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add content from file using jQuery?

Tags:

html

jquery

I have main html document:

<html><head></head>
<body>
    <div id="content">
    </div>
</body>
</html>

Also I have a content file (not the html document, just html code):

<div class="CodeRay">
<div class="code"><pre><span class="no">   1</span> require
....
</pre></div>

I want to add the content file to html document like here:

<html><head></head>
    <body>
        <div id="content">
            <div class="CodeRay">
            <div class="code"><pre><span class="no">   1</span> require
            ....
            </pre></div>
        </div>
    </body>
</html>

How to use jQuery to accomplish this task? Also I need to run this site localy. Thanks.

EDIT: Locally means like this "file:///E:/Work/ReadTheCode/main.html"

like image 501
megas Avatar asked May 30 '11 22:05

megas


2 Answers

Use jQuery's .load() function. The code would probably look something like this:

$(document).ready(function(){
  $('#content').load('contentFile.html');
});

If you need more info, here is the link to jquery's load documentation.

like image 118
Vap0r Avatar answered Oct 01 '22 12:10

Vap0r


you can use something like this:

$('#result').load('ajax/test.html');

See: http://api.jquery.com/load/

like image 26
Dan Avatar answered Oct 01 '22 11:10

Dan