Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load external html into a div?

I've created this little code using jquery to load an external HTML file into my div, but it doesn't work, I'm running out of ideas. Any other jquery code works well. Any help appreciated:

<div id="zaladuj"> 
load external html file
</div> 
<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript"> 
    $('#zaladuj').click(function () { 
        $(this).load('s1.htm'); 
    }); 
</script> 
like image 525
user2660811 Avatar asked Oct 14 '13 22:10

user2660811


People also ask

How do I display one HTML page inside another?

The HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.

How do I load JavaScript into HTML?

Adding JavaScript into an HTML Document You can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.


1 Answers

You need to wrap your code within jQuery.ready() function since you have to wait for DOM to be fully loaded.

<script type="text/javascript">
    $(document).ready(function(){
        $('#zaladuj').click(function () { 
            $(this).load('s1.htm'); 
        }); 
    });
</script>
like image 106
Fouad Fodail Avatar answered Oct 15 '22 23:10

Fouad Fodail