I have 2 external html file (header and footer),
that I load with this code:
<div id="header-div"></div>
<div id="footer-div"></div>
$(function () {
$("#header-div").load("/AfekDent/header.html");
$("#footer-div").load("/AfekDent/footer.html");
});
the header file include javascript code that isn't working..
function switchClass(i) {
var lis = $('#home-news > div');
lis.eq(i).removeClass('home_header_on');
lis.eq(i).removeClass('home_header_out');
lis.eq(i = '++i' % lis.length).addClass('home_header_on');
lis.eq(i = '++i' % lis.length).addClass('home_header_out');
setTimeout(function () {
switchClass(i);
}, 3500);
}
$(window).load(function () {
switchClass(-1);
});
what is the problem?
1 Answer 1
The $(window).load() event is called on the page load, not when the additional HTML has been loaded.
answered Apr 2, 2016 at 17:35
Paul
36.4k12 gold badges98 silver badges124 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Dudi Delman
Ok, so what trigger indicate all elements are loaded (includ the elment in the header files)?
Paul
There isn't one that does what you're asking, at least not directly. The
.load() method does allow for a callback function, though, so you could track yourself when each of your additional html files is complete and call whatever logic you want when they're both done.default
<script>tags? Can you give us a complete exanple of the header and footer, please?.htmlor.htm