JQuery Questions & Answers
1) What is JQuery?
JQuery is a JavaScript Library designed to simplify DOM , It is
easy and quite good in manipulation, Ajax capabilities, CSS Animation and event
handling.
JQuery systax is designed to make programming easier on the top
of DOM and any manipulation , navigate a document, select
DOM elements, create animations, handle events.
2) What is the difference between JavaScript & JQuery?
Javascript is an language while JQuery is a JavaScript Library. Which
is written on the top of Javascript but Jquey have a many functions that makes
easy to use it and it’s a medium to interact with DOM through Javascript.
3) What is the starting point in Jquery?
JQuery starting point is $(document).ready() and it is executed
when DOM is loaded.
4) What is the difference between document.ready() and onload?
Document.ready() is executed
when DOM is loaded but onload is executed when everything gets loaded on the
page included with images and all associated resources etc.
There can have multiple
document.ready available on the page but only a single onload function gets
available.
5) What is the difference between .js and min.js?
There are two types of
versions available , one is development that is .js files and other is Production
or deployment version that is min.js and Production version is very light weighed
and small in size because of removing whitespaces and newlines. So always better
to use Production version for quick load.
6) What are the selectors and how can we use this?
As JQuery are used to work
with DOM elements so To find them in DOM, we have to use selectors
There are many types of
selectors as below
Name – Select all name
which matches particular Name
ID –To get a single
element from DOM and is used #(hash) with ID
Class –To get a group of
elements from DOM having matched class and is used .(dot) with ID
Universal-
select all element available in the DOM and used *(star)
Attribute Selector –
select elements based on attribute may
be custom or build in
7) Is JQuery Server side or client Side?
JQuey is a client side scripting.
8) What is $() in jQuery
library?
The
$() is an alias of jQuery() function, $() function is used to wrap any object into
jQuery object, which then allows you to call various method defined jQuery
object. You can even pass a selector string to $()function, and it will return
jQuery object containing an array of all matched DOM elements. I have seen this
jQuery
asked several times, despite it’s quite basic, it is used to differentiate
between developer who knows jQuery or not.
9) What is the difference between this and $(this)
this refers to DOM object but
$(this) is a JQuery wrapper so shows JQuery object.
Both this and $(this)
represents the current element in which it have. But $(this) shows extra
feature with JQuery.
10) What is CDN in JQuery?
A Content Delivery Network
(CDN) is a system of computers that exist all over the world and cache files
for users to access. Web developers can leverage the use of CDNs (and the good
graces of Google and Microsoft) to host their jQuery Library for faster access
and improved performance
There are two good options available
for CDN and its usage
·
Microsoft
<head>
<script
type="text/javascript"
src="http://ajax.microsoft.com/ajax/jquery/jquery-1.6.1.min.js"> </script>
</head>
·
Google
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
</head>
11) What is each function , how it works?
each is used to loop the
objects data and get data from it , It could be wither array or objects , lists
etc.
suppose below is a div having
ul element and , we have to get all li elements then , we can get it through
each function.
<div>
<ul>
<li>test</li>
<li>test1</li>
</ul>
</div>
$( "li" ).each(function( index ) {
console.log( index + ": " +
$(this).text() );
});