About JQuery

By ukmodak | March 31st 2024 10:31:18 AM | viewed 884 times

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:

  1. HTML/DOM manipulation
  2. CSS manipulation
  3. HTML event methods
  4. Effects and animations
  5. AJAX
  6. Utilities

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:

  1. Google
  2. Microsoft
  3. IBM
  4. Effects and animations
  5. Netflix

How many javascript library

Most popular Javascript library are as follows:

  1. jQuery
  2. Underscore and Lodash
  3. D3.js
  4. React
  5. Glimmer

How many jquery framework

Most popular Javascript frameworks are as follows:

  1. Bootstrap
  2. Angular and AngularJS
  3. Node.js
  4. Ember.js
  5. Aurelia
  6. Vue.js

Downloading jQuery

There are two versions of jQuery available for downloading:

  1. Production version - this is for your live website because it has been minified and compressed
  2. Development version - this is for testing and development (uncompressed and readable code)

Adding jQuery to Your Web Pages

There are several ways to start using jQuery on your web site. You can:

  1. Download the jQuery library from jQuery.com
  2. Include jQuery from a CDN, like Google

The jQuery library is a single JavaScript file, and you reference it with the HTML <script > tag (notice that the <script > tag should be inside the <head > section):

<head>
    <script src="jquery-3.4.0.min.js"></script>
</head>

Can also add from Google CND

<head> <https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> </head>

Can also add from Microsoft CDN

<head> <https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.0.min.js"></script> </head>

jQuery Syntax

Basic syntax is: $(selector).action()

  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)

Example:

	$(this).hide() - hides the current element.

	$("p").hide() - hides all <p> elements.

	$(".test").hide() - hides all elements with class="test".

	$("#test").hide() - hides the element with id="test".

The Document Ready Event

You might have noticed that all jQuery methods in our examples, are inside a document ready event:

$(document).ready(function(){
  // jQuery methods go here...
}); 

This is to prevent any jQuery code from running before the document is finished loading (is ready)

It is good practice to wait for the document to be fully loaded and ready before working with it. This also allows you to have your JavaScript code before the body of your document, in the head section.

Here are some examples of actions that can fail if methods are run before the document is fully loaded:

  • Trying to hide an element that is not created yet
  • Trying to get the size of an image that is not loaded yet

The jQuery team has also created an even shorter method for the document ready event:

$(function(){

  // jQuery methods go here...

}); 
bONEandALL
Visitor

Total : 20975

Today :29

Today Visit Country :

  • Germany
  • United States
  • Singapore
  • China
  • United Kingdom
  • South Korea
  • Czechia