PDA

View Full Version : making jquery work


tony09uk
01-23-2013, 07:46 PM
Hi, I am trying to learn jquery and seem to be struggling to get it to work, can someone please help.

So far I have gone to Jquery (http://jquery.com/download/) and copied and pasted the source code into a .js file which I have name jquery.
I have referenced the file <script src="jquery.js"></script> in the body of my practice page.

I then added

<script>

var lis = jquery('ul li').css('color', 'green');

</script>

and in the browser using the developer tools I got the following message
"Uncaught ReferenceError: jquery is not defined "
I assume i have got something worng, can you please help?

Corrosive
01-24-2013, 10:04 AM
Check all of your paths and locations.

jmichae3
02-01-2013, 06:55 AM
Hi, I am trying to learn jquery and seem to be struggling to get it to work, can someone please help.

So far I have gone to Jquery (http://jquery.com/download/) and copied and pasted the source code into a .js file which I have name jquery.
I have referenced the file <script src="jquery.js"></script> in the body of my practice page.

I then added

<script>

var lis = jquery('ul li').css('color', 'green');

</script>

and in the browser using the developer tools I got the following message
"Uncaught ReferenceError: jquery is not defined "
I assume i have got something worng, can you please help?

try sourcing that js file BEFORE you try to use any of its functions. you will have better success then.
like this:

<script src="jquery.js"></script><!--sorry, can't place code in there except comments-->
<script>
var lis = jquery('ul li').css('color', 'green');
</script>


also, are you sure you are cqalling it right? every place I have seen references the page as $, so I should think it's something like

<script src="jquery.js"></script><!--sorry, can't place code in there except comments-->
<script>
var lis = jquery('ul li').css('color', 'green');
</script>


I am definitely no jquery expert here. I would have to get a book like anyone else. but this is from what little exp I have had with jquery. $ is just another identifier character in js according the the BNF grammar (language spec), and jquery makes explicit use of that character for an identifier.

an identifier is used for things like a function or variable name.

jmichae3
02-01-2013, 07:13 AM
http://api.jquery.com/jQuery/

I think you have the case wrong. js in browsers is case sensitive on identifiers.
should be jQuery not jquery. fix that.