Friday, December 3, 2010

Jquery Dollar Sign and parentheses Analaysis

Jquery often uses a Dollar sign followed by parentheses $( ).

This is the jquery factory or selector. You can use any css elements inside the parentheses to select them from the html page. Then you can apply your javascript code to those elements.

For Example:
If you click this button below the following block will be colored withe a anitmation


Now let us look at the code

$(document).ready(function(){
$('#test1').click(function(){
$('#test11').hide().css('background-color','green').slideToggle('slow');
});
});

Take a close look at the first line $(document).ready

we are using the $( ) factory to select the document and when it's ready we're executing an anonymous function. Then we are selecting #test1 div by the factory so that when it is clicked it will execute another another anonymous function.

$('#test11').hide().css('background-color','green').slideToggle('slow');
This is an example of the method chaining of jquery.  And see how easy is the jquery to use!

We shall build more advanced code from the next post.

No comments:

Post a Comment