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.
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 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.
I have taken script from a webpage document I have made and I have saved onto a notepad document with the extension .js.
I would like to now know how I can reference this .js file from the current page that I have created so that the script will run on that page without the actual code being there, just the reference link.
Something like this?
<script type="text/javascript" src="myfile.js" />
It must be a reference link. There are other techniques besides the standard, but they all rely on linkage. You can't beat the linkage. You can't stop the linkage. You mus succumb to the linkage.
That's not how the web works? You might be able to use some sort of developer tool to execute arbitrary javascript from a file when the page loads, but that would just be overriding the default way the web works.
you will need to do :
<script type="text/javascript" src="URI_TO_DIR/extension.js"></script>
see this page about embedding a javascript file
if script is on your computer, it will of course not be accessible on the web, for that you'd need a webserver or a webspace
You can include an external JavaScript using a script tag with a src attribute. For example, something like
<script type="text/javascript" src="javascriptfile.js"></script> should do what I think you're asking for.
I have website A: http://dl.dropbox.com/u/3264697/calc/v2/index.html
It is working as intended, 100%.
I have website B: http://pe2kasb.net63.net/
It is not working as intended. Website B is a file for file mirror of A.
I assume then, this is something wrong with the host. Looking at the Javascript console, the error appears to be related to the host:
screenshot here http://img825.imageshack.us/img825/4782/unlednwe.png
Need I contact them, or is there something I can do...? I'm new to JQuery, and I believe that's what is the root of the issue but... i'm not sure.
You are trying to load jQuery from ../v2/media/js/jquery.js but there is no such file in the second website.
I recommend that instead of hosting JQuery yourself, you use a hosted version:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript">
</script>
This post explains the reasons.
You have invalid jQuery path at http://pe2kasb.net63.net/
Replace
<script type="text/javascript" src="../v2/media/js/jquery.js"></script>
with
<script type="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
Also you have dataTable.js missing.
You are loading JQuery from ../v2/media/js/jquery.js which does not seem to exist...
To solve the issue and improve the speed of the website
do not store JQuery on the server, rather load it from a 3rd party (Google works well)
use JQuery minified version
To load JQuery from Google you can just use:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
More information here
EDIT: note that the above automatically loads the minified version of JQuery. If, for whatever reason (?) you wanted to load the uncompressed version you could use
google.load("jquery", "1", {uncompressed:true});
Look what http://pe2kasb.net63.net/v2/media/js/jquery.js refers to.
The file does not exist.
Upload it or include it from another location.
Make sure that jQuery is correctly linked, currently jQuery is supposed to be at "../v2/media/js/jquery.js" on "http://pe2kasb.net63.net/", which means go back one folder then enter "/v2/media/js/jquery.js".