user4893937
user4893937

Reputation:

jQuery: $ not defined

I want to make simple jQuery click function. But this one dose not work. not even the simple alert. could you please assist me.

$(document).ready(function(){ alert("JavaScript is working");
$("#tab").slideUp("fast");
$("#steps").click(function(){
$("#tab").slideToggle("slow");
});
});

If you think it is a link error then my all link go like:

<link type="text/css" rel="stylesheet" href="divset.css">
<link type="text/css" rel="stylesheet" href="top.css">
<script type="text/javascript" src="hint2.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

where divset.css, top.css and hint2.js are my css and jQuery documents.

Upvotes: 1

Views: 644

Answers (2)

Arun P Johny
Arun P Johny

Reputation: 388316

From the markup you have shared it looks like said script is in the file hint2.js, if so when that script is executed jQuery is not yet loaded that is the readon for the error so

<link type="text/css" rel="stylesheet" href="divset.css">
<link type="text/css" rel="stylesheet" href="top.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="hint2.js"></script> 

Upvotes: 3

Norlihazmey Ghazali
Norlihazmey Ghazali

Reputation: 9060

Add your code after jquery libs.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="hint2.js"></script> 

Upvotes: 6

Related Questions