0

I created a web page wherein I want to display there another HTML file. I used jQuery to do this but wasn't able to display the content of the file I have included. Why do you think this happened. Thanks a lot.

Here's my code for my mainpage.

sample.html

<html>
<head>
<title> Sample Only </title>

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js"></script>
    <script> 
        $(function(){
            $('#footerLang').load("sampleFooter.html");
        });
    </script> 


</head>

    <body>

        <div id="footerLang">
            <h1></h1>
        </div>

    </body>

</html>

sampleFooter.html

<p> THIS IS A FOOTER </p>
4
  • 1
    check on Firefox browser Commented Sep 1, 2016 at 6:43
  • @LaljiTadhani you're right. Commented Sep 1, 2016 at 7:14
  • Ajax nga gamitin mo. Loooool. Kahapon pa to e. Di mo parin nakuha. Hahahaha Commented Sep 1, 2016 at 7:32
  • @HermLuna Men browser incompatibility lang ang issue. Commented Sep 1, 2016 at 12:36

2 Answers 2

2

It is highly possibly because you are placing the following block in head without $(document).on("ready", function() { ...; });

$(function(){
    $('#footerLang').load("sampleFooter.html");
});

In this case jQuery will unable to find the #footerLang element since the DOM is not ready, you could revise the script as follow

$(function(){
    $(document).on("ready", function () {
        $('#footerLang').load("sampleFooter.html");
    });
});

or move the script tag just before the </body>

<html>
<head>
<title> Sample Only </title>

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js"></script>


</head>

    <body>

        <div id="footerLang">
            <h1></h1>
        </div>

    <script> 
        $(function(){
            $('#footerLang').load("sampleFooter.html");
        });
    </script> 
    </body>

</html>
Sign up to request clarification or add additional context in comments.

Comments

0

I found out that this was just a browser compatibility issue. I launch it in Firefox and it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.