Question: I swear I have included jquery in the page header, it is right there!

Nonetheless the following code, which I've included near the bottom of the page (and inline for now) gives me an error saying "TypeError: $ is not a function."

```
<script>
        function displayResult(longA, latA, longB, latB, units) {
            $("#distance").html(calcDist(longA, latA, longB, latB, units));
            if (units=="m") {
                $("#unitLabel").html("miles");
                $("units").prop("selectedIndex",0);
            } else {
                $("#unitLabel").html("kilometers");
                $("#units").prop("selectedIndex",1);
            }
            $("#longA").val(longA);
            $("#latA").val(latA);
            $("#longB").val(longB);
            $("#latB").val(latB);
        }

        $("#calculateButton").click(function() { //This is the line it's complaining about
            var longA=$("#longA").val();
            var latA=$("#latA").val();
            var longB=$("#longB").val();
            var latB=$("#latB").val();
            var units=$("#units").val();
            displayResult(longA, latA, longB, latB, units);
        })(jQuery);
    </script>

```

Higher up in the page header I've got the following:

```
<script src="jquery.js" ></script>
<script src="calcDistSinglePage.js" ></script>

```

I'm not using Wordpress or anything, this is a very straightforward hand-coded HTML page.

Answer: 
Make sure the **jQuery library** it's the first script you load.

Add this just before the closing `</body>` tag.

```
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
            <script>window.jQuery || document.write('<script src="js/vendor/jquery-{{JQUERY_VERSION}}.min.js"><\/script>')</script>

```

* Download the file locally and inside js/vendor/ add the file.
* Replace the value {{JQUERY\_VERSION}} in the script above adding your jquery version.

Here one CDN you could use.

<https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js>

<https://code.jquery.com/jquery-2.1.3.min.js>
You are probably linking it from a root folder that is not your HTML folder. Use an absolute path:

```
<script src="/jquery.js" ></script>

```

Or make sure `jquery.js` is in the *same* folder as your HTML.