dani jinji
dani jinji

Reputation: 471

simplest jquery test doesn't work

for some reason I just want to check if my jQuery loaded, but it doesn't work even though the src file in the script is a good link, any ideas?

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Demo</title>
</head>
<body>
    <a href="http://jquery.com/">jQuery</a>
    <script src="C:\wamp\www\jquery-test\jquery-1.11.3.min.js"></script>
    <script>

    $( document ).ready(function() {
        $( "a" ).click(function( event ) {
            alert( "The link will no longer take you to jquery.com" );
            event.preventDefault();
        });
    });

    </script>
</body>
</html>

Upvotes: 0

Views: 178

Answers (5)

T&#226;n
T&#226;n

Reputation: 1

$( "a" ).click(function( event ) {
  event.preventDefault();
  alert( "The link will no longer take you to jquery.com" )  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="http://jquery.com/">jQuery</a>

Upvotes: 0

Helping Hands
Helping Hands

Reputation: 5396

Load Jquery from CDN should work for you , Please check updated code :

<!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>Demo</title>
    </head>
    <body>
        <a href="http://jquery.com/">jQuery</a>
        <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
        <script>

        $( document ).ready(function() {
            $( "a" ).click(function( event ) {
                alert( "The link will no longer take you to jquery.com" );
                event.preventDefault();
            });
        });

        </script>
    </body>
  </html>

Your all other code seems fine , I just changed path to retrieve Jquery jquery-1.11.3.min.js and it is working.

Upvotes: 1

Rudresha Parameshappa
Rudresha Parameshappa

Reputation: 3926

try this it will work, you need to put event.preventDefault(); in the begining.

$( document ).ready(function() {
    $( "a" ).click(function( event ) {
    event.preventDefault();
        alert( "The link will no longer take you to jquery.com" );
    });
});

Upvotes: 0

Subodh Ghulaxe
Subodh Ghulaxe

Reputation: 18651

Try following code, since you are using wamp I have you can access jQuery on your local environment using this URL http://localhost/jquery-test/jquery-1.11.3.min.js

  <!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>Demo</title>
    </head>
    <body>
        <a href="http://jquery.com/">jQuery</a>
        <script src="http://localhost/jquery-test/jquery-1.11.3.min.js"></script>
        <script>

        $( document ).ready(function() {
            $( "a" ).click(function( event ) {
                alert( "The link will no longer take you to jquery.com" );
                event.preventDefault();
            });
        });

        </script>
    </body>

</html>

If above code does not work then load jQuery from some CDN like this

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

Upvotes: 0

Pirozek
Pirozek

Reputation: 1270

Load your jQuery from CDN instead of local path on your computer. This way, you dont need webserver running.

https://code.jquery.com/jquery-1.11.3.min.js instead of C:\wamp\www\jquery-test\jquery-1.11.3.min.js

Upvotes: 0

Related Questions