0

I'm trying to test out how the animate() function works, and this is an example I got from stackexchange actually (it works on fiddle), but when I run it on my local computer, it doesn't work anymore.

Here's the code:

<html>

<head>
    <script type="text/javascript" src="scripts\jquery-1.11.0.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('button').click(function () {
                $('div').animate({
                    width: 'toggle'
                });
            });
            alert("hei");
        });
    </script>
    <style type="text/css">
        div {
            background-color: red;
            height: 100px;
            width: 100px;
            display: none;
        }
    </style>
</head>

<body>
    <button>Show/Hide</button>
    <div></div>
</body>

Why is this? When I refresh, there's no alert popping up so it's not even processing the javascript I have in there. But it works fine in fiddle.

Oh, and here's the fiddle. But I really don't think it's relevant since it works there, just not on my local computer. Am I missing declaring a library?

7
  • Your jQuery path should use slash instead of backslash. Also, any JS error in console? Commented Feb 25, 2014 at 5:45
  • Do you load jQuery correctly? Commented Feb 25, 2014 at 5:47
  • working fiddle http://jsfiddle.net/cCGN7/1/ Commented Feb 25, 2014 at 5:47
  • Good catch. The console gives me two errors: Failed to load resource: the server responded with a status of 404 (Not Found) localhost/tests/scripts/jquery-1.11.0.js Uncaught ReferenceError: $ is not defined Commented Feb 25, 2014 at 5:49
  • 1
    Did your jQuery JS file exist in scripts/ folder? Probably not. Commented Feb 25, 2014 at 5:51

3 Answers 3

2

Please change below line :

<script type="text/javascript" src="scripts\jquery-1.11.0.js"></script>

with this one :

 <script type="text/javascript" src="scripts/jquery-1.11.0.js"></script>

You have used backslash instead of slash

It work For me

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

Comments

1

I think your jQuery path is not correct you have used

scripts\jquery-1.11.0.js

normally we used scripts/jquery-1.11.0.js

1 Comment

you're right, my path wasn't correct. I've corrected it now.
0

scripts\jquery-1.11.0.js should be scripts/jquery-1.11.0.js

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.