Sunday, February 6, 2011

JQuery

JQuery is a library consists of javascript functions. It reduces the javascript codes in an application as just need to call those functions included in the library.

First need to import the library before using it in the application.
   <script type="text/javascript" src="jquery.js"></script>

The below program hides the p tags when click the button. So this uses button click event.  
<html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){   $("button").click(function(){     $("p").hide();   }); }); </script> </head> <body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Click me</button> </body> </html> 
Below are some other ways of using JQuery

$(this).hide()- hides current element
$("p").hide() - hides all paragraphs
$("p.test").hide() - hides all paragraphs withclass="test"
$("#test").hide() - hides the element withid="test"
 
$("[href]") -select all elements with an href attribute. 
$("[href='#']") select all elements with an href value equal to "#".
$("[href!='#']") select all elements with an href attribute NOT equal to "#".
$("[href$='.jpg']") select all elements with an href attribute that ends with ".jpg". the official web site - http://jquery.com/ Can learn more on http://www.w3schools.com/jquery/default.asp

1 comment:

  1. Thanks..

    This article gave to me quick step to JQuary...

    Also I heard there are some other technique to import JQuary library using google web service.

    Can you explain me that?

    ReplyDelete