9lessons programming blog
Loading Search
Wednesday, October 28, 2009

Jquery Basics Series -1

Hi Friends, if you really want to learn jQuery follow basic series on 9lessons. Jquery is an awesome javascipt library, it’s help you for developing dazing web projects.

In this tutorial I want to discuss very basic level jquery and working with Click() event.

Jquery Basics Series

How to add jQuery to your website

Installing
You can download jquery.js file form jquery.com.
<script type="text/javascript" src="jquery.js"></script>
OR
Recommended
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js
"></script>

Jquery Code
Generally used script run this when the HTML is all ready.  Live Demo
<script type="text/javascript">
$(document).ready(function()
{
alert('Welcome 9lessons Jquery Basic Series');
});
</script>

Similar as previous script. Take a look at Live Demo
<script type="text/javascript">
$(function()
{
alert('Welcome 9lessons Jquery Basic Series');
});
</script>

Run this when the whole page has been downloaded. Take a look at Live Demo
<script type="text/javascript">
$(window).load(function()
{
alert('Loaded Whole Page including images)');
});
</script>



jQuery Stucture
Here $ = jquery, selector is a DOM element and function execute a jquery fuction.
$(selector).function(parameters);

DOM - Document Object Model Wiki

Selectors

-> Select DOM elements eg: $('h1') ,$('div'), $('li')..
-> Select ID : $('#id_name')
-> Select Class : $('.class_name')

Working with Click() Event
Structure $(selector).click(). Take a look at Live Demo
<script type="text/javascript">
$(function()
{

$('#button_action').click(function()
{
alert('Hey Button');
});

$('.link_action').click(function()
{
alert('Hey Link');
});

});
</script>
<body>
<include type='button' value='BUTTON' id='button_action'/>
<a href='#' class='link_action'>LINK</a>
</body>

Hide and Show With Click Event
Hiding and Showing the div tag. Take a look at Live Demo
<script type="text/javascript">
$(function()
{

$('.hide_box').click(function()
{
$('#box').hide();
});

$('.show_box').click(function()
{
$('#box').show();
});

});
</script>
<body>
<a href="#" class="hide_box">HIDE</a>
<a href="#" class="show_box">SHOW</a>
<div id="box"></div>
</body>

Related Links about Click Event
Magical Sign-up Page with jQuery and CSS.
How to Implement an Animation Effect Website with jQuery
Facebook like suggestions with jQuery content appears and disappears.
Sponsored Links

Share this post

Comments
{ 20 comments }
himanshugpt said...

Well this was a good to start with.... easy and catching..

Himanshu
http://himanshugpt.wordpress.com/

Srinivas Tamada said...

@himanshugpt

Thank You

Elijah Manor said...

Nice introduction!

Next time maybe could format code snippets a little more (indentation). Personally, I use SyntaxHighlighter (http://j.mp/15xmoF)

Also, you might consider hosting your examples on JsBin (http://jsbin.com) to share w/ others and enable them to modify, play, tweak w/ your examples.

papyromancer said...

This is great. I'm just learning Javascript, and I've been trying to start with jQuery to learn how js libraries are handled.

This kicked me in the right. There's a lot of good info here for a 5 minute read :D

Lemein said...

Hi timothy here, your greatest fan
now can you have the same link hiding and showing an element at the same time, after it is clicked for the first time it shows an element, after it is clicke for the second tme, it hides the element

Srinivas Tamada said...

@Lemein

Thank you! I had given basic example about Click() element. I will discuss more about Click() on basics series 2

Ravikumar Tamada said...

Thanx my brother, it was a good intro... i am waiting for basic series 2 [:-)]

Lemein said...

Thanx. I realised you can use the toggle()function to accomplish wat i wanted. Thanx and continue to keep us posted

පහන් said...

thank you. Its very helpful. I am one of your RSS subscribers. keep it up.

Srinivas Tamada said...

Thank You Pahan

diknowstech said...

Thank you, Nice Tutorial.

khel said...

thanks for the tutorial very straight forward

Nanzy said...

hi dude if u know about some php so plz make login and registration form for me ?

i know every one is want money but like as a friend can u make it ?

I'm From Pakistan
my e-mail : rlucky35@yahoo.com thnx

Hardik Shah [Guru] said...

For an HTML element like the following :

Hello

Can I use $("div1") .. ? Are double quotes allowed .. ?

------------------------------------------

Also when in an "external .js file" I have :

function abc()
{
var a;
}

Does 'a' become a global variable .. ?

sahayarex said...

Its an excellent post to start learning jquery...
keep doing this good job....

Anonymous said...

very nice...

Srinivas Tamada said...

@Hardik Shah

jquery DOM elements

$(body), $(img) etc

$("#idname")

$(".classname")

tangy urchins said...

thanks Good

raj shah said...

jquery making me loving it...

Anonymous said...

It's a good post for beginners to jquery, Thanks for post.

Post a Comment

Subscribe now!Recent Posts

Categories

Subscribe now!Popular Posts

People Says

@9lessons thank you for the great tutorials, we truly appreciate your contributions to the design community.

Smashing Magazine

Like Me

follow me
products

9lessons labs

9lessons clouds

Android application

Chrome Extension