jQuery Interview Questions and Answers

jQuery Interview Questions and Answers

1. What is jQuery?

A. jQuery can simply be interpreted as most advanced JavaScript framework which is used for performing high-level applications which include feature-rich, fast,and lightweight framework which assists in to through the HTML DOM, add Ajax interaction, build animations, manipulation of the page content, modify the alignment and render cool UI effect. This is a client-side scripting language.

2. Can differentiate between jQuery and JavaScript?

A. The difference between the jQuery and the JavaScript can simply be explained.
JavaScript can simply be interpreted as a high-level application language whereas, jQuery can be interpreted as a library which is built within the JavaScript language & helps in the better functioning of JavaScript.

3.Can a jQuery library be used for server scripting?

A. jQuery can be interpreted as an internally built library which is being used in the JavaScript.
And jQuery is strictly been designed with the functionality of client-side scripting. jQuery is not compatible with server-side scripting.

4.Why exactly is the need for the use of jQuery?

.A. jQuery is a highly programmed internal library for the better functioning of JavaScript. It handles a number of applications and its prominence can never be ignored. The following list will be depicting the reasons for why is the need to use jQuery?
* jQuery comes very handily for the purpose of designing user-friendly web applications.
* By making an effective use of jQuery the performance of an application can be greatly enhanced.
* Very fast and extensible.
* Only minimal lines of codes will be sufficient for writing UI related functions.

5.State different jQuery methods that are used to provide effects?

A. jQuery has a set of methods implying which we can expect to provide different effects within the system. Some of the jQuery methods include.
* FadeOut()
* Toggle()
* Hide()
* Show()
* FadeIn()

6. Describe the minimized version of the jQuery and its benefits.

A. With the minimized version of the jQuery, the efficiency of the webpage can be greatly improved. The effectiveness of the webpage which is having a minimized version of jQuery will be a lot better than the effectiveness of the webpage which is having a normal js file.
This is the reason why most of the web pages are nowadays are found to have a minimized version of the jQuery.

7.Explain about different scenarios where jQuery can be effectively implemented?

A. jQuery is a highly advanced library application which extensively is used in following scenarios:
* Apply CSS static or dynamic functions.
* Calling functions on events.
* For the purpose of manipulation.
* For creating different animation effects.Having the presence of all the advanced library applications jQuery is best at maintaining different applications with a higher degree of effectiveness.

8.Which parameters are being used for the jQuery Ajax method?

A. JQuery Ajax method makes use of four different parameters which include
* URL – The URL must be clearly specified in order to send the request.
* type – Specifies the type of request(Get or Post)
* data – Specifies data to be sent to the server
* Cache – This tells if the browser should index the specific page or not.
* success(result,status,xhr) – A function to be run when the request succeeds

9. Explain the ways through which we can include jQuery on a page?

A. Including jQuery in a page can be done with the help of the following ways.
* Local copy inside script tag
* Remote copy of jQuery.com
* By keeping a remote copy of Ajax API
* Making a local copy of script manager control
* Embedded script using client script object

10. Differentiate the concepts of ID selector and class selector in jQuery?

A. Just like they are used in the CSS, both ID selector and Class selector are used for the same functioning .
In order explain the functioning of both the concepts in simpler words, ID selector uses ID while class selector makes use of a class to select the different elements.In the case where you are needed to select only one element then we have to go with the ID selector.
And if you want to select a group of elements, then we have to go with the class selector.

11.What is JQuery.noConflict?

A. In order to help the system to overcome the conflicts between the different libraries and frameworks the jQuery no-conflict option given by the jQuery. This concept is really advanced which has been developed over the recent times. In the case of any conflicts which arise between the libraries and frameworks using this jQuery.noConflict function will help in overcoming all the conflicts.

12. Explain the concept of fade effect in jQuery?

A. 1. In jQuery there are three different applications applying which we can avail the fade effect.
Fade effect can be availed by using the functions which are fadeIn, fadeOut and fadeTo.

2. The opacity of elements gets changed with animation through the effect of these methods.
The syntax for the fading effect includes
Syntax:

$(selector).fadeIn(speed,callback)
$(selector).fadeOut(speed,callback)
$(selector).fadeTo(speed,opacity,callback)

13.Explain how the jQuery stores data related to an element?

A. Information of an element can be stored in the simple javascript by simply adding a domain object model property to the element. This results in the rising of issues such as leakage of memory in the browsers.
But in the case of jQuery the user does not need to be bothered by the memory management issues.For ex : Storing and retrieving data related to an element:

