Load html content in div

Sowmya picture Sowmya · Sep 20, 2013 · Viewed 28.6k times · Source

I am trying to load the content from another html file into my existing html file using jquery .load

But unfortunately it is not loading the content.

Please suggest me with the proper solution.

Here is my existing html and jquery to load content from external HTML file

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Review</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    </head>
    <body>
            <ul class="reviews" id="revw">

            </ul>
    </div>
    <script>
    function check(){
$( "#revw" ).load( "review_list.html #test" );
}
    </script>
    </body>
    </html>

Page from which we need to load the content

<html>
<head></head>
<body>
<div id='test'>
 Load this content to the id="revw" div.
</div>
</body>
</html>

Answer

techfoobar picture techfoobar · Sep 20, 2013

You are not calling the function check() anywhere.

Try this:

...
<script>
function check() {
    $( "#revw" ).load('review_list.html #target');
}
$(document).ready(function() {
    check(); // call the function
});
</script>
...