jQuery Syntex


How jQuery works ?

To use jQuery on a html page there are following methods:

  1. Download jQuery js file ( jquery-2.1.4.min.js ) and add this file to to html page as
     <script src="Scripts/jquery-2.1.4.min.js"></script>
  2. We can also use CDN as
     <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

jQuery syntex

All jquery code is writen inside script tag ( <script> Write jQuery code here. </script> )

jQuery start with $ ( doller ) symbol and its general syntex is as

$(selector).someMethod();

Some examples are as

  1. $('p').hide();
  2. $('p').show();
  3. $('buton').click();

The jQuery Document Ready Event

All the jQuery code is written in this event. As the name suggest this enent is fired when html page is loaded by the browser and ready for action.

Do any action before document ready may cause problem as:

  • Hide an element before it is loaded.
  • Apply the size on an element before is loaded.

There are two way to use document ready event:

  1. Old style:
     $(document).ready( function() {  // Document is ready here ...  
    }) ;
  2. New style:
     $(function(){
    	// Document is ready here ...
    });