$(‘#myDiv’).data(‘keyName’, { foo : ‘bar’ });
$(‘#myDiv’).data(‘keyName’); // { foo : ‘bar’ }

14.Differentiate onload() and document.ready().

A. The main differentiating factor of onload() and document.ready() is that
At max, a page supports the existence of only one onload function, & all the other onload functions will be getting terminated
While coming to the document.ready function, a page can have more than one document.ready function.
Also, the document.ready function is called when the DOM gets loaded and whereas the onload function gets called only when the DOM images get loaded on the page.

15.What are the types of selectors in jQuery?

A. There are three types of selectors in jQuery:
CSS Selector
XPath Selector
Custom Selector

16.Explain bind() vs live() vs delegate() methods.

A. TThe 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.

17. How to read, write and delete cookies in jQuery ?

A. 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”);

18. What is a CDN?

A. 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.

19. Which are the popular jQuery CDN? and what is the advantage of using CDN?

A. There are 3 popular jQuery CDNs.
Google.
Microsoft.
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

20. How to load jQuery locally when CDN fails?

A. 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.

<script type=”text/javascript”>
if (typeof jQuery == ‘undefined’)
{
document.write(unescape(“<script src=’Scripts/jquery.1.9.1.min.js’ type=’text/javascript’></script>”));
}
</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.

21. Difference between $(this) and ‘this’ in jQuery?

A. 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);
});
});

22.What is the difference between eq() and get() methods in jQuery?

A. eq() returns the element as a jQuery object. This method constructs a new jQuery object from one element within that set and returns it. That means that you can use jQuery functions on it.get() return a DOM element. The method retrieve the DOM elements matched by the jQuery object. But as it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can’t be used. Find out more here.

23.Is jQuery a programming language?

A. jQuery is not a programming language but a well-written JavaScript code. It is used to traverse documents, event handling, Ajax interaction, and Animation.

24.What is the difference between JavaScript and jQuery?

A. The simple difference is that JavaScript is a language while jQuery is a built-in library built for JavaScript. jQuery simplifies the use of JavaScript language.

25.Is jQuery replacement of JavaScript?

A. No, jQuery is not the replacement of JavaScript. jQuery is written on the top of JavaScript, and it is a different library. jQuery is a lightweight JavaScript library which is used to interact with JavaScript and HTML.

26.What is $() in jQuery library?

A. The $() function is an alias of jQuery() function. It is used to wrap any object into jQuery object which later facilitates you to call the various method defined jQuery object. You can pass a selector string to $() function, and it returns a jQuery object which contains an array of all matched DOM elements.

27.What is the use of toggle() method in JQuery?

A. The jQuery toggle() is a particular type of method which is used to toggle between the hide() and show() method. It shows the hidden elements and hides the shown element.

$(selector).toggle();
$(selector).toggle(speed, callback);
$(selector).toggle(speed, easing, callback);
$(selector).toggle(display);

speed: It is an optional parameter. It specifies the speed of the delay. Its possible values are slow, fast and milliseconds.
easing: It specifies the easing function to be used for transition.
callback: It is also an optional parameter. It specifies the function to be called after completion of toggle() effect.
display: If true, it displays an element. If false, it hides the element.

28.Is it possible that jQuery HTML work for both HTML and XML document?

A. No, jQuery HTML only works for HTML document. It doesn’t work for XML documents.

29.What is the starting point of code execution in jQuery?

A. $(document).ready() function is the starting point of jQuery code. It is executed when DOM is loaded.

30.What is the goal of CDN and what are the advantages of using CDN?

A. The primary goal of the CDN is to provide content to the end-users with high availability and high performance.Advantages of using CDN:
It reduces the load from the server.
It saves bandwidth. jQuery framework is loaded faster from these CDN.
If a user regularly visits a site which is using jQuery framework from any of these CDN, it will be cached.

31.What is a use of jQuery filter?

A. jQuery filter is used to filter the specific values from the object. It filters the result of your original query into specific elements.

32.What is the use of val() method in JQuery?

A. The .val() method is primarily used to get the values of form elements such as input , select and textarea

33.What is the difference between prop and attr?

A. attr(): It gets the value of an attribute for the first element in the set of matched element.
prop(): it gets the value of a property for the first element in the set of matched elements. It is introduced in jQuery 1.6.

34.What is slice() method in jQuery?

A. The slice() method selects a subset of the matched elements by giving a range of indices. It gives the set of DOM elements on the basis of a parameter.Syntax:
.slice( start, end[Optional] )
Start: This is the first and mandatory parameter of the slice method. This specifies from where to start to select the elements.
End: This is an optional parameter. It specifies the range of the selection. This indicates where to stop the selection of elements, excluding end element.

