28 Aug, 2008

Getting started with jQuery

Posted by: Mahbub In: Getting Started

I assume that we know what jQuery is. Well to brush it up, “jQuery is a javascript library that makes our life easier” . I like to define in that way. Ok, now in this post, I’m gonna show you how to get things started for jQuery. As you can read this blog, it’s obvious that you have an Internet connection and of course you’re using some browser. So let’s just try one piece of code before making the post lengthy. Before that let’s see what we need for that

  • jQuery Library (download from http://jqueryjs.googlecode.com/files/jquery-1.2.6.js) This is the current release when I’m writing the post.
  • A modern browser (IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+) with javascript enabled.
  • And a text editor (my Fav is notepad++)

I suppose we all know how does a basic html page look like. We’d just run a simple piece of code adding jQuery library
Now, just copy and paste the above code and save it calling “jquery-test.html”.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>My Jquery Playground</title>
<script src=”jquery-1.2.6.js” type=”text/javascript”></script>
<script type=”text/javascrpt”>

$(document).ready(function(){
alert(“Muhahaha”);
});

</script>
</head>
<body>
</body>
</html>

And now you can run the code by double clicking the file you have just created. Have you clicked ? and can you see the laughter (“Muhahaha”) ? If Yes, then we have just started to use jQuery.

Now I think we need little bit of an explanation of what we did in the above code.

First, we have started with a very basic html template
Secondly, we just added the jQuery javascript library using
<script type=”text/javascrpt” src=”jquery-1.2.6.js”></script>
And then we wrote a javascript block
<script type=”text/javascrpt”>
$(document).ready(function(){
alert(“Muhahaha”);
});
</script>

what did it do? well, $(document).ready(function(){ ..blah blah }); means execute “blah blah” code when page (document) loads. Perhaps writing

$(function(){
alert(“Muhahaha”);
});

would do the same thing.

EASY, huh ?

So you have just got started with jQuery. Check the other posts for little bit more fun & Magics.

For more reading, visit jquery.com site.

2 Responses to "Getting started with jQuery"

1 | sekhar

April 7th, 2009 at 4:56 am

Avatar

nice explaination

2 | Mike

June 19th, 2009 at 11:52 am

Avatar

I just became familiar with the js library “thing” and downloaded a simple menu for jQuery. Is it really this easy or am I kidding myself? I have a feeling I just stumbled upon something that is misleading in simplicity :-)

Comment Form


Translator

English flagItalian flagKorean flagChinese (Simplified) flagChinese (Traditional) flagPortuguese flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagCroatian flagDanish flagFinnish flagHindi flagPolish flagRomanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flagSlovak flagSlovenian flagUkrainian flagVietnamese flagAlbanian flagEstonian flagGalician flagMaltese flagThai flagTurkish flagHungarian flag

Tags