1

I'm trying to make a script that imports my site's header into each page. I have already seen these pages:

I followed these sites, and I still get this error in the console:

jQuery.Deferred exception: Object doesn't support property or method 'load' 
TypeError: Object doesn't support property or method 'load'
   at Anonymous function (http://localhost/header-footer.js:4:5)
   at l (https://code.jquery.com/jquery-3.3.1.slim.min.js:2:29559)
   at Anonymous function (https://code.jquery.com/jquery-3.3.1.slim.min.js:2:29869) undefined

My index.html has the following in the body section:

<div id="header"></div>
<script src="..." integrity="..." crossorigin="anonymous"></script> <!--jQuery-->
<script src="/header-footer.js"></script> <!--Shown below-->

The header-footer.js file includes:

$(document).ready(function () {
    var header = $("#header");
    header.addClass("container-fluid clearfix"); // Bootstrap classes (unrelated as far as I know)
    header.load("/header.html");
});

I would just like to be able to import my header.html file into my index.html file.

I don't think this is related to the error, but here are the contents of my header.html file:

<ul class="list-inline">
    <li>
        <div class="dropdown">
            <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</button>
            <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownButton">
                <a class="dropdown-item" href="...">Another page</a>
            </div>
        </div>
    </li>
    <li><a class="btn btn-primary" href="/" role="button">Home</a></li>
    <li class="lead" style="float: left;">Website Name</li>
</ul>
<hr>

What silly mistake have I made? Thank you!

2
  • 2
    You're using jquery slim. Is that correct? Try to use code.jquery.com/jquery-3.2.1.min.js instead of slim version. Commented Nov 3, 2018 at 0:10
  • 1
    Glad to hear @RenanAraújo helped. You can also see here for other differences between jQuery and jQuery slim: stackoverflow.com/questions/35424053 Commented Nov 3, 2018 at 0:13

1 Answer 1

2

You're using jquery slim.

Use code.jquery.com/jquery-3.2.1.min.js instead of slim version to use load method.

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

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.