1. What is jQuery?

A. jQuery can simply be interpreted as most advanced JavaScript framework which is used for performing high-level applications which include feature-rich, fast,and lightweight framework which assists in to through the HTML DOM, add Ajax interaction, build animations, manipulation of the page content, modify the alignment and render cool UI effect. This is a client-side scripting language.

2. Can differentiate between jQuery and JavaScript?

A. The difference between the jQuery and the JavaScript can simply be explained.
JavaScript can simply be interpreted as a high-level application language whereas, jQuery can be interpreted as a library which is built within the JavaScript language & helps in the better functioning of JavaScript.

3.Can a jQuery library be used for server scripting?

A. jQuery can be interpreted as an internally built library which is being used in the JavaScript.
And jQuery is strictly been designed with the functionality of client-side scripting. jQuery is not compatible with server-side scripting.

4.Why exactly is the need for the use of jQuery?

.A. jQuery is a highly programmed internal library for the better functioning of JavaScript. It handles a number of applications and its prominence can never be ignored. The following list will be depicting the reasons for why is the need to use jQuery?
* jQuery comes very handily for the purpose of designing user-friendly web applications.
* By making an effective use of jQuery the performance of an application can be greatly enhanced.
* Very fast and extensible.
* Only minimal lines of codes will be sufficient for writing UI related functions.

5.State different jQuery methods that are used to provide effects?

A. jQuery has a set of methods implying which we can expect to provide different effects within the system. Some of the jQuery methods include.
* FadeOut()
* Toggle()
* Hide()
* Show()
* FadeIn()

6. Describe the minimized version of the jQuery and its benefits.

A. With the minimized version of the jQuery, the efficiency of the webpage can be greatly improved. The effectiveness of the webpage which is having a minimized version of jQuery will be a lot better than the effectiveness of the webpage which is having a normal js file.
This is the reason why most of the web pages are nowadays are found to have a minimized version of the jQuery.

7.Explain about different scenarios where jQuery can be effectively implemented?

A. jQuery is a highly advanced library application which extensively is used in following scenarios:
* Apply CSS static or dynamic functions.
* Calling functions on events.
* For the purpose of manipulation.
* For creating different animation effects.Having the presence of all the advanced library applications jQuery is best at maintaining different applications with a higher degree of effectiveness.

8.Which parameters are being used for the jQuery Ajax method?

A. JQuery Ajax method makes use of four different parameters which include
* URL – The URL must be clearly specified in order to send the request.
* type – Specifies the type of request(Get or Post)
* data – Specifies data to be sent to the server
* Cache – This tells if the browser should index the specific page or not.
* success(result,status,xhr) – A function to be run when the request succeeds

9. Explain the ways through which we can include jQuery on a page?

A. Including jQuery in a page can be done with the help of the following ways.
* Local copy inside script tag
* Remote copy of jQuery.com
* By keeping a remote copy of Ajax API
* Making a local copy of script manager control
* Embedded script using client script object

10. Differentiate the concepts of ID selector and class selector in jQuery?

A. Just like they are used in the CSS, both ID selector and Class selector are used for the same functioning .
In order explain the functioning of both the concepts in simpler words, ID selector uses ID while class selector makes use of a class to select the different elements.In the case where you are needed to select only one element then we have to go with the ID selector.
And if you want to select a group of elements, then we have to go with the class selector.

11.What is JQuery.noConflict?

A. In order to help the system to overcome the conflicts between the different libraries and frameworks the jQuery no-conflict option given by the jQuery. This concept is really advanced which has been developed over the recent times. In the case of any conflicts which arise between the libraries and frameworks using this jQuery.noConflict function will help in overcoming all the conflicts.

12. Explain the concept of fade effect in jQuery?

A. 1. In jQuery there are three different applications applying which we can avail the fade effect.
Fade effect can be availed by using the functions which are fadeIn, fadeOut and fadeTo.

2. The opacity of elements gets changed with animation through the effect of these methods.
The syntax for the fading effect includes
Syntax:

$(selector).fadeIn(speed,callback)
$(selector).fadeOut(speed,callback)
$(selector).fadeTo(speed,opacity,callback)

13.Explain how the jQuery stores data related to an element?

A. Information of an element can be stored in the simple javascript by simply adding a domain object model property to the element. This results in the rising of issues such as leakage of memory in the browsers.
But in the case of jQuery the user does not need to be bothered by the memory management issues.For ex : Storing and retrieving data related to an element:

