Featured Article

Thursday, April 11, 2013

jQuery Syntax

Welcome back, after installing jQuery , we are ready to write our magic code, So this tutorial will help you to learn the basic syntax of jQuery which is realy the most important step when learning  any programming language.Unfortunatly , many beginners who wants to learn faster ignore this step and focus on advanced technics and complex functions , but they'll find many big problems because they don't know how this function's built and what does it mean this keyword , ...



Like any other Javascript library , jQuery was simply designed to change and interact the Html document . So , we have to understand the way that javascript could interact with Html , in other words, the DOM (Document Object Model)  .The image below represent a DOM structure for an Html document :

DOM Structure

The DOM define the way to access and manipulate Html Documents , Every node in Html can be easily accessed by Javascript and then jQuery .Don't worry , you will learn more about DOM interaction in the next tutorials .So , let's move to the  jQuery syntax.

Indeed , the process is easy to understand , jQuery access the Html or CSS elemnt using a 'Selector'  and then it perform an action .

A jQuery selector start with this symbol : $( )  ,  Inside the parentheses, we can put :

    -Html Tag name :      $('h1')   to access all the level 1 headers in the Html document.
    -Tag Class : The same way when we refer to a Html tag class in CSS using the point : . at the begin of the class name  . let's consider the following html code :

<p class = 'paragraph'></p>

to access this element using jQuery , simply add the tag class name inside the parentheses and preced it by a point :

$('.paragraph')

      -Tag Id : the same procedure for the class , just replace the point with #

<h1 id='header-1'>this is a header<h1> 

$('#header-1') 


Note : 

If you want to select all the elements in the document , just put this symbol : * inside the parentheses.
example : $('*') 
 


Friday, April 5, 2013

How to install jQuery ?

As you learned in the first tutorial , jQuery is a JavaScript library. In other words, a file extension ". Js". For use in an HTML page, you have to refer to it inside  <script> tag, preferably inside <head> like this  :

Install jQuery

The value of the src attribute is jquery.js. As you can see, the file location is not specified in the attribute. This means that it must be in the same folder as the HTML document. However, If you use the previous instruction ,the jquery Library will not be usable , There are two different solutions :   

1- If your computer is not always connected to the Internet and /or if your Internet connection is not fast, you can download jQuery to any folder and reference it locally.   

 2- If your computer is always connected to the Internet, you can reference the jQuery library, indicating a Web address.  

Let's Examine the two solutions !
 

Download jQuery locally :  

  Step1 : Go to the jQuery Official site and  Click on "Download  jQuery" Button in the Home page.
  Step2 : Choose : "Download the compressed, production jQuery 1.9.1"  , a .txt file that contain the   required code will open.  Copy and paste it into bloc note and save the file with  "jquery.js' as name in the same folder of the Html page.
  Step3 : Copy and paste the code below between <head> and  </head> :
 

All jQuery functions and Coding work must be inside the script tag. So , Now let's move to the second method to install jQuery :

Using CDN :


Using CDN (Content Management Network) , jQuery Installation become easier than downloading the library . In fact , with CDN , jQuery is hosted by Google and Microsoft , you just have to refer to it by adding a special link to your script tag .

jQuery Google CDN URL : ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
jQuery Microsoft CDN URL : ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js

Note : 
the Links Provided above refers to the 1.9.1 version of jQuery , which is the recent one so far .

So if you want to use the CDN Method then  add one of the below codes  inside the <head> tag .

Google CDN :
 


Microsoft CDN :




 
Now that we installed jQuery , Our web page is able to execute jQuery events and functions correctly , So let's move to the next tutorial.


Popular Posts

From Pinterest

Bloglog