jQuery Interview Questions and Answers

Q.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.
Q.2. Can differentiate between jQuery and JavaScript?
A. jThe 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.
Q.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.
Q.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.
Q.5.State different jQuery methods that are used to provide effects?
A. j 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()
Q.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.
Q.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.
Q.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.
Q.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
Q.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.
Q.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.
Q.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)
Q.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’ }
Q.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.
Q.15.What are the types of selectors in jQuery?
A. There are three types of selectors in jQuery:

  • CSS Selector
  • XPath Selector
  • Custom Selector
Q.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.
Q.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”);
Q.18. What is a CDN?
A. 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.19. Which are the popular jQuery CDN? and what is the advantage of using CDN?
A. There are 3 popular jQuery CDNs.

  1. Google.
  2. Microsoft.
  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.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("%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.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);
});
});
Q.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.
Q.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.
Q.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.
Q.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.
Q.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.
Q.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.
Q.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.
Q.29.Is jQuery library used for server scripting or client scripting?
A. It is a library for client-side Scripting.
Q.30.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.
Q.31.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.
Q.32.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.
Q.33.What is the use of val() method in JQuery?
A. The jQuery val() method is used:

  • To get the current value of the first element in the set of matched elements.
  • To set the value of every matched element.
Q.34.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.
Q.35.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.