0

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?

3
  • Did you wrap your script in<script> tags? Can you give us a complete exanple of the header and footer, please? Commented Apr 2, 2016 at 17:33
  • no, the scripts are in an external .js file. Commented Apr 2, 2016 at 18:03
  • Your post's title: Javascript on load external html files. That's what I was asking for. An external HTML file ends with an extension of .html or .htm Commented Apr 2, 2016 at 18:05

1 Answer 1

1

The $(window).load() event is called on the page load, not when the additional HTML has been loaded.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, so what trigger indicate all elements are loaded (includ the elment in the header files)?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.