So what exactly is jQuery? jQuery is a concise JavaScript library. The developers state that jQuery aims to change the way we write JavaScript. I like to think of jQuery as a tool that allows us to simplify JavaScript code. This “Getting Started Guide” is intended as a quick introduction to jQuery - mainly for website designers.
Document Ready?
Say you have a simple function. To execute the function, you must specify an action. For example:
<a href="#" onload="aFunction();">Hello World!</a>
The function, “aFunction”, is executed when the page loads. Similarly, you can apply the “onclick” event to element. This allows you to execute a single function when that element is clicked. It is important to note that you can only apply 1 (a single) function to events such as onclick, onload etc.
jQuery allows us to easily execute multiple functions when events are triggered. Say, for example, that you wanted to assign a value to a variable when the DOM (document) has loaded. To assign a value to a variable using JavaScript, we can write:
var variableName = "variable value"
To have this value assigned when the document has loaded, we can place the code within the $(document).ready() function:
$(document).ready(function() { var variableName = 'variable value'; });
You may also see this written as:
$(function() { var variableName = 'variable value'; });
This is really just shorthand notation. Use whichever you feel comfortable with.
How About Other Events?
Say we have a simple element on our page:
<span id="someID">Some Text</span>
How do we use jQuery to perform action(s) when the link is clicked? Well, we could use the “click” event:
$("#someID").click(function() { alert("Hello World!"); });
We can see that the “click” action causes the defined function to be executed when elements, that have id=”someID”, are clicked. Hence, the following code is executed at the click of a button:
alert("Hello World!");
This is the “alert” function. The “alert” function displays a defined message (in this case ‘Hello World!’) when executed. We can see this code in action: demonstration page.
Other events include “blur”, “change”, “dblclick”, “focus”, “hover” etc. You can find an extensive list of events at Visual jQuery.
CSS Manipulation
You can manipulate an element’s CSS attributes using jQuery. Hopefully you can see where this is going… Using an event (e.g. click), it is possible to manipulate any element. Let’s continue with the previous example:
<span id="someID">Some Text</span>
We could change the color of the text when that text is clicked:
$("#someID").click(function() { $("#someID").css("color","red"); });
As before, we insert the code we want to be executed inside the “click” function. However, this time I introduce to you jQuery’s CSS manipulation abilities. The syntax follows:
$("#someID").css("CSS-attribute-name", "CSS-attribute-value");
Note: Instead of selecting element(s) to be manipulated by their ID, we could select by class. To select elements by their classes, we would use “.className” instead of “#someID”.
Here is a demonstration page.
jQuery Tutorial Summary
Hopefully, after reading this tutorial, you can see how useful jQuery is as a scripting tool. The purpose of this tutorial was to introduce you to some of jQuery’s basic features. Stay tuned for more ![]()

June 3, 2008
Quote
GREAT article! I learned alot! You wrote it so simple. Many of the jQuery beginner articles I have seen in the past seem to jump all over the place and can’t seem to explain it in a logical manner. You got it down though!
Again, thanks for the taking the time to write this. You helped me out.
June 27, 2008
Quote
Yeah, great article, thanks!
July 12, 2008
Quote
I agree, great article.
My only query, when changing the color of the text to red, as in
There is nothing on the page that prompts the user to click. I missed it three times.
Just a thought.
Jim
July 12, 2008
Quote
Hi Jim!
I wanted to keep things really simple. The purpose of this article is really to introduce the basic functions and syntax. A note should probably be added to the demo page instructing visitors to click the text to trigger the event.
Thanks for your feedback. It is much appreciated.
July 12, 2008
Quote
Does jquery work if the page is tested locally (i.e. not loaded to a server)?
I copied the code to my own file, saved it as a html - nothing added, then when I clicked, the text remained unchanged.
July 12, 2008
Quote
It should work locally. Check to make sure that you are correctly including the jQuery library in the head section of your page:
You will need to first download the library though: http://jquery.com/
July 14, 2008
Quote
Hi Homar:
Sorry for my confusion. What jquery.js do I need? I went to jquery.com, it lists the following:
Download jQuery
Download jQuery 1.2.6 (16kb, Minified and Gzipped) Great for production use.
Download jQuery 1.2.6 (97kb, Uncompressed) Great for testing, learning and development.
Download jQuery 1.2.6 (30kb, Packed) For those that can’t Gzip their JavaScript.
jQuery 1.2.6 Release Notes What was changed in the release.
None of which I can see in the html source code.
July 14, 2008
Quote
Hi Jim!
Any of those will do (except for the release notes). Generally, people choose the release with the smallest file size for production. The Minified and Gzipped version is good!
July 15, 2008
Quote
Got it thanks.
Now onto the project that lead me here initially. - Text re-sizing.
October 30, 2008
Quote
Really simple article, easy to understand. Thanks a ton.
December 3, 2008
Quote
jQuery solved some major frustrations for me ( and yes, jQuery is easy too ) :
I discovered the joys of using jQuery a few months ago and found I was able to use to enhance my flash based web site very elegantly.
Flash content is pretty much invisible to search engines, although Google and others claim otherwise. This puts Flash based sites at an SEO disadvantage and really burdens the web page designer with the task of generating duplicate, text only content that is simply there for keyword indexing ( although it does help with visitors who don’t have flash and with screen reading software for the visually impaired ).
I took some of my web site navigation out of my flash movie and rebuilt it using jQuery inline links. ( jQuery does such smooth transitions that it almost looks like flash anyway ). Fortunately, flash 8 now has an External Interface Class that permits robust communication between javascript on a web page and its embedded swf ( flash ) movie file.
I can invoke Actionscript functions within the flash movie ( with parameters ) and controll my movie very efficiently. Yes, still have to build external content files but I like the way jQuery grabs text from other files ( written within specific div id’s ) that even my non-flash pages have nice interactive features that mimic some of the flash.
There something very elegant about jQuery in the way it manages the messy DOM scripting related chores and frees you up to work more on creative, design related work.
I know purists dismiss it to the extent that it hides so much of the DOM that a coder doesn’t really learn the internals of Javascript and DOM scripting but the end result if much nicer effects and less headaches while coding.
John
Redesigned Flash Site using jQuery :
http://www.coolvegasmap.com
June 5, 2009
Quote
thanks for the article.
@Homar I would suggest loading jquery from Google CDN.
June 25, 2009
Quote
Thank u very much.Really it is a very simple article for beginner to start JQuery.
June 25, 2009
Quote
Thank u very much.Really it is a very simple article for beginner to start JQuery.