Reputation: 1
I have a JavaScript file with this line:
$('.item').load('page'); // (tried with document ready)
It does not work. It looks like the line executes before the page is fully loaded (because it works when I type the same line in the console).
Upvotes: 0
Views: 1164
Reputation: 14823
There are a couple of conditions you need to verify. The path to the document (including file extension) needs to be correct relative to the page that is using this load function. The element you are trying to load into needs to exist.
Are you getting errors in your console? What does it say?
This absolutely works.
<body>
<div class="item"></div>
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
<script>
$(document).ready(function() {
$('.item').load('page.html');
});
</script>
</body>
Upvotes: 1
Reputation: 457
Have you tried waiting until the window is loaded?:
$(window).load(function(){
$('.item').load('page');
});
Upvotes: 0
Reputation: 460
do
$('document').ready(function(){
$('.item').load('page');
});
You need to call it when the page is ready.
Upvotes: 0