jQuery could be a light-weight write less do more JavaScript library

Jquery

What is jQuery?
jQuery could be a light-weight, “write less, do more”, JavaScript library.
The purpose of jQuery is to form it abundant easier to use JavaScript on your web site.
jQuery takes lots of common tasks that need several lines connected with JavaScript code to complete, and wraps all of them in strategies that you just will decision with one line of code.
jQuery conjointly simplifies lots of the sophisticated things from JavaScript, like Ajax calls and DOM manipulation.
The jQuery library contains the subsequent features:
– HTML/DOM manipulation
– CSS manipulation
– HTML event strategies
– Effects and animations
– AJAX
– Utilities
Jquery
Why jQuery?
There are uncountable alternative JavaScript frameworks out there, however jQuery appears to be the foremost widespread, and additionally the foremost long.
Many of the largest corporations on the net use jQuery, such as:
Google
Microsoft
IBM
Netflix

Adding jQuery to Your web content
There are many ways in which to start out mistreatment jQuery on your computing machine. You can:
– Downloading the jQuery library from jQuery.com
– Include jQuery from a CDN, like Google

Accessing jQuery
You will discover two variations associated with jQuery designed for downloading it:
Production variation – it is for your stay site due to the fact it is often minified as well as compressed
Development variation – it is with regard to assessment as well as advancement (uncompressed as well as understandale code)
Equally variations may be saved through jQuery. com.
The particular jQuery library is often a single JavaScript data file, and you also reference point this with all the HTML <script> point (notice that this <script> point needs to be within the <head> section):

<head>
<script src=”jquery-1.11.3.min.js”></script>
</head>

jQuery CDN
Should you not would like to get along with sponsor jQuery oneself, you can the idea coming from a CDN (Content Delivery Network).
Google along with Microsof company sponsor jQuery.
Make use of jQuery via Yahoo and google or Microsof company, make use of one of several using:

Google CDN:
<head>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js”></script>
</head>

Microsoft CDN:
<head>
<script src=”http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js”></script>
</head>

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()
– A $ sign to define/access jQuery
– A (selector) to “query (or find)” HTML elements
– A jQuery action() to be performed on the element(s)

