The purpose of jQuery is to make it much easier to use JavaScript on your website.
What You Should Already Know
Before you start studying jQuery, you should have a basic knowledge of:
- HTML
- CSS
- JavaScript
What is jQuery?
jQuery is a lightweight, "write less, do more", JavaScript library.
The purpose of jQuery is to make it much easier to use JavaScript on your website.
jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.
The jQuery library contains the following features:
- HTML/DOM manipulation
- CSS manipulation
- HTML event methods
- Effects and animations
- AJAX
- Utilities
Note: In addition, jQuery has plugins for almost any task out there.
Why jQuery?
There are lots of other JavaScript frameworks out there, but jQuery seems to be the most popular, and also the most extendable.
Many of the biggest companies on the Web use jQuery, such as:
Google, Microsoft, IBM, Netflix etc.
Will jQuery work in all browsers?
The jQuery team knows all about cross-browser issues, and they have written this knowledge into the jQuery library. jQuery will run exactly the same in all major browsers, including Internet Explorer 6!
Adding jQuery to Your Web Pages
There are several ways to start using jQuery on your web site. You can:
- Download the jQuery library from jQuery.com
- Include jQuery from a CDN, like Google or Microsoft or any other reliable source.
Downloading jQuery
There are two versions of jQuery available for downloading:
Production version : this is for your live website because it has been minified and compressed
Development version : this is for testing and development (uncompressed and readable code)
Both versions can be downloaded from jQuery.com.
The jQuery library is a single JavaScript file, and you reference it with the HTML.
- With jQuery you can select (query) HTML elements and perform "actions" on them.
jQuery Syntax
The jQuery syntax is tailor made for selecting HTML elements and performing some action on the element(s).
Basic syntax is: $(selector).action()
- "$" sign to define/access jQuery (Sometimes if you get error $ is not a function or It it says jQuery not defined you can use "jQuery" in place of "$" .).
- (selector) to "query (or find)" HTML elements
- jQuery action() to be performed on the element(s)
Document Ready Event
You might have noticed in many jQuery codes that all jQuery methods are inside a "document ready event" like as shown below:
$(document).ready(function(){
// Random jQuery Code.
});
It is good practice to wait for the document to be fully loaded and ready before working with it.
No comments:
Post a Comment