jQUERY
INTERVIEW QUESTIONS :
Q1. What is jQuery?
jQuery is a JavaScript library that simplifies
JavaScript and AJAX programming. JavaScript is used to add interactivity and
dynamic content to web pages. AJAX (Asynchronous JavaScript and XML) is used
for handling external data asynchronously through JavaScript, without
refreshing the whole page.
jQuery emphasizes the interaction between
JavaScript and HTML. jQuery contains all the common DOM, event, effects, and
Ajax functions in a single JavaScript file.
The jQuery file needs to be included in the file
which is going to use the jQuery functionality.
jQuery provides a new class called jQuery
without extending the built-in JavScript classes which acts as a wrapper around
objects for providing them the extended operations.
Q2. Advantages of jQuery?
The advantages of using
jQuery are:
JavaScript
enhancement without the overhead of learning new syntax
Ability to
keep the code simple, clear, readable and reusable
Eradication
of the requirement of writing repetitious and complex loops and DOM scripting
library calls
Q3. Explain the features of jQuery.?
Features of jQuery are :
Effects and
animations
Ajax
Extensibility
DOM element
selections functions
Events
CSS
manipulation
Utilities -
such as browser version and the each function.
JavaScript
Plugins
DOM
traversal and modification.
Q4. Explain the concepts of "$ function" in
jQuery with an example.?
The type of
a function is "function".
There are a lot of anonymous functions is
jquery.
$(document).ready(function()
{});
$("a").click(function() {});
$.ajax({
url: "someurl.php",
success: function() {}
});
Q5. Why is jQuery better than javascript?
jQuery is
great library for developing ajax based application.
It helps the
programmers to keep code simple and concise and reusable.
jQuery
library simplifies the process of traversal of HTML DOM tree.
jQuery can
also handle events, perform animation, and add the ajax support in web
applications.
Q6. Explain how jQuery Works.?
<html>
<head>
<script type="text/javascript"
src="jquery.js"></script>
<script
type="text/javascript">
// You can write the code here
</script>
</head>
<body>
<a
href="http://careerride.com/">CareerRide</a>
</body>
</html>
Q7. When can you use jQuery?
jQuery can be used to
for developing ajax based applications
It can be used to keep the code simple, concise
and reusable.
It simplifies the
process of traversal of HTML DOM tree.
It can also handle events, perform
animation, and add the ajax support in web applications.
Q8. What does dollar sign($) means in Jquery?
Dollar sign is nothing but it's an alias for Jquery. Take a look at below jquery code
$(document).ready(function(){
});
Over here $ sign can be replaced with
"jQuery " keyword.
jQuery(document).ready(function(){
});
Q9. How is body onload() function is defferent from
document.ready() functon used in Jquery?
Document.ready()
function is different from body onload() function because off 2 reasons.
1. We can have more than one document.ready() function in a page
where we can have only
one onload function.
2. Document.ready() function is called as
soon as DOM is loaded where body.onload()
function is called when everything gets loaded on the
page that includes DOM, images and
all associated resources of the page.
Q10. What is Jquery UI?
JQuery
UI is a library which is built on top of JQuery library. JQuery UI comes with
cool widgets, effects and
interaction mechanism.
See below page on this site. Date Picker control
used in this page to select date is an example
of JQuery UI.
Q11. Name some of the methods of Jquery used to provide
effects?
Some
of the common methods are :
1. Show()
2.
Hide()
3. Toggle()
4. FadeIn()
5. FadeOut()
Q12. what are the different type of selectors in Jquery?
There
are 3 types of selectors in Jquery
1. CSS Selector
2. XPath Selector
3. Custom Selector
Q13. How can you select all elements in a page using
Jquery?
<script
language="javascript" type="text/javascript">
$("*").css("border",
"2px dotted red");
</script>
Q14. How can you select all elements in a page using
jQuery?
To
select all elements in a page, we can use all selectors, for that we need to
use *(asterisk symbol).
<script language="javascript"
type="text/javascript">
$("*").css("border",
"2px dotted red");
</script>
The above code
will select all elements of the web page and apply border width as 2 pixel,
style as dotted and color as red.
Q15. What is the Difference between Jquery-X.X.X.js and
Jquery.X.X.X-min.js?
In terms of
functionality, there is no difference between the jQuery-x.x.x.js and
jQuery-x.x.x-min.js (also called minified version). However this can play a
vital role in the performance of the web page.
Q16. How it affects the performance?
jQuery-1.4.4.js
file size is 178 KB as against its minified version jQuery-1.4.4-min.js that is
only 76.7 KB in size. So when your page loads in the client?s browser if you
are not using minified version, it loads 178 KB file that takes more time to
load than 76.7 KB.
Q17. What is CDN?
CDN Stands for Content Distribution Network or also called Content Despan style=livery Network is a group of computers placed at various points
connected with network containing copies of data files to maximize bandwidth in
accessing the data. In CDN a client access a copy of data nearer to the client
location rather than all clients accessing
from the one
particular server. This helps to achieve better performance of data retrieval
by client.
There are two
leading CDNs available that hosts jQuery files.
Microsoft - To load jQuery from Microsoft AJAX CDN
jQuery file can be
loaded from Microsoft AJAX CDN. For more details, go to
http://www.asp.net/ajaxlibrary/cdn.ashx.
You will need to keep following
tags in your page.
<script
type="text/javascript" language="Javascript"
src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js"></script>
Google - To load jQuery from Google Libraries API
jQuery file can be
loaded from Google CDN for more details, go to
http://code.google.com/apis/libraries/devguide.html. You will need to keep
following tag in your page.
<script
type="text/javascript" language="Javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
What’s relationship
between JavaScript and ECMAScript? - ECMAScript is yet another name for
JavaScript (other names
include LiveScript). The current JavaScript that you see supported in browsers
is ECMAScript revision 3.
Q18. What are JavaScript types?
Number, String,
Boolean, Function, Object, Null, Undefined
Q19. How do you convert numbers between different bases
in JavaScript?
Use the parseInt()
function, that takes a string as the first parameter, and the base as a second
parameter. So to convert hexadecimal 3F to decimal, use parseInt
("3F", 16);
Q20. What does isNaN function do?
Return true if the
argument is not a number.
Q21. What is negative infinity?
It’s a number in
JavaScript, derived by dividing negative number by zero.
What boolean operators
does JavaScript support?
&&, || and !
Q22. What does "1"+2+4 evaluate to?
Since 1 is a string,
everything is a string, so the result is 124.
Q23. How about 2+5+"8"?
Since 2 and 5 are
integers, this is number arithmetic, since 8 is a string, it’s concatenation,
so 78 is the result.
Q24. What looping structures are there in JavaScript?
for, while,
do-while loops, but no foreach.
Q25. How do you create a new object in JavaScript?
var obj = new Object();
or var obj = {};
Q26. How do you assign object properties?
obj["age"] =
17 or obj.age = 17.
Q27. What’s a way to append a value to an array?
arr[arr.length] = value;
Q28. What is this keyword?
It refers to the
current object.
Is jQuery a library for
client scripting or server scripting?
Client scripting
Q29. Is jQuery a W3C standard?
No
Q30. What are jQuery Selectors?
Selectors are used in
jQuery to find out DOM elements. Selectors can find the elements via ID, CSS,
Element name and hierarchical position of the element.
Q31. The jQuery html() method works for both HTML and
XML documents?
It only works for HTML.
Q32. Which sign does jQuery use as a shortcut for
jQuery?
$(dollar) sign.
Q33. What does $("div") will select?
It will select all
the div element in the page.
Q34. What does $("div.parent") will select?
All the div
element with parent class.
Q35. What is the name of jQuery method used for an
asynchronous HTTP request?
jQuery.ajax()
Q36. What is Jquery?
JQuery is Java Script
library or Java Script Framework which helps in how to traverse HTML documents,
do some cool animations, and add Ajax interaction to any web page. It mainly
helps programmer to reduce lines of code as huge code written in Java Script,
can be done easily with JQuery in few lines.
Q37. What does dollar Sign ($) means in JQuery?
Dollar Sign is nothing
but it's an alias for JQuery. Take a look at below jQuery code
$(document).ready(function(){
});
Over here $ sign can be
replaced with "jQuery " keyword.
jQuery(document).ready(function(){
});
Q38. How is body onload() function is different from
document.ready() function used in jQuery?
Document.ready()
function is different from body onload() function because off 2 reasons.
1. We can have more than
one document.ready() function in a page where we can have only one onload
function.
2. Document.ready()
function is called as soon as DOM is loaded where body.onload() function is
called when everything gets loaded on the page that includes DOM, images and
all associated resources of the page.
Click below link to get
mostly asked jQuery interview question.
http://jquerybyexample.blogspot.com/2011/08/mostly-asked-jquery-interview-questions.html
Q39. What are the steps you need to follow to use
jQuery in ASP.Net project?
It's really simple. One
just need to add reference of javascript file(.js). Go to Jquery.com and
download the latest version of jQuery. When download is completed, there is a
"jQuery-1.3.2.js" in the folder. Include this file
<script
src="_scripts/jQuery-1.3.2.js"
type="text/javascript"></script>
and you good to go now
for JQuery.
Note : 1.3.2 denotes the
library version.. It can be vary depending upon the version of Jquery you
download.
Q40. What is JQuery UI?
JQuery UI is a library
which is built on top of JQuery library. JQuery UI comes with cool widgets,
effects and interaction mechanism.
See below page on this
site. Date Picker control used in this page to select date is an example of
JQuery UI.
Q41. What are features of JQuery or what can be done
using JQuery?
Features of Jquery
1. One can easily
provide effects and can do animations.
2. Applying / Changing
CSS.
3. Cool plugins.
4. Ajax support
5. DOM selection events
6. Event Handling
Q42. Name some of the methods of JQuery used to provide
effects?
1. Show()
2. Hide()
3. Toggle()
4. FadeIn()
5. FadeOut()
Q43. What are the different type of selectors in Jquery?
There are 3 types
of selectors in Jquery
1. CSS Selector
2. XPath Selector
3. Custom Selector
Q44. What are the advantages of JQuery ?
There are many
advantages with JQuery. Some of them are :
. It is more like a
JavaScript enhancement so there is no overhead in learning a new syntax.
. It has the ability to
keep the code simple, readable, clear and reusable.
. It would eradicate the
requirement for writing complex loops and DOM scripting library calls.
Q45. How can you select all elements in a page using
jQuery?
To select all elements
in a page, we can use all selectors, for that we need to use *(asterisk
symbol).
<script
language="javascript" type="text/javascript">
$("*").css("border",
"2px dotted red");
</script>
The above code will
select all elements of the web page and apply border width as 2 pixel, style as
dotted and color as red.
Q46. What is jQuery?
jQuery is not a language
but it is a well written JavaScript code, As quoted on official jQuery website
“it is a fast and concise JavaScript Library that simplifies HTML document
traversing, event handling, animating, and Ajax interactions for rapid web
development.“
In order to work with
jQuery you should be aware of basics of JavaScript, HTML and CSS.
It was released in
January 2006 at BarCamp NYC by John Resig.
Licensing:
It is free, open source
software Dual-licensed under the MIT License and the GNU General Public
License. Microsoft has integrated jQuery officially into its IDE Visual Studio 2010
and jQuery intellisense is available in Visual Studio 2010 now.
Q47. Why jQuery?
jQuery is very compact
and well written JavaScript code that increases the productivity of the
developer by enabling them to achieve critical UI functionality by writing very
less amount of code.
It helps to
# Improve the
performance of the application
# Develop most
browser compatible web page
# Implement UI
related critical functionality without writing hundreds of lines of codes
# Fast
# Extensible – jQuery
can be extended to implement customized behavior
Other advantages of
jQuery are
# No need to learn
fresh new syntax's to use jQuery, knowing simple JavaScript syntax is enough
# Simple and
Cleaner code, no need to write several lines of codes to achieve complex
functionality.
Q48. Where to download jQuery from?
http://www.jquery.com/
Q49. How to use jQuery?
jQuery usually comes as
a single JavaScript file containing everything comes out of the box with
jQuery. It can be included within a web page using the following mark-up:
To load local jQuery
file
<script
type="text/javascript"
src="jQuery-1.4.1-min.js"></script>
Q50. Do I need to refer jQuery file both in Master
page/base page/template page and content page?
No, master page/base
page/ template page basically helps to create consistent layout for the page in
the application. In case you have referred the jQuery file in master page/base
page/ template page that cause rendering the file in the browser, you do not need
to refer jQuery file the content page again.
In summary, there should
not be more than one <script> tag with jQuery file reference in the
source code of the rendered web page in the browser.
Q51. What is the difference between jQuery-x.x.x.js and
jQuery.x.x.x-min.js” ?
In terms of
functionality, there is no difference between the jQuery-x.x.x.js and
jQuery-x.x.x-min.js (also called minified version). However this can play a
vital role in the performance of the web page.
Q52. How it affects the performance?
jQuery-1.4.4.js file
size is 178 KB as against its minified version jQuery-1.4.4-min.js that is only
76.7 KB in size. So when your page loads in the client?s browser if you are not
using minified version, it loads 178 KB file that takes more time to load than
76.7 KB.
Q53. Which version of jQuery file should be used?
In most of the recent
releases so far, the core functionality of jQuery remains same however some
more cool and better features are added. Ideally you should use the latest
jQuery files available on the jQuery.com website. By doing this you ensure that
your earlier functionality will still work and you can use new features
available as part of the new release.
Q54. What is CDN?
CDN Stands for Content
Distribution Network or also called Content Delivery Network is a group of
computers placed at various points connected with network containing copies of
data files to maximize bandwidth in accessing the data. In CDN a client access
a copy of data nearer to the client location rather than all clients accessing
from the one particular
server. This helps to achieve better performance of data retrieval by client.
There are two leading
CDNs available that hosts jQuery files.
Microsoft - To
load jQuery from Microsoft AJAX CDN
jQuery file can be
loaded from Microsoft AJAX CDN. For more details, go to
http://www.asp.net/ajaxlibrary/cdn.ashx. You will need to keep following tags
in your page.
<script
type="text/javascript" language="Javascript"
src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js"></script>
Google - To load jQuery
from Google Libraries API
jQuery file can be
loaded from Google CDN for more details, go to
http://code.google.com/apis/libraries/devguide.html. You will need to keep
following tag in your page.
<script
type="text/javascript" language="Javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
Q55. Why to load jQuery file from CDN?
You may ask that if we
can load the jQuery file from our own server why to load it from the CDNs. The
answer is logical and very simple. The browser behavior is that whenever it
loads any webpage, it keeps related files (eg. Javascript file, CSS file and
Images) used for that page into its cache (also called history). When next time
the user browses any web page, browser loads only those files that are new or
modified and is not available in the browser cache or history. In this way,
browser improves its performance and loads the page.
The possibility is that
if more and more websites are using CDNs, the user might have already browsed
some other web pages that is using CDNs jQuery file and that file may have into
browser cache; so when user browse your page and you are also using CDNs file,
the older cached version of jQuery file will be used. In this way your page
will load faster as browser will not have to load the jQuery file for your page
again.
The benefit
1. Faster page
load as jQuery file need not to be downloaded
2. Saves your
bandwidth as jQuery file is not loaded from your server
3. Scalable -
generally CDNs place these files on the servers located at different
geographical locations of the world so that they load faster so irrespective of
from where your user is browsing your page, your application runs well.
Q56. What if the latest jQuery version is available and
I am still referring older version of jQuery file from CDNs?
Do not worry about it,
it?s a general promise made by CDNs that they will remain hosting the older
version of the files on the same location where they had initially released; so
even if newer version of the files are released, the older version remains
there on the CDNs and your web page still works.
Q57. How to load local jQuery file in case CDN is not
available?
Sometimes, it may happen
that the CDN you have used to load the jQuery file is not available (it rarely
happens, however anything is possible, isn?t it?); in that case you should load
your local jQuery file that is available on your server so that all jQuery related
functionality still work on your page.
Write following
lines of code
<!-- START -
jQuery Reference -->
<script
type="text/javascript" language="Javascript"
src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js
"></script>
<script type='text/javascript'>//<![CDATA[
if (typeof jQuery ==
'undefined') {
document.write(unescape("%3Cscript
src='/Script/jquery-1.4.1.min.js' type='text/javascript'
%3E%3C/script%3E"));
}//]]>
</script>
<!-- END - jQuery
Reference -->
Replace bolded path with
your own jQuery file path on the server. In the above code, first line tries to
load the jQuery file from CDN, if browser could load the file successfully,
“jQuery” variable will ndiv class=ot be undefined and next script will not run
otherwise next script will run that will write the script tag to load the
jQuery file from your server.
Q58. How to execute jQuery code?
1. As and when page loads, execute the jQuery code
<script
language="javascript" type="text/javascript">
$(function () {
$("#div1").css("border",
"2px solid green");
});
</script>
OR
<script language="javascript"
type="text/javascript">
$("#div1").css("border",
"2px solid green");
</script>
The benefit of executing
jQuery code in this way is that it doesn?t wait the whole page to load
completely, so in case you want user to see the effects as soon as the
corresponding elements are loaded, you can use this.
However the disadvantage
is that if the element on which jQuery has to execute has not loaded then it
will error out or you will not get desired result; so while using this way of
executing jQuery code, you will have to make sure that the element on which you
want to work with jQuery is loaded first (you can place your jQuery code right
after your HTML element).
Q59. . Execute jQuery only when the complete DOM
objects (the complete page has been loaded). You will have to wrap your code in
.ready function.
<script
language="javascript" type="text/javascript">
$(document).ready(function () {
$("#div1").css("border",
"2px solid green");
});
</script>
This is the better
and safer way to execute jQuery. This makes sure that jQuery code will execute only
if complete page has been loaded in the browser so you are rest assured that
user will not see any undesired behavior on the page.
As a developer, the
decision of where and how to write jQuery code lies on you. I prefer to use 2nd
method as it ensures that my complete page is loaded in the browser and I am
ready to play with any element available on the page.
jQuery Core
jQuery accepts a string
enclosed with double quote (“”) that can contain a CSS selector which is used
to match a set of elements ospan class
=n the web page.
=n the web page.
jQuery code can start
with either “jQuery” word or a “$” (dollar symbol). Take a look at below code
snippet
<script
language="javascript" type="text/javascript">
$(function () {
jQuery("#div1").css("border",
"2px solid red");
});
</script>
OR
<script
language="javascript" type="text/javascript">
$(function () {
$("#div1").css("border",
"2px solid green");
});
</script>
Both above code snippets
are functionally same and do the same thing. So you can either user jQuery or $
when you are writing jQuery code.
Q60. How to give alert message in jQuery on a Button
Click ?
Hi all,
First, include
jQuery in your application.
Drop a textbox in your
.aspx page:-
<input
id="inputField" type="text" size="12"/>
include a button also:-
<asp:Button
ID="Button1" runat="server" Text="get"/>
Now, here's the script:-
<script
type="text/javascript">
$(document).ready(function () {
$('#Button1').click(function () {
alert($('#inputField').attr("value"));
});
});
</script>
Q61. What are Selectors in jQuery mean ?
Generally in HTML, if we
need to work with any control on a web page we need to find the control. For
that we use document.getElementByID or document.getElementByName. But in jquery
we do it using Selectors.
Using this selectors we
can select all the controls as well using a symbol (* )
A sample code snippet
can be of this form
<script
language="javascript" type="text/javascript">
$("*").css("border",
"10px red");
</script>
This will make all the
borders in the web page with a width of 10 pixel and color as red.
Q62. Is it good to load
jquery from CDN(Content delivery network) ?
Yes, it is always good
to load your jquery from content delivery network. It provides some benefits
like :-
(1) Caching - It means
that if any previously visited site by user is using jQuery from Google CDN
then the cached version will be used. It will not be downloaded again.
(2) Reduces load - It
reduces the load on your web server as it downloads from Google server's.
Example :-
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
Q63. Do we need to add the JQuery file both at the
Master page and Content page as well?
No, if the Jquery file
has been added to the master page then we can access the content page directly without
adding any reference to it.
This can be done using
this simple example
<script
type="text/javascript"
src="jQuery-1.4.1-min.js"></script>
Q64. What is the advantage of using the minified
version of JQuery rather than using the conventional one?
The advantage of
using a minified version of JQuery file is Efficiency of the web page
increases.
The normal version
jQuery-x.x.x.js has a file size of 178KB
but the minified version
jQuery.x.x.x-min.js has 76.7 KB.
The reduction in size
makes the page to load more faster than you use a conventional jQuery file with
178KB
Q65. What is CDN and how jQuery is related to it?
CDN - It stands
for Content Distribution Network or Content Delivery Network.
Generally, a group of
systems at various places connected to transfer data files between them to
increase its bandwidth while accessing data. The typical architecture is
designed in such a way that a client access a file copy from its nearest client
rather than accessing it from a centralized server.
So we can load this
jQuery file from that CDN so that the efficiency of all the clients working
under that network will be increased.
Example :
We can load jQuery from
Google libraries API
<script
type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
Q66. Can we select a element having a specific class in
jQuery ?
Yes, we can select an
element with a specific class, we use the class selector.The class name must
contain the prefix as "." (dot).
<script
language="javascript" type="text/javascript">
$(".class1").css("border",
"2px solid red");
</script>
Above code will select
all the elements of the webpage containing the class as "class1" and apply
the css style border width as 2 Pixel, style as solid and color as red.
Q67. What is the use of Delegate() Method in jQuery?
The delegate() method
can be used in two ways.
1) If you have a parent
element, and you want to attach an event to each one of its child elements,
this delegate() method is used.
Ex:Un-ordered List
Instead of attaching an
event to each <li> element, you can attach a single event to <ul>
element.
Example:
$("ul").delegate("li",
"click", function(){
$(this).hide();
});
2) When an element is
not available on the current page, this method is used.
.live() method is also
used for the same purpose but, delegate() method is a bit faster.
Example:
$("ul").delegate("li",
"click", function(){
$(this).hide();
});
This will hide any list
items that are not currently available on the page. They may be loaded via an
Ajax request and then append to it.
Using .bind() or
.click() methods, you would have to manually attach events to these new list
items once they are added.
Q68. Which sign does jQuery use as a shortcut for
jQuery?
NOTE: This is objective
type question, Please click question title for correct answer.
Q69. JQuery is a client scripting.
NOTE: This is objective
type question, Please click question title for correct answer.
Q70. Can be used JQuery with AJAX?
NOTE: This is objective
type question, Please click question title for correct answer.
Q71. JQuery is JavaScript Library or JSON Library?
JQuery is a javascript
library not JSON Library. Jquery library is single JavaScript file that
contains Common DOM, event effects and Ajax functions.
"JQuery is a
library of javascript function."
For more Info:
http://jquery.com/
What does .size() method
of jquery return ?
Posted by: Akiii
.size() method of jquery
returns number of element in the object. That means that you can count the
number of elements within an object.
For example :-
$(document).ready(function(){
var Count =
$("div").size();
alert(Count);
});
Q72. What is the difference between jquery.size() and
jquery.length ?
jquery.size() and
jquery.length both returns the number of element found in the object. But,
jquery.length is faster than jquery.size() because size() is a method but
length is a property .
So, there is always an
overhead in calling a function.
Q73. How to set Page Title using jQuery ?
$(function(){
$(document).attr("title", "Dotnet
Funda");
});
Q74. How will you Encode/Decode URL in jQuery ?
In jquery, you can use
the following functions to encode and decode url :-
encodeURIComponent(url)
and decodeURIComponent(url)
You have to pass the
complete url with parameterized value in the function and in return it will
encode/decode you url for you !
Q75. What is the use of jQuery Connect?
It is used to connect or
bind a function to another function.It is use to execute a function whenever
a function from another
object is executed.
e.g.
function
FirstFunction(){
this.Func1 = function(){
execute1 = 'A class';
}
}
var firstFunc = new
FirstFunction();
function
SecondFunction(){
this.Func2 =
function(){
execute2 =
'Another Class';
}
}
var secondFunc = new
SecondFunction();
$.connect(firstFunc,'Func1',secondFunc,Func2);
In this case whevever we
invoke secondFunc.Func2,firstFunc.Func1 will also gets executed indicating that
Func2 of object
secondFunc has been associated/ connected to Func1 of object firstFunc
Q76. What is the use of jQuery disconnect?
It is used to disconnect
a function to another function.It is the opposite of $.connect.
e.g.
$.disconnect(firstFunc,'Func1',secondFunc,Func2);
will disconnect Func1
from Func2 where Func1 is the reference function and Func2 is connected one.
Q77. What is the use of jQuery disconnectAll?
It is used to disconnect
all the connected functions.
e.g.
$.disconnectAll(firstFunc,'Func1');
will disconnect all the
connected function from the reference function Func1.
Q78. What are the minimal/must steps needed to execute JQuery?
1.Wait for the DOM of
the page to be ready.
2.Finds the appropriate
HTML elements that needs to be acted on by using selector.
3.Add event handlers.
e.g.
//Step 1: Wait for the
DOM of the page to be ready.
$(document).ready(function
()
{
//Step 2: Finds the appropriate HTML elements
that needs to be acted on by using selector
var btnObject = $('#btnSayHello');
//Step 3: Add event handlers (Here click events)
btnObject.click(function ()
{
alert("Hello World...My First JQuery
Program");
});
});
Q79. How to debug JQuery?
1.Placing debugger
keyword
Add the keyword debugger
to the line from where we want to start the debugging and then run the Visual
Studio in Debug mode by pressing F5 or using the Debug button.
e.g.
<script language
="javascript">
$(document).ready(function
()
{
var btnObject = $('#btnSayHello');
debugger;
btnObject.click(function ()
{
alert("Hello World...My First JQuery
Program");
});
});
</script>
Q80. .Inserting a break point after attaching worker
process
Press ALT + CTRL + P or
tools -> AttachProcess then choose w3wp.exe .
Q81. What are the ways by which we can include JQuery
in our page?
1.Refer to a local copy
using the <script> tag
2.Refer to a remote copy
on JQuery.com or the remote copy in the Google AJAX API
3.Refer to a local copy
using Script Manager Control
4.Refer to an embedded
script using the ClientScript object
Q82. How to invoke Jquery function from code behind?
Suppose we want to
change the background color of a div tag from the code behind upon button
click.In code behind write the below
protected void
btnChangecolor_Click(object sender, EventArgs e)
{
string script =
"<script type=\"t/divext/JavaScript\"
language=\"javascript\">ChangeDivBackgroundcolor();</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(),
"ChangeColor", script);
}
The aspx file will be as
under
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
<title></title>
<script
type="text/javascript"
src="Scripts/jquery-1.7.2.js"></script>
<script
type="text/javascript">
function ChangeDivBackgroundcolor()
{
var divObject =
$('#divTest');
divObject.css("background-color",
"cyan");
}
</script>
</head>
<body>
<form
id="form1" runat="server">
<div>
<asp:Button
ID="btnChangecolor" runat="server" Text="Say
Hello" onclick="btnChangecolor_Click" />
</div>
<div
id="divTest">Change the color of this div</div>
</form>
</body>
</html>
Q83. What is the significance of document.ready()?
It indicates that the
DOM of the page is ready and we can start manipulating the DOM elements even
though other parts
of the page content(e.g.
images/other external resources) are not fully loaded.As soon as the DOM is
loaded,
everything inside the
(document).ready() should be load even before the page contents are loaded.
Q84. Why is JQuery faster than Javascript at execution
time?
The onLoad function for
the window object executes after the entire page is fully loaded.Untill DOM
tree is completely created and all images/other associated resources (like
audio files,video files etc) are fully loaded,this onLoad function is never
executed and hence the script execution needs to wait till the page is loaded.
But the document.ready()
method of JQuery indicates that the DOM of the page is ready and we can start
manipulating the DOM elements even though other parts of the page content(e.g.
images/other external resources) are not fully loaded.As soon as the DOM is
loaded, everything inside the (document).ready() should be load even before the
page contents are loaded.
It is because of this
reason that JQuery code runs faster
Q85. What is jQuery ?
It's very simple
but most valuable Question on jQuery means jQuery is a fast and concise
JavaScript Library that simplifies HTML document traversing, animating, event
handling, and Ajax interactions for rapid web development. jQuery is designed
to change the way that you write JavaScript. Jquery is build library for
javascript no need to write your own functions or script jquery all ready done
for you
Q86. How you will use Jquery means requirement needed
for using jquery?
Nothing more need
to do just olny download jquery library(.js file) from any of the jquery site
Download jquery and just linked with your html pages like all other javascript
file
like below :
Code:
< script src="jquery.js"
language="javascript" type="text/javascript">
Q86. what the use of $ symbol in Jquery?
$ Symbol is just
replacement of jquery means at the place of $ you may use jquery hence $ symbol
is used for indication that this line used for jquery
Q87. How do you select an item using css class or ID
and get the value by use of jquery?
If an element of
html like < div> , < p> or any tag have ID MyId and class used
MyClass then we select the element by below jquery code
Code:
$('#MyId') for ID and
for classs $('.MyClass')
and for value
Code:
var myValue =
$('#MyId').val();
// get the value
in var Myvalue by id
Or for set the
value in selected item
Code:
$('#MyId').val("print
me");
// set the value
of a form input
Q88. How to get the server response from an AJAX
request using Jquery?
When invoking
functions that have asynchronous behavior We must provide a callback function
to capture the desired result. This is especially important with AJAX in the
browser because when a remote request is made, it is indeterminate when the
response will be received.
Below an example
of making an AJAX call and alerting the response (or error):
Code:
$.ajax({
url: 'pcdsEmpRecords.php',
success: function(response) {
alert(response);
},
error: function(xhr) {
alert('Error! Status = ' + xhr.status);
}
});
Q89. How do you update ajax response with id "
resilts"?
By using below
code we can update div content where id 'results' with ajax response
Code:
function updateStatus()
{
$.ajax({
url: 'pcdsEmpRecords.php',
success: function(response) {
// update div id Results
$('#results').html(response);
}
});
}
Q90. How do You disable or enable a form element?
There arspan
style=e two ways to disable or enable form elements.
Set the 'disabled'
attribute to true or false:
Code:
// Disable #pcds
$('#pcds').attr('disabled',
true);
// Enable #pcds
$('#pcds').attr('disabled',
false);
Add or remove the
'disabled' attribute:
// Disable #pcds
$("#pcds").attr('disabled',
'disabled');
// Enable #x
$("#pcds").removeAttr('disabled');
Q91. How do you check or uncheck a checkbox input or
radio button?
There are two ways
to check or uncheck a checkbox or radio button.
Set the 'checked'
attribute to true or false.
Code:
// Check #pcds
$('#pcds').attr('checked',
true);
// Uncheck #pcds
$('#pcds').attr('checked',
false);
Add or remove the
'checked' attribute:
// Check #pcds
$("#pcds").attr('checked',
'checked');
// Uncheck #pcds
$("#pcds").removeAttr('checked');
Q92. How do you get the text value of a selected
option?
Select elements
typically have two values that you want to access. First there's the value to
be sent to the server, which is easy:
Code:
$("#pcdsselect").val();
// => 1
The second is the
text value of the select. For example, using the following select box:
Code:
<select
id="pcdsselect">
<option
value="1">Mr</option>
<option value="2">Mrs</option>
<option
value="3">Ms</option>
<option
value="4">Dr</option></ attribute:span>
<option
value="5">Prof</option>
</select>
If you wanted to
get the string "Mr" if the first option was selected (instead of just
"1"), you would do that in the following way:
Code:
$("#mpcdsselect
option:selected").text();
// =>
"Mr"
Q93. What is jQuery?
Latest answer: jQuery is
a lightweight JavaScript library that emphasizes interaction between JavaScript
and HTML.............
Q94. Advantages of jQuery
Latest answer: The
advantages of using jQuery are: JavaScript enhancement without the overhead of
learning new syntax............
Q95. Explain the features of jQuery.
Latest answer: Features
of jQuery are :
Effects and
animations
Ajax
Extensibility.............
Q96. Why is jQuery better than javascript?
Latest answer: jQuery is
great library for developing ajax based application.
It helps the
programmers to keep code simple and concise and reusable..............
Read answer
Explain how jQuery
Works.
Latest answer:
<html>
<head>
<script type="text/javascript"
src="jquery.js"></script>
<script
type="text/javascript">................
Read answer
Q97. When can you use jQuery?
Latest answer: JQuery
can be used to
apply CSS
call functions on
events
traverse the
documents...................
Read answer
Q98. What is jQuery Selectors? Give some examples.
jQuery Selectors
are used to select one or a group of HTML elements from your web page.
jQuery support all
the CSS selectors as well as many additional custom selectors.
jQuery selectors
always start with dollar sign and parentheses: $()
There are three
building blocks to select the elements in a web document.
1) Select elements by
tag name
Example: $(div)
It will select all
the div elements in the document.
2) Select elements by ID
Example: $(#xyzid”)
It will select
single element that has an ID of xyzid
3) Select elements by
class
Example:
$(“.xyzclass”)
It will select all
the elements having class xyzclass
Q99. How can we give face effect in jQuery?
In jQuery we have
three methods to give the fade effect to elements: fadeIn, fadeOut and fadeTo
This methods
change the opacity of element with animation.
Syntax:
$(selector).fadeIn(speed,callback)
$(selector).fadeOut(speed,callback)
$(selector).fadeTo(speed,opacity,callback)
“speed” can be one
of following values : “slow”, “fast”, “normal” or milliseconds
“opacity” specify
the value that allows the fading to given opacity.
“callback” is the
function which we want to run once the fading effect is complete.
For example
$("clickme").click(function(){
$("mydiv").fadeTo("slow",0.50);
});
$("clickme").click(function(){
$("mydiv").fadeOut(3000);
});.
Q100. Explain the animate function.
-The animate function is
used to apply the custom animation effect to elements.
-Syntax:
$(selector).animate({params},
[duration], [easing], [callback])
“param” defines
the CSS properties on which you want to apply the animation.
“duration” specify
how long the animation will run. It can be one of following values : “slow”,
“fast”, “normal” or milliseconds
“easing” is the
string which specify the function for the transition.
“callback” is the
function which we want to run once the animation effect is complete.
For example
<div
id="clickToAnimate">
Click Me
</div>
<div
id="mydiv" style=”width:200px; height:300px; position: relative;
right: 20px;">
</div>
Following is the
jQuery to animate opacity, left offset, and height of the mydiv element
$('#
clickToAnimate’).click(function() {
$('#book').animate({
opacity: 0.30,
left: '+=20',
height: 'toggle'
}, 3000,
function() {
// run after the
animation complete.
});
});
Q101. What is .siblings() method in jQuery?
When we want to
fetch siblings of every elements in the set of matched elements then we can use
siblings() method.
We filter the
elements fetched by an optional selector.
Syntax :
.siblings( [selector])
“selector” is the
selector expression which specify the matched elements.
For example
<ul>
<li> item 1
</li>
<li
id=”second_item”> item 2 </li>
<li
class=”myitem”> item 3 </li>
<li
class=”myitem”> item 4 </li>
</ul>
Now we want to find the
siblings of the element of id “second_item” and change the text color to Blue :
$(‘li.second_item’).siblings().css(‘color’,’blue’);
If we want specific
sibling elements for example the elements having class “myitem” then we can
pass a optional selector:
$(‘li.second_item’).siblings(‘.myitem’).css(‘color’,’blue’);
Q102. Explain width() vs css(‘width’).
In jQuery, there
are two way to change the width of an element.
One way is using
.css(‘width’) and other way is using .width().
For example
$(‘#mydiv’).css(‘width’,’300px’);
$(‘#mydiv’).width(100);
The difference in
.css(‘width’) and .width() is the data type of value we specify or return from
the both functions.
In .css(‘width’)
we have to add “px” in the width value while in .width() we don’t have to add.
When you want to
get the width of “mydiv” element then .css(‘width’) will return ‘300px’ while
.width() will return only integer value 300.
Q103. What is the use of jQuery.data()?
jQuery.data() is
used to set/return arbitrary data to/from an element.
Syntax:
jQuery.data(element, key, value)
“element” is the
DOM element to which the data is associated.
“key” is an
arbitrary name of the piece of data.
“value” is value
of the specified key.
Suppose we want to
set the data for a span element:
jQuery.data(span,
“item”, { val1: 10, val2: "myitem" });
If we want to retrieve
the data related to div element and set it to label’s data:
$("label:val1").text(jQuery.data(div,
"item").val1);
$("label:val2").text(jQuery.data(div,
"item").val2);
Q104. Explain bind() vs live() vs delegate() methods.
-The bind() method will
not attach events to those elements which are added after DOM is loaded while
live() and delegate() methods attach events to the future elements also.
-The difference
between live() and delegate() methods is live() function will not work in
chaining. It will work only on an selector or an element while delegate()
method can work in chaining.
For example
$(document).ready(function(){
$("#myTable").find("tr").live("click",function(){
alert($(this).text());
});
});
Above code will
not work using live() method. But using delegate() method we can accomplish
this.
$(document).ready(function(){
$("#dvContainer")children("table").delegate("tr","click",function(){
alert($(this).text());
});
});
Q105. Explain the each() function.
-The each() function
specify the function to be called for every matched element.
Syntax:
$(selector).each(function
(index, element))
“index” is the
index position of the selector.
“selector”
specifies the current selector where we can use “this” selector also.
In the case when
we need to stop the each loop early then we can use “return false;”
For example
$("#clickme").click(function(){
$("li").each(function(){
document.write($(this).text())
});
});
This will write
the text for each “li” element.
Q106. Explain slideToggle() effect.
-slideToggle() effect is
used to give animated sliding effect to an element.
Syntax:
slideToggle([ duration]
[, easing] [, callback])
“duration” is the
number specifying how long the animation will run.
“easing” is the
string which specify the function for the transition.
“callback” is the
function which we want to run once the animation is complete.
If the element is
visible then this effect will slide the element up side and make it completely
hidden. If the element is hidden then slideToggle() effect will slide it down
side and make it visible.
We can specify the
toggle speed with this effect.
For example
$("#clickme").click(function(){
$("#mydiv").slideToggle(“slow”,
function(){
//run after the
animation is complete.
});
});
Q107. What is difference between $(this) and ‘this’ in
jQuery?
Refer the following
example
$(document).ready(function(){
$(‘#clickme’).click(function(){
alert($(this).text());
alert(this.innerText);
});
});
-this and $(this)
references the same element but the difference is that “this” is used in
traditional way but when “this” is used with $() then it becomes a jQuery
object on which we can use the functions of jQuery.
-In the example
given, when only “this” keyword is used then we can use the jQuery text()
function to get the text of the element, because it is not jQuery object. Once
the “this” keyword is wrapped in $() then we can use the jQuery function text()
to get the text of the element.
Q108. What is the use of param() method.
The param() method
is used to represent an array or an object in serialize manner.
While making an
ajax request we can use these serialize values in the query strings of URL.
Syntax:
$.param(object | array, boolValue)
“object | array”
specifies an array or an object to be serialized.
“boolValue”
specifies whether to use the traditional style of param serialization or not.
For example:
personObj=new Object();
empObject.name="Arpit";
empObject.age="24";
empObject.dept=”IT”;
$("#clickme").click(function(){
$("span").text($.param(empObject));
});
It will set the
text of span to “name=Arpit&age=24&dep=IT”
Q109. What is jQuery.holdReady() function?
-By using
jQuery.holdReady() function we can hold or release the execution of jQuery’s
ready event.
-This method
should be call before we run ready event.
-To delay the
ready event, we have to call
jQuery.holdReady(true);
-When we want to release
the ready event then we have to call
jQuery.holdReady(false);
-This function is
helpful when we want to load any jQuery plugins before the execution of ready
event.
For example
$.holdReady(true);
$.getScript("xyzplugin.js",
function() {
$.holdReady(false);
});
Q110. Explain .empty() vs .remove() vs .detach().
-.empty() method is used
to remove all the child elements from matched elements.
-.remove() method
is used to remove all the matched element. This method will remove all the
jQuery data associated with the matched element.
-.detach() method
is same as .remove() method except that the .detach() method doesn’t remove
jQuery data associated with the matched elements.
-.remove() is
faster than .empty() or .detach() method.
Syntax:
$(selector).empty();
$(selector).remove();
$(selector).detach();
Q111. How to read, write and delete cookies in jQuery?
-To deal with cookies in
jQuery we have to use the Dough cookie plugin.
-Dough is easy to
use and having powerful features.
-Create cookie
$.dough("cookie_name",
"cookie_value");
Read Cookie
$.dough("cookie_name");
Delete cookie
$.dough("cookie_name",
"remove");
Q112. Is window.onload is different from
document.ready()?
- The window.onload() is
Java script function and document.ready() is jQuery event which are called when
page is loaded.
- The difference
is that document.ready() is called after the DOM is loaded without waiting for
all the contents to get loaded. While window.onload() function waits until the
contents of page is loaded.
- Suppose there is
very large image on a page, at that time window.onload() will wait until that
image is loaded totally.
- So while using
the window.onlaod() function the execution will be slow, but the
document.ready() will not wait until the image is loaded.
Q113. What is Chaining in jQuery?
- Chaining is very
powerful feature of jQuery.
- Chaining means
specifying multiple function and/or selectors to an element.
- Examine the
below example
$(document).ready(function(){
$('#mydiv').css('color',
'blue');
$('#mydiv').addClass('myclass');
$('#mydiv').fadeIn('fast');
}
By using chaining we can
write above code as follows
$(document).ready(function(){
$('#mydiv').css('color',
'blue').addClass('myclass').fadeIn('fast');
});
-Advantage of chaining
is that it makes your code simple and simple to manage.
-The execution
becomes faster because the code search for the element only once.
Q114. What is difference between sorting string array
and sorting numerical array in jQuery?
The sort method is used
to sort any array elements. It sorts the string elements alphabetically.
For example
$(document).ready(function(){
var mylist = [
“Apple”,”Orange”,”Banana”];
mylist =
mylist.sort();
$(“#mydiv”).html(list.join(“”));
});
It will give following
output
Apple
Banana
Orange
Now we declare a
numerical array and use sort() method to sort its elements.
$(document).ready(function(){
var mylist = [
“20”,”3””100”,”50”];
mylist =
mylist.sort();
$(“#mydiv”).html(list.join(“”));
});
It will give following
output
100
20
3
50
Q115. What is difference between prop and attr?
In jQuery both
prop() and attr() function is used to set/get the value of specified property
of an element.
The difference in
both the function is that attr() returns the default value of the property
while the prop() returns the current value of the property.
For example
<input value="My
Value" type="text"/>
$('input').prop('value',
'Changed Value');
-.attr('value')
will return 'My Value'
-.prop('value')
will return 'Changed Value'
Q116. How to always reference latest version of jQuery?
When you reference the
jQuery on your web page, you have to specify the version number also.
<script
type=”text/javascript”
src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”>
</script>
Above code will always
load the 1.5.1 version of jQuery. If you reference the latest jQuery then you
don’t need to change the code every time the new version of jQuery is released.
To achieve this you have
to use following code
<script
type=”text/javascript”
src=”http://code.jquery.com/jquery-latest.min.js”>
</script>
This code will always
reference the latest version of jQuery in your page.
Q117. What is resize() function in jQuery?
The resize() function is
called whenever the browser size is changed. This event can be only used with
$(window).
Syntax:
.resize([event_data],
handler(event_object))
-The “event_data” is the
data to be sent to the handler.
-The
“handler(event_object)” is a function to be called each time when the window is
resized.
For example
$(window).resize(function()
{
$('#message).text('window
is resized to ' + $(window).width() + ‘x’ + $(window).height());
});
What is the difference between Body.OnLoad and jQuery document.ready() Event?
Both Body.OnLoad() event and jQuery.ready() event will execute the javascript code when the page is loaded.
- Body.Onload() event will be called only after the DOM and associated resources like images got loaded, but jQuery's document.ready() event will be called once the DOM is loaded i.e., it wont wait for the resources like images to get loaded. Hence, the functions in jQuery's ready event will get executed once the HTML structure is loaded without waiting for the resources.
- We can have multiple document.ready() in a page but Body.Onload() event cannot.
Defining Body.Onload() event<body onload="javascript function name or the atcual script">
Defining jQuery.ready() event
<script type="text/javascript">
$(document).ready(function() {
//Script goes here
});
$(document).ready(function() {
//Script goes here
});
</script>
OR
<script type="text/javascript">
$(function() {
//Script goes here
});
</script>
$(function() {
//Script goes here
});
</script>
Q.How check currently loaded jQuery UI
version on the page?
Ans: // Returns jQuery UI version (ex: 1.8.2) or undefined
$.ui.version
Ans: // Returns jQuery UI version (ex: 1.8.2) or undefined
$.ui.version
Q. What is jQuery.noConflict?
Ans: As other client side libraries like
MooTools, Prototype can be used with jQuery and they also use $() as their
global function and to define variables. This situation creates conflict as $() is used by jQuery and other library as their global
function. To overcome from such situations, jQuery has introduced jQuery.noConflict().
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
jQuery("div").hide();
});
You can also use your own specific character in
the place of $ sign in jQuery.
var $j = jQuery.noConflict();
// Use jQuery via jQuery(...)
$j(document).ready(function(){
$j("div").hide();
});
Q. Is there any difference between body onload() and
document.ready() function?
Ans: document.ready() function is different from body onload() function for 2 reasons.
1. We can have more than one document.ready() function
in a page where we can have only one bodyonload function.
2. document.ready() function is called as soon as DOM is
loaded where body.onload() function is called when everything gets
loaded on the page that includes DOM, images and all associated resources of
the page.
Q. What is the difference between .js and .min.js?
Ans: jQuery library comes in 2 different
versions Production and Deployment. The deployment version is also known as
minified version. So .min.js is basically the minified version of jQuery
library file. Both the files are same as far as functionality is concerned. but
.min.js is quite small in size so it loads quickly and saves bandwidth.
Q. Why there are two different version of jQuery library?
Q. Why there are two different version of jQuery library?
Ans: jQuery library comes in 2 different
versions.
1. Production
2. Deployment
The production version is quite useful at
development time as jQuery is open source and if you want to change something
then you can make those changes in production version. But the deployment
version is minified version or compressed version so it is impossible to make
changes in it. Because it is compressed, so its size is very less than the
production version which affects the page load time.
Q. What is a CDN?
Ans: A content delivery network or content
distribution network (CDN) is a large distributed system of servers deployed in
multiple data centers across the Internet. The goal of a CDN is to serve
content to end-users with high availability and high performance.
Q. Which are the popular jQuery CDN? and what is the advantage of using CDN?
Q. Which are the popular jQuery CDN? and what is the advantage of using CDN?
Ans: There are 3 popular jQuery CDNs.
1. 1. Google.
2. 2. Microsoft
3. 3. jQuery.
Advantage of using CDN.
· It reduces the load from your server.
· It saves bandwidth. jQuery framework will load faster from these
CDN.
· The most important benefit is it will be cached, if the user has
visited any site which is using jQuery framework from any of these CDN
Q. How to load jQuery from CDN?
Ans: Below is the code to load jQuery from all
3 CDNs.
Code to load jQuery Framework from Google CDN
Code to load jQuery Framework from Google CDN
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
Code to load jQuery Framework from Microsoft CDN
<script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js">
</script>
Code to load jQuery Framework from jQuery Site(EdgeCast CDN)
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>
Q. How to load jQuery locally when CDN fails?
Ans: It is a good approach to always use CDN
but sometimes what if the CDN is down (rare possibility though) but you never
know in this world as anything can happen.
Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.
Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
document.write(unescape("%3Cscript
src='Scripts/jquery.1.9.1.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
It first loads the jQuery from Google CDN and
then check the jQuery object. If jQuery is not loaded successfully then it will
references the jQuery.js file from hard drive location. In this example, the
jQuery.js is loaded from Scripts folder.
Q. What are selectors in jQuery and how many types of selectors
are there?
Ans: To work with an element on the web page,
first we need to find them. To find the html element in jQuery we use
selectors. There are many types of selectors but basic selectors are:
· Name: Selects all elements which match with the given element
Name.
· #ID: Selects a single element which matches with the given ID
· .Class: Selects all elements which match with the given Class.
· Universal (*): Selects all elements available in a DOM.
· Multiple Elements E, F, G: Selects the combined results of all
the specified selectors E, F or G.
· Attribute Selector: Select elements based on its attribute
value.
Q.What are the fastest selectors in Jquery?
Ans: ID and element selectors are the fastest selectors
Q.What are the slower selecoters in Jquery?
Ans: Class selectors are slower
Q.Which one is faster Jquery ID selector or JavaScript getElementById()?
(Jquery ID selector vs JavaScript getElementById())
Ans: JavaScript getElementById() is faster than Jquery Id ($("#elementID")) selector
Q.Where Jquery code execute? On client browser or server browser?
On client browser
Ans: ID and element selectors are the fastest selectors
Q.What are the slower selecoters in Jquery?
Ans: Class selectors are slower
Q.Which one is faster Jquery ID selector or JavaScript getElementById()?
(Jquery ID selector vs JavaScript getElementById())
Ans: JavaScript getElementById() is faster than Jquery Id ($("#elementID")) selector
Q.Where Jquery code execute? On client browser or server browser?
On client browser
Q.What is Chaining in jQuery?
Ans:
In jQuery, Chaining means to connect multiple functions, events on selectors. look at Sample Code 1 and 2.
Ans:
In jQuery, Chaining means to connect multiple functions, events on selectors. look at Sample Code 1 and 2.
Q.What are features of JQuery
or
What can be done using JQuery?
Features of Jquery
1. One can easily provide effects and can do animations.
2. Applying / Changing CSS.
3. Cool plugins.
4. Ajax support
5. DOM selection events
6. Event Handling
Q. Which is fast document.getElementByID('txtName') or
$('#txtName').?
Ans: Native JavaScipt is always fast. jQuery
method to select txtName "$('#txtName')" will internally makes
a call todocument.getElementByID('txtName'). As jQuery is written on top of JavaScript and it internally
uses JavaScript only So JavaScript is always fast.
Q. Difference between $(this) and 'this' in jQuery?
Ans: this and $(this) refers to the same element. The only difference is the
way they are used. 'this' is used in traditional sense, when 'this' is wrapped
in $() then it becomes a jQuery
object and you are able to use the power of jQuery.
$(document).ready(function(){
$('#spnValue').mouseover(function(){
alert($(this).text());
});
});
In below example, this is an object but since
it is not wrapped in $(), we can't use jQuery method and use the native
JavaScript to get the value of span element.
$(document).ready(function(){
$('#spnValue').mouseover(function(){
alert(this.innerText);
});
});
Q. What is asynchronous in Jquery ?
A. By default, all requests are sent asynchronously (i.e. this is set to
true
by default). If you need synchronous requests, set this option to false
.
contentType (default:
'application/x-www-form-urlencoded; charset=UTF-8'
)
crossDomain (default:
false for same-domain requests, true for cross-domain requests
)$.ajax({
url: "data.php",
context: document.body
}).done(function() {
$( this ).addClass( "content" );
});
Q. What is Proxy in jquery?
A. Proxy is an object that can be used to control and access to another object. It implements the same interface as this other object and passes on any method invocations to it. This other object is often called the real subject. one way to combine that is to implement a proxy pattern in JavaScript, enabling the basics of aspect-oriented programming (AOP)
(function() {
// log all calls to setArray
var proxied = jQuery.fn.setArray;
jQuery.fn.setArray = function() {
console.log( this, arguments );
return proxied.apply( this, arguments );
};
})();
Q.What is Closure?
A. Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope. In the following example, the variable counter is visible within the create, increment, and print functions, but not outside of them.
function create() {
var counter = 0;
return {
increment: function() {
counter++;
},
print: function() {
console.log( counter );
}
}
}
var c = create();
c.increment();
c.print(); // 1
No comments:
Post a Comment