I am very new to web development and Javascript in general and I hae done some Jquery coding by adding my code in my HTMl code all the time. Now, I just moved the same code to my .Js file and my console shows me following error:
$ is not defined [Break On This Error] $(document).ready(function () {
It just says JQuery is not defined. It means that I can not refer to Jquery or any other Javascript files in my Js file?
Or there is something that I am missing here?
Just include jQuery before your script is called
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
For other jQuery stuff available in CDN, see this:
http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery
Update: This is as close to "using" as you can get, in my mind. It's not required to download the jQuery library to your system or host it on your server.
in your html did you move the whole jquery file into your .js file? you shoudl have it as something like:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"type="text/javascript"></script>
// Now load your .js file
<script type="text/javascript" src="your .js file"></script>
Also if you downloaded jquery forget about it, the top link means you're loading jquery from google so you'll always have the latest version, I really cant be much more help unless you upload your code, sorry.
Related
I am following the "Using Play Framework with scala" tutorial. I am able to follow all the steps except the last one to use the coffeescript with jquery. I can see the javascript file getting generated, but in the browser, I am seeing this error
"ReferenceError: $ is not defined".
I am new to javascript and coffeescript,
here is my coffeescript code:
and here is the javascript as shown in the browser console
is there some syntax issue that can cause the problem? Help appreciated.
I am attaching the image, if indentation could be one of the reasons for this to fail.
add this line (depending on your version of jQuery)
<script src="#routes.Assets.at("javascripts/jquery-1.11.2.js")" type="text/javascript"></script>
to the <head> </head> section in app/views/main.scala.html .
For me, this template is loading for every page. but first you need to download jQuery and add it to your javascripts folder (under public).
In Play 2.3: Note the lib/jquery/jquery.js path. The lib folder denotes the extract WebJar assets, the jquery folder corresponds to the WebJar artifactId, and the jquery.js refers to the required asset at the root of the WebJar.
So just add
<script type="text/javascript" src="#routes.Assets.versioned("lib/jquery/jquery.js")"></script>
to the <head> </head> section in app/views/main.scala.html.
basic javascript, now everything seems crystal clear.
Just one line to include jquery in the index.scala.html to include jquery plugin.
In an HTML file, I included jQuery via
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
I downloaded the library via the context menu and now see it in the project folder under External Libraries. Yet, it seems jQuery is not recognized.
<script type="text/javascript">
$(document).ready(function() {
..
});
</script>
The $ is underlined and code hinting asks me to create a function or method called $. The code itself works though.
What am I supposed to do to make PhpStorm recognize the external JavaScript library?
As LazyOne pointed out in his comment I had to look up settings, and there I realized I had to download the library again, and made it global.
I have a few JSP pages, that include some JavaScript(jquery, jquery mobile and some javascript functions that I wrote).
When loading the pages and try to run my functions, I get in Firebug an error, that the function was not found. I have looked into the page source, and the function is there.
All the other jquery mobile functions work.
The only way to make my script work is to make a forced refresh(ctrl+f5).
Why is this happening? How can I fix it?
EDIT
It seems that a simple refresh would also work.
Here is the source code of the page:
http://pastebin.com/6sJnfPDQ
I have retagged your question to remove "Java" and "JSP", as this is irrelevant (server vs browser).
Once your JSP is rendered in the browser, please do look in the page source and see what happened to your tags.
make sure all of your js files are being loaded properly.
also make sure that your js files are being loaded in the proper order.
make sure that, where necessary, you're wrapping your JS in a document ready function of some type
also, I recommend that you add the type attribute to your script tags:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
Why do I get this error on 2 of my externally called JavaScript files?
I tried the code inside my index.html file and it ran perfectly.
I've called all my scripts before stylesheets.
There are 4 scripts running on this page, all JavaScript, 2 of them work but 2 of them don't.
Try putting jQuery script tag on top of the other script tags.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
You will receive this error if you are trying to use jQuery without having included the library.
Did you forget to include the jQuery library? Or maybe your url to the .js file is incorrect.
i need jquery to work on a browser locally. how do i know if it is installed and how do i install it ?
my question is specific to being able to run this code:
onmouseover="evt.target.setAttribute('opacity', '0.5'); $('#someDiv').show();"
onmouseout="evt.target.setAttribute('opacity', '1'); $('#someDiv').hide();"
You can test if jQuery is loaded by opening your javascript console (in Chrome: Settings > More tools > Javascript console).
Where the little blue arrow appears type:
if(jQuery) alert('jQuery is loaded');
Press enter.
jQuery isn't installed like a program, it's a file that needs to be included in your source code somehow, the most common practice is to include by adding <script type='text/javascript' language='javascript' src='local/path/to/jquery.js'></script> in the <head> section of your page.
If you are going to include jQuery locally, as per Robert's suggestion, you will first have to download it from here: http://code.jquery.com/jquery-1.4.2.min.js
put this right above your closing body tag:
<script src="//ajax.googleapis.com/ajax/libs/jquery/[jquery version here]/jquery.min.js"
language="javascript" type="text/javascript"></script>
jquery isn't "installed" into a browser. it's a js library referenced from the web page you are viewing.
EDIT: This works if you have internet access. If not, you will have to download that file to your local system and reference the local path.