Top JQuery Interview Questions and Answers
Top 50 JQuery Interview Questions & Answers
1. What is jQuery?
jQuery is not a programming language but a well written JavaScript code. It is a JavaScript code, which do document traversing, event handling, Ajax interactions and Animations.
2. Why jQuery is needed?
jQuery is needed for the following list:
- Used to develop browser compatible web applications
- Improve the performance of an application
- Very fast and extensible
- UI related functions are written in minimal lines of codes
3. Whether jQuery HTML work for both HTML and XML documents?
No, jQuery HTML only works for HTML documents not for XML Documents.
4. What are the methods used to provide effects?
Some of the effects methods are:
- Show()
- Hide()
- Toggle()
- FadeIn() and
- FadeOut()
5. What is the advantage of using minimized version of jQuery?
Efficiency of web page increases when minimized version of jQuery is used.min.js file will be more than 50% less than the normal js file. Reduction in the file size makes the web page faster.
6. Is jQuery is a JavaScript or JSON library file?
jQuery is a library of JavaScript file and it consists of DOM, event effects and the Ajax functions. jQuery is said to be a single JavaScript file.
7. Which operating system is more compatible with jQuery?
Mac, Windows and Linux are more compatible with the jQuery.
8. How can we include jQuery library in ASP.Net project?
Download the jQuery library from jQuery.com and include that reference in the asp.net page.
9. Which command will give a version of jQuery?
The command $.ui.version returns jQuery UI version.
10. In what scenarios jQuery can be used?
jQuery can be used in following scenarios:
- Apply CSS static or dynamic
- Calling functions on events
- Manipulation purpose
- Mainly for Animation effects
11. What is the difference between find and children methods?
Find method is used to find all levels down the DOM tree but children find single level down the DOM tree.
12. What is jQuery connect?
A ‘ jQuery connect’ is a plugin used to connect or bind a function with another function. Connect is used to execute function from any other function or plugin is executed.
13. How to use connect?
Connect can be used by downloading jQuery connect file from jQuery.com and then include that file in the HTML file. Use $.connect function to connect a function to another function.
14. What are the features of jQuery, has been used in web applications?
jQuery uses features like Sliding, File uploading and accordian in web applications.
15. What are the browser related issues for jQuery?
Browser compatibility of jQuery plugin is an issue and needs lot of time to fix it.
16. Whether we need to add jQuery file in both Master and Content page?
jQuery file should be added to the Master page and can use access from the content page directly without having any reference to it.
17. What are the basic selectors in jQuery?
Following are the basic selectors in jQuery:
- Element ID
- CSS Name
- Tag Name
- DOM hierarchy
18. Can we call C# code behind using jQuery?
Yes, we can call C# code from jQuery as it supports .net application.
19. What is the use jQuery.data method?
jQuery.data methods is used to associate the data with the DOM nodes and the objects. This data method makes the jQuery code clear and concise.
20. What is the use of each function in jQuery?
Each function is used to iterate each and every element of an object. It is used to loop DOM elements, arrays and the object properties.
21. What is the difference between size and length of jQuery?
Size and length both returns the number of element in an object. But length is faster than the size because length is a property and size is a method.
22. Can we add more than one ‘document.ready’ function in a page?
Yes, we can add more than one document.ready function in a page. But, body.onload can be added once in a page.
23. What is the use of jQuery load method?
jQuery load method is a powerful AJAX method which is used to load the data from a server and assign the data into the element without loading the page.
24. Whether our own specific characters are used in place of $ in jQuery?
Yes, We can use our own variable in place of $ by using the method called no Conflict () method.
var sample = $.noConflict()
25. What are the four parameters used for jQuery Ajax method?
The four parameters are
- URL – Need to specify the URL to send the request
- type – Specifies type of request(Get or Post)
- data – Specifies data to be sent to server
- Cache – Whether the browser should cache the requested page
26. What is the use of jQuery filter?
The jQuery filter is used to filter the certain values from the object list based on the criteria. Example is to filter certain products from the master list of products in a cart website.
27. Which program is useful for testing jQuery?
QUnit is used to test jQuery and it is very easy and efficient.
28. What is CDN?
CDN is abbreviated as Content Distribution network and it is said to be a group of companies in different location with network containing copies of data files to maximize bandwidth in accessing the data.
29. What are the two types of CDNs?
There are two types of CDNs:
- Microsoft – Load jQuery from Ajax CDN
- Google – Load jQuery from Google libraries API
30. Which sign is used as a shortcut for jQuery?
Dollar ($) sign is used as a shortcut for jQuery.
31. Is jQuery is a client or server scripting?
jQuery is a client scripting.
32. What is the script build up by jQuery?
jQuery is a Javascript file and it is single javascript file that contains common DOM, event effects and Ajax functions.
33. How can we debug jQuery?
There are two ways to debug jQuery:
Debugger keyword
- Add the debugger to the line from where we have to start debugging and then run Visual Studio in Debug mode with F5 function key.
- Insert a break point after attaching the process
34. What are all the ways to include jQuery in a page?
Following are the ways to include jQuery in a page:
- Local copy inside script tag
- Remote copy of jQuery.com
- Remote copy of Ajax API
- Local copy of script manager control
- Embedded script using client script object
35. What is the use of jQuery.ajax method ()?
jQuery.ajax method is used for asynchronous HTTP requests.
36. Where can we download JQuery?
jQuery javascript can be downloaded from jQuery official website – www.jquery.com
37. Is jQuery is a replacement of JavaScript?
No, jQuery is not a replacement of JavaScript.
38. What is called chaining?
Chaining is used to connect multiple events and functions in a selector.
39. What are the advantages of jQuery?
Following are the advantages of jQuery:
- Just a JavaScript enhancement
- Coding is simple, clear, reusable
- Removal of writing more complex conditions and loops
40. Whether C# code behind can be called from jQuery?
Yes, we can call C# code behind from jQuery.
41. What is the use of jQuery.data() method?
jQuery data method is used to associate data with DOM nodes and JavaScript objects. This method will make a code very concise and neat.
42. What is the difference between onload() and document.ready()?
In a page, we can have only one onload function but we can have more than one document.ready function. Document.ready function is called when DOM is loaded but onload function is called when DOM and images are loaded on the page.
43. What is the use of jQuery each function?
jQuery each function is used to loop through each and every element of the target jQuery object. It is also useful for multi element DOM, looping arrays and object properties.
44. How method can be called inside code behind using jQuery?
$.ajax can be called and by declaring WebMethod inside code behind using jQuery.
45. Which is the fastest selector in jQuery?
ID and Element are the fastest selectors in jQuery.
46. What is the slowest selector in jQuery?
Class selectors are the slowest selectors in jQuery.
47. Where jQuery code is getting executed?
jQuery code is getting executed on a client browser.
48. What is the method used to define the specific character in place of $ sign?
‘NoConflict’ method is used to reference a jQuery and save it in a variable. That variable can be used instead of Sign.
49. Why jQuery is better than JavaScript?
jQuery is a library used for developing Ajax application and it helps to write the code clean and concise. It also handles events, animation and Ajax support applications.
50. What are the types of selectors in jQuery?
There are three types of selectors in jQuery:
- CSS Selector
- XPath Selector
- Custom Selector
jQuery Interview Question
A list of top frequently asked jQuery interview questions and answers are given below.
1) What is jQuery?
jQuery is a fast, lightweight, feature-rich client side JavaScript framework. It has provided a much needed boost to JavaScript. Before jQuery, JavaScript codes were lengthy and bigger, even for smaller functionality.
2) Is jQuery a programming language?
jQuery is not a programming language but a well written JavaScript code. It is used to traverse documents, event handling, Ajax interaction and Animation.
3) What is the difference between JavaScript and jQuery?
The simple difference is that JavaScript is a language while jQuery is a built-in library built of JavaScript. jQuery simplifies the use of JavaScript language.
4) Is jQuery replacement of JavaScript?
No, jQuery is not the replacement of JavaScript. jQuery is written on the top of JavaScript and it is a different library. jQuery is lightweight JavaScript library which is used to interact JavaScript and HTML.
5) Why do we use jQuery?
- It is very easy to learn and use.
- It is used to develop browser compatible web applications.
- It improves the performance of an application.
- It is very fast and extensible.
- It facilitates you to write minimal lines of codes for UI related functions.
- It provides a cross-browser support.
6) What are the effects methods used in jQuery?
These are some effects methods used in jQuery:
- show()
- hide()
- toggle()
- fadeIn()
- fadeOut()
7) Is it possible that jQuery HTML work for both HTML and XML document?
No, jQuery HTML only works for HTML document. It doesn't work for XML documents.
8) What is $() in jQuery library?
The $() function is an alias of jQuery() function. It is used to wrap any object into jQuery object which later facilitates you to call various method defined jQuery object. You can pass a selector string to $() function and it will return jQuery object which contains an array of all matched DOM elements.
9) Is jQuery library used for server scripting or client scripting?
It is a library for client side Scripting.
10) Is jQuery a W3C standard?
No, jQuery is not a W3C standard.
11) What is the starting point of code execution in jQuery?
$(document).ready() function is the starting point of jQuery code. It is executed when DOM is loaded.
12) What is the basic requirement to start with the jQuery?
You need to make reference of its library to start with jQuery. You can download the latest version of jQuery from jQuery.com.
13) Can you use a special character in place of $ (dollar sign) in jQuery?
Yes.
14) Can you use multiple document.ready() function on the same page?
Yes. You can use any number of document.ready() function on the same page.
15) What is the difference between find and children methods?
Find method is used to find all levels down the DOM tree while children method is used to find single level down the DOM tree.
16) What is a CDN?
CDN stands for Content Delivery Network or Content Distribution Network. It is a large distributed systems of servers deployed in multiple data centers across the internet.
17) What is the goal of CDN and what are the advantages of using CDN?
The main 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 visits regularly a site which is using jQuery framework from any of these CDN, it will be cached.
18) How can you use jQuery library in your project?
You can use jQuery library in ASP.Net project from downloading the latest jQuery library from jQuery.com and include the references to the jQuery library file in your HTML/PHP/JSP/Aspx page.
- <script src="_scripts/jQuery-1.2.6.js" type="text/javascript"></script>
- <script language="javascript">
- $(document).ready(function() {
- alert('test');
- });
- </script>
19) What are selectors in jQuery? How many types of selectors in jQuery?
If you want to work with an element on the web page, first you need to find it. Selectors are used to find the HTML elements in jQuery. There are many types of selectors. Some basic selectors are:
- Name: It is used to selects all elements which match with the given element Name.
- #ID: It is used to selects a single element which matches with the given ID
- .Class: It is used to selects all elements which match with the given Class.
- Universal (*): It is used to selects all elements available in a DOM.
- Multiple Elements E, F, G: It is used to selects the combined results of all the specified selectors E, F or G.
- Attribute Selector: It is used to select elements based on its attribute value.
20) What is use of jQuery filter?
: jQuery filter is used to filter the certain values from the object. It filters the result of your original query into specific elements.
21) What are the different types of selectors in jQuery?
There are three types of selectors in jQuery:
- CSS Selector
- Custom Selector
- XPath Selector
22) What is the difference between ID selector and class selector in jQuery?
ID selector and class selector are same like they are used in CSS. ID selector uses ID while class selector uses class to select elements.
If you need to select just one element, use ID selector. If you want to select a group of elements, having same CSS class, use class selector.
23) How to add and remove CSS classes to an element using jQuery?
You can use addclass() jQuery method to add CSS class to an element and removeclass() jQuery method to remove CSS class from an element.
24) Can you write a jQuery code to select all links inside the paragraph?
Yes. You can use <a> tag nested inside paragraph <p> tag to select all links.
25) What is the difference between prop and attr?
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.
26) What are the two types of CDNs?
There are two types of CDN:
- Microsoft: It loads jQuery from AJAX CDN.
- Google: It loads jQuery from Google libraries API.
27) What is the use of animate function in jQuery?
The animate function is used to apply the custom animation effect to elements. Syntax:
- $(selector).animate({params}, [duration], [easing], [callback])
Here,
- "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.
28) How can you disable jQuery animation?
By using jQuery property "jQuery.fx.off" and setting it to true, you can disable jQuery animation.
What is jQuery Selectors? Give some examples.1. jQuery Selectors are used to select one or a group of HTML elements from your web page. |
How can we give face effect in jQuery?1. In jQuery we have three methods to give the fade effect to elements: fadeIn, fadeOut and fadeTo. $(selector).fadeIn(speed,callback)
$("clickme").click(function() |
Explain the animate function.-The animate function is used to apply the custom animation effect to elements. $(selector).animate({params}, [duration], [easing], [callback])
<div id="clickToAnimate">
$('# clickToAnimate’).click(function() |
What is .siblings() method in jQuery?1. When we want to fetch siblings of every elements in the set of matched elements then we can use siblings() method. <ul>
$(‘li.second_item’).siblings().css(‘color’,’blue’);
$(‘li.second_item’).siblings(‘.myitem’).css(‘color’,’blue’); |
Explain width() vs css(‘width’).1. In jQuery, there are two way to change the width of an element. $(‘#mydiv’).css(‘width’,’300px’);
|
What is the use of jQuery.data()?1. jQuery.data() is used to set/return arbitrary data to/from an element. jQuery.data(span, “item”, { val1: 10, val2: "myitem" });
$("label:val1").text(jQuery.data(div, "item").val1); |
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. $(document).ready(function()
$(document).ready(function() |
Explain the each() function.- The each() function specify the function to be called for every matched element. $(selector).each(function (index, element))
$("#clickme").click(function()
|
Explain slideToggle() effect.- slideToggle() effect is used to give animated sliding effect to an element. slideToggle([ duration] [, easing] [, callback])
$("#clickme").click(function() |
What is difference between $(this) and ‘this’ in jQuery?Refer the following example: $(document).ready(function()
|
What is the use of param() method.1. The param() method is used to represent an array or an object in serialize manner. personObj=new Object();
|
What is jQuery.holdReady() function?- By using jQuery.holdReady() function we can hold or release the execution of jQuery’s ready event. jQuery.holdReady(true);
jQuery.holdReady(false);
$.holdReady(true); |
Explain .empty() vs .remove() vs .detach().- .empty() method is used to remove all the child elements from matched elements. $(selector).empty(); |
How to read, write and delete cookies in jQuery?- To deal with cookies in jQuery we have to use the Dough cookie plugin. $.dough("cookie_name", "cookie_value");
$.dough("cookie_name");
$.dough("cookie_name", "remove"); |
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. |
What is Chaining in jQuery?- Chaining is very powerful feature of jQuery. $(document).ready(function()
$(document).ready(function()
|
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. $(document).ready(function()
$(document).ready(function()
|
What is difference between prop and attr?1. In jQuery both prop() and attr() function is used to set/get the value of specified property of an element. <input value="My Value" type="text"/>
|
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”
<script type=”text/javascript”
|
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). .resize([event_data], handler(event_object))
$(window).resize(function() |
How can jquery library be added to pages? Write a basic jquery code?The jquery library is a collection of all the jquery methods. It is stored in the form of a single java script file. Th format of adding a jquery file to an html page is: <head>
<html> |
What are the types of selectors that are used in jquery? Give examples.- Jquery enables the user to select specifically the element that is to be effected. jquery allows the user to select in the following ways: $("p") will select all the <p> elements.
$("[href]") is used to select all elements which have an href attribute. |
How can images be made to appear scrolling one over another?- Jquery provides the user with the ability to change the attributes of a property dynamically. The jquery slide method can be used to change the height of elements gradually. This can be used to give the scroll effect of an image over image. |
What are the various ajax functions?Ajax allows the user to exchange data with a server and update parts of a page without reloading the entire page. Some of the functions of ajax are as follows: $.ajaxSetup({
|
What are the guidelines for an application to follow the principles of progressive enhancement.Progressive enhancement is web development technique that would allow the application to be accessible to any computer with any Internet connection. For an application to work on the principles of progressive enhancement the following rules / guidelines must be met: |
How can events be prevented to work after an ajax request?There are two ways to handle this issue: $('#mydiv').click(function(e)
$('a').click(fn); |
How can an element be checked if it contains a specific class?The hasClass method defined can be used to check if an element actually contains the specified class. $("div").click(function()
if ( $('#myDiv').is('.pretty.awesome') )
|
Why is the block display style used for animations?In html only the block level elements can have custom heights and widths. So when a user defines an animation method for usage such as show, hide, slide up etc the display css property of the block being animated is set to display block style. On completion of the animation the display style of the block would be changed to its original value. This procedure does not work properly for inline elements and the following workarounds can be applied to it: |
What are the approaches of extracting a query string with regular expressions?There are two approaches of doing so: var data = string.replace("http://localhost/view.php?", "");
|
How does jquery store data related to an element?In plain java scripts the information about an element can be stored by adding a domain object model property to the element. This results in memory leak problems in certain browsers. In jquery the user does not has to worry about memory management issues. $('#myDiv').data('keyName', { foo : 'bar' });
$('#myList li').each(function() |
Explain the common methods of sending a request to a server.The two most common methods of sending a request to a server are : |
Create a plugin that would add and remove a class on hover.The plugin can be considered to be simply a new method that can be used by a user to extend the prototype object of a jquery. A plugin performs some actions on a collection of elements. Each method that comes with the jquery core can be considered to be a plugin. (function($) |
Explain the use of the .pushStack() method.The pushStack() method works by accepting an array of DOM elements and pushes them into a stack. This is done so that call to methods like .end() and .andSelf are able to behave correctly. The jquery internally uses this method to keep track of all the previous collections of jquery while using a chain traversing method. Good examples of such methods could be .parents() and .filter(). // select some divs |
How is the deferred method in jquery important in relation to animate method?The .animate() method is used to create animations with other shorthands using it. The queue() method can be used to link together multiple animation methods to create an unique effect. These methods are effective when all the data is available locally and all the methods are executed on as single system only. In case the user wants to use the animation methods on a data that resides on the server and wants to handle at a single go the user can make used of the .deferred method. var my$ = $.sub(); |
Explain some of the key concepts of good code organization patterns.Some of the key concepts that should be followed while: |
How can related code be encapsulated? Give example.The object literal is one of the simplest ways that the user can encapsulate related code together. It helps by removing any anonymous functions from the users code. It can also be used to centralize configuration options. var myFeature = |
Write a code for the implementation of a module pattern.The object literal does not provide any privacy for the methods or properties. The module pattern allows the user to offer privacy to functions and variables. It can be used to set to expose limited API. var feature =(function() |
Write the code to define a RequireJs module with its dependencies.The RequireJS is a dependency management tool that can be used by the user to manage script modules. It can be used to load scripts once a page has been loaded. This helps in evenly distributing the downloads. require.def("my/shirt", |
Explain the use of the $.fn.bind and $.fn.trigger.Both the $.fn.bind and $.fn.triggers are two important jquery methods. They are primarily used with custom events. $(document).bind('myCustomEvent', { foo : 'bar' }, |
What is the Struts2 jQuery plugin and its advantages.The struts2 jquery plugin is used to: <div id="result">Result Div</div>
|