Spilot
Spilot

Reputation: 1525

why is this very simple jquery not working?

All I have is a simple html page and a simple .js file. I can't find any syntax errors. The jquery library is included where it's supposed to be, as is the .js file. Any idea what might be going wrong?

The first chunk of code is my html:

<!DOCTYPE html>
<html>
    <head>
    <script src="http://myDomain.com/myInvites.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script src="http://www.parsecdn.com/js/parse-1.2.2.min.js"></script>

    </head>
    <body>
        <div id="mainDiv">

            <p><a href="#">anchor</a></p>

        </div>
    </body>
</html>

This is the .js page named myInvites.js:

$(function()
{
    $('#mainDiv').click(function()
    {
        alert("working");

    });//closes click
});//closes function

Upvotes: 2

Views: 205

Answers (1)

Blender
Blender

Reputation: 298106

Your JS file is loading before jQuery. You can't utilize jQuery if it hasn't loaded yet.

Switch the order of the first two script tags:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://myDomain.com/myInvites.js"></script>

Upvotes: 14

Related Questions