$(‘#myDiv’).data(‘keyName’, { foo : ‘bar’ });
$(‘#myDiv’).data(‘keyName’); // { foo : ‘bar’ }

14.Differentiate onload() and document.ready().

A. The main differentiating factor of onload() and document.ready() is that
At max, a page supports the existence of only one onload function, & all the other onload functions will be getting terminated
While coming to the document.ready function, a page can have more than one document.ready function.
Also, the document.ready function is called when the DOM gets loaded and whereas the onload function gets called only when the DOM images get loaded on the page.

15.What are the types of selectors in jQuery?

A. There are three types of selectors in jQuery:
CSS Selector
XPath Selector
Custom Selector

16.Explain bind() vs live() vs delegate() methods.

A. TThe 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.

17. How to read, write and delete cookies in jQuery ?

A. 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”);

18. What is a CDN?

A. 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.

19. Which are the popular jQuery CDN? and what is the advantage of using CDN?

A. There are 3 popular jQuery CDNs.
Google.
Microsoft.
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

20. How to load jQuery locally when CDN fails?

A. 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.

<script type=”text/javascript”>
if (typeof jQuery == ‘undefined’)
{
document.write(unescape(“<script src=’Scripts/jquery.1.9.1.min.js’ type=’text/javascript’></script>”));
}
</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.

21. Difference between $(this) and ‘this’ in jQuery?

A. 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);
});
});

22.What is the difference between eq() and get() methods in jQuery?

A. eq() returns the element as a jQuery object. This method constructs a new jQuery object from one element within that set and returns it. That means that you can use jQuery functions on it.get() return a DOM element. The method retrieve the DOM elements matched by the jQuery object. But as it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can’t be used. Find out more here.

23.Is jQuery a programming language?

A. jQuery is not a programming language but a well-written JavaScript code. It is used to traverse documents, event handling, Ajax interaction, and Animation.

24.What is the difference between JavaScript and jQuery?

A. The simple difference is that JavaScript is a language while jQuery is a built-in library built for JavaScript. jQuery simplifies the use of JavaScript language.

25.Is jQuery replacement of JavaScript?

A. No, jQuery is not the replacement of JavaScript. jQuery is written on the top of JavaScript, and it is a different library. jQuery is a lightweight JavaScript library which is used to interact with JavaScript and HTML.

26.What is $() in jQuery library?

A. The $() function is an alias of jQuery() function. It is used to wrap any object into jQuery object which later facilitates you to call the various method defined jQuery object. You can pass a selector string to $() function, and it returns a jQuery object which contains an array of all matched DOM elements.

27.What is the use of toggle() method in JQuery?

A. The jQuery toggle() is a particular type of method which is used to toggle between the hide() and show() method. It shows the hidden elements and hides the shown element.

$(selector).toggle();
$(selector).toggle(speed, callback);
$(selector).toggle(speed, easing, callback);
$(selector).toggle(display);

speed: It is an optional parameter. It specifies the speed of the delay. Its possible values are slow, fast and milliseconds.
easing: It specifies the easing function to be used for transition.
callback: It is also an optional parameter. It specifies the function to be called after completion of toggle() effect.
display: If true, it displays an element. If false, it hides the element.

28.Is it possible that jQuery HTML work for both HTML and XML document?

A. No, jQuery HTML only works for HTML document. It doesn’t work for XML documents.

29.What is the starting point of code execution in jQuery?

A. $(document).ready() function is the starting point of jQuery code. It is executed when DOM is loaded.

30.What is the goal of CDN and what are the advantages of using CDN?

A. The primary goal of the CDN is to provide content to the end-users with high availability and high performance.Advantages of using CDN:
It reduces the load from the server.
It saves bandwidth. jQuery framework is loaded faster from these CDN.
If a user regularly visits a site which is using jQuery framework from any of these CDN, it will be cached.

31.What is a use of jQuery filter?

A. jQuery filter is used to filter the specific values from the object. It filters the result of your original query into specific elements.

32.What is the use of val() method in JQuery?

A. The .val() method is primarily used to get the values of form elements such as input , select and textarea

33.What is the difference between prop and attr?

A. attr(): It gets the value of an attribute for the first element in the set of matched element.
prop(): it gets the value of a property for the first element in the set of matched elements. It is introduced in jQuery 1.6.

34.What is slice() method in jQuery?

A. The slice() method selects a subset of the matched elements by giving a range of indices. It gives the set of DOM elements on the basis of a parameter.Syntax:
.slice( start, end[Optional] )
Start: This is the first and mandatory parameter of the slice method. This specifies from where to start to select the elements.
End: This is an optional parameter. It specifies the range of the selection. This indicates where to stop the selection of elements, excluding end element.