Examples:
– $(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 Particular Document Event
It’s likely you have realized that just about all jQuery strategies in this good examples, usually are inside of a document prepared event:

$(document).ready(function(){

// jQuery methods go here…

});

This really is to avoid almost any jQuery value by operating prior to a record is completed packing (is ready).
It truly is good train to await for the record for being fully crammed and also prepared just before dealing with the item. Which lets you include your JavaScript value prior to a entire body of one’s  document , in the head portion.
Below are a few types of actions that can crash if techniques are generally function prior to a record is usually fully crammed:
Attempting to obscure an element that’s not made yet
Trying to get the dimensions of an image that’s not crammed yet.

$(function(){

// jQuery methods go here…

});

jQuery Selectors
jQuery selectors let you pick in addition to operate HTML element(s).
jQuery selectors are employed to help “find” (or select) HTML things according to their identification, classes, sorts, attributes, ideals of attributes plus much more. It really is good active CSS Selectors, and therefore, it’s got a few very own personalized selectors.
Many selectors throughout jQuery begin with the actual dollar indicator in addition to parentheses: $().

The actual element Selector
The actual jQuery element selector chooses things based on the element title.

You can select all <p> elements on a page like this:
$(“p”)

Example
When a user clicks on a button, all <p> elements will be hidden:
$(document).ready(function(){
$(“button”).click(function(){
$(“p”).hide();
});
});

The #id Selector
The particular jQuery #id selector works by using the particular identity attribute of HTML tag to get the certain factor.
The identity ought to be distinctive just a webpage, consequently you should use the particular #id selector when you wish to get a solitary, distinctive factor.
To locate an element that has a certain identity, produce a new hash persona, as well as the particular identity in the HTML factor:

$(“#test”)
When a user clicks on a button, the element with id=”test” will be hidden:

$(document).ready(function(){
$(“button”).click(function(){
$(“#test”).hide();
});
});

The .class Selector
The jQuery category selector detects aspects that has a specific  class.
To discover elements that has a specific class, write an interval character, accompanied by this brand in the category:
$(“.test”)

Example
When a user clicks on a button, the elements with class=”test” will be hidden:

$(document).ready(function(){
$(“button”).click(function(){
$(“.test”).hide();
});
});

Functions In a Separate File
If your web page consists of a lot of web pages, and you need ones jQuery functions to become all to easy to maintain, it is possible to placed ones jQuery functions inside a distinct. js file.
After we display jQuery in this course, the actual functions are added in straight into the actual <head> part. On the other hand, frequently it’s better than place them inside a distinct file, in this way (use the actual src attribute for you to make reference to the actual. js file):

Example
<head>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js”>
</script>
<script src=”my_jquery_functions.js”></script>
</head>

What are Events?
A number of differerent visitor’s actions that the web site can easily answer are generally called events
A meeting shows the actual time while one thing transpires.

Examples:
— moving a sensitive mouse more than a component
— choosing the radio button
— simply clicking a component
The word “fires/fired” is usually combined with occasions

jQuery Syntax For Event Methods
With jQuery, nearly all DOM occasions offer an comparable jQuery method.
In order to assign a simply click function to all sentences on the site, you’re able to do this:
$(“p”).click();

The next step is to help determine just what must happen once the event that will fire. You will need to pass some sort of operate towards event:
$(“p”).click(function(){
// action goes here!!
});

Commonly Used jQuery Event Methods
$(document).ready()
The $(document).ready() method allows us to execute a function when the document is fully loaded.

click()
The particular click() process connects an event handler functionality to a HTML element.
The particular functionality is actually accomplished if user click on the HTML element.
The next instance states that: If a click event shoots on a <p> element ; hide the current <p> element:
Example
$(“p”).click(function(){
$(this).hide();
});

dblclick()
The particular dblclick() method connects an event handler functionality to an HTML element.
The particular functionality  is executed when the user double-clicks on the HTML element:
Example
$(“p”).dblclick(function(){
$(this).hide();
});

mouseenter()
The particular mouseenter() methods connects an event handler functionality to an HTML element.
The particular function is executed when the mouse pointer enters the HTML element:
Example
$(“#p1”).mouseenter(function(){
alert(“You entered p1!”);
});

mouseleave()
The particular mouseleave() methods connects an event handler functionality to an HTML element.
The particular function is executed when the mouse pointer leaves the HTML element:
Example
$(“#p1”).mouseleave(function(){
alert(“Bye! You now leave p1!”);
});

mousedown()
The particular mousedown() methodsconnects an event handler functionality to an HTML element.
The particular function is executed, when the left, middle or right mouse button is pressed down, while the mouse is over the HTML element:
Example
$(“#p1”).mousedown(function(){
alert(“Mouse down over p1!”);
});

mouseup()
The particular mouseup() methods connects an event handler functionality to an HTML element.
The particular function is executed, when the left, middle or right mouse button is released, while the mouse is over the HTML element:
Example
$(“#p1”).mouseup(function(){
alert(“Mouse up over p1!”);
});

hover()
The particular hover() methods connects takes two functionality and is a combination of the mouseenter() and mouseleave() methods.
The particular first function is executed when the mouse enters the HTML element, and the second function is executed when the mouse leaves the HTML element:
Example
$(“#p1”).hover(function(){
alert(“You entered p1!”);
},
function(){
alert(“Bye! You now leave p1!”);
});

focus()
The particular focus() methods connects an event handler functionality to an HTML element.
The particular function is executed when the form field gets focus:
Example
$(“input”).focus(function(){
$(this).css(“background-color”, “#cccccc”);
});

blur()
The particular blur() methods connects an event handler functionality to an HTML element.
The particular function is executed when the form field loses focus:
Example
$(“input”).blur(function(){
$(this).css(“background-color”, “#ffffff”);
});

The on() Method
The particular  on() method connects one or more event handlers for the selected elements.
Attach a click event to a <p> element:
Example
$(“p”).on(“click”, function(){
$(this).hide();
});

Attach multiple event handlers to a <p> element:
Example
$(“p”).on({
mouseenter: function(){
$(this).css(“background-color”, “lightgray”);
},
mouseleave: function(){
$(this).css(“background-color”, “lightblue”);
},
click: function(){
$(this).css(“background-color”, “yellow”);
}
});

Content Credit :- fzmovies

Leave a Reply

Your email address will not be published. Required fields are marked *