Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$ is undefined error in jquery

I am getting this error while using twitter bootstrap. I didn't get this error when using it in html. I converted it into a wordpress theme, and now i am getting this error.

<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$('.dropdown-toggle').dropdown()
</script>

I am getting these errors.

  1. "$ is undefined" on bootstrap-dropdown.js line 72.
  2. "$(".dropdown-toggle").dropdown is not a function"

any help is much appreciated. thanks.

edit: i tried this https://stackoverflow.com/a/9301017/759257

and included the latest jquery version 1.7.1 and now it works!!

like image 956
Karthik Avatar asked Feb 16 '12 15:02

Karthik


People also ask

What is undefined jQuery?

The undefined property indicates that a variable has not been assigned a value, or not declared at all.

Is not defined check jQuery?

You may experience the “jQuery is not defined error” when jQuery is included but not loaded. Make sure that it's loaded by finding the script source and pasting the URL in a new browser or tab. The snippet of text you should look for to find the URL to test.

Is undefined JavaScript error?

Undefined means that a variable has been declared but has not been assigned a value. In JavaScript, properties and functions can only belong to objects. Since undefined is not an object type, calling a function or a property on such a variable causes the TypeError: Cannot read property of undefined .


3 Answers

You're loading the scripts in the wrong order. Load jQuery first, otherwise it won't be available for the bootstrap script.

like image 173
JJJ Avatar answered Oct 18 '22 09:10

JJJ


You're not setting it in the right order:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js"></script>
<script type="text/javascript">
$('.dropdown-toggle').dropdown();
</script>
like image 36
Alex Avatar answered Oct 18 '22 08:10

Alex


I assume the "bootstrap-dropdown.js" file is a jQuery plugin. If that's the case, you need to load jQuery first, so switch your <script> tags around.

like image 22
Anthony Grist Avatar answered Oct 18 '22 09:10

Anthony Grist