How to add content from a file using jQuery?

I have a basic html document:

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

I also have a content file (not an html document, just HTML code):

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

I want to add a content file to an 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 complete this task? Also I need to run this site locally. Thank.

EDIT : locally means this file: /// E: /Work/ReadTheCode/main.html

+5
source share
2 answers

Use jQuery function .load(). The code will probably look something like this:

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

If you need more information, here is a link to the jquery download documentation.

+9
source

- :

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

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

+2

All Articles