jQuery Interview Questions
1 .
Which is the fastest selector in jQuery?
ID and Element are the fastest selectors in jQuery.
2 .
What is the slowest selector in jQuery?
Class selectors are the slowest selectors in jQuery.
3 .
What is chaining in jQuery?
Chaining is a  powerful feature of jQuery. Chaining means specifying multiple functions and/or selectors to an element.
 
Chaining reduces the code segment and keeps it very clean and easy to understand. Generally chaining uses the jQuery built in functions that makes compilation a bit faster.
 
By using chaining we can write the above code as follows :  

$(document).ready(function() {  
    $("#div2").html($("#txtBox").prop("readonly")) + '</br>';  
    $("#div3").html($("#txtBox").attr("readonly"));  
});  
4 .
How to work with parent(), children() and siblings() methods in jQuery?
The parent() function returns the parent of the selected element by calling the jQuery parent() function. The siblings() function returns all the siblings of given HTML elements.
5 .
What is jQuery.holdReady() function?
jQuery.holdReady() function is what we can hold or release the execution of jQuery's ready event. This method should be called before we run the ready event. To delay the ready event, we need to call jQuery.holdReady(true);
 
When we want to release the ready event then we need to call jQuery.holdReady(false);
 
This function is helpful when we want to load any jQuery plugin before the execution of the ready event or want to perform certain events/functions before document.ready() loads .
6 .
What is resize() function in jQuery?
The resize event occurs when the size of the browser window is changed. jQuery resize() Method attaches window element to an event handler function and this event handler function executes when the resize event occurs.
 
jQuery resize() Method Syntax :
$(window).resize(function(){
 //code that executes when the resize event occurs.
});
7 .
Differentiate the concepts of .js and .min.js?
The jQuery library has two different versions Development and Production. The other name for the deployment version is minified version. 
 
Considering the functionality, both the files are much similar to each other. Being smaller in size, the  .min.js   gets loaded quickly saving the bandwidth.
8 .
Elaborate jQuery Ajax Events.
Ajax methods trigger an event handler that results in jQuery Ajax Events. Some of the examples of jQuery Ajax Events are as listed below.
 
These events are categorized into local events and global events.
 
1. ajaxStart() : It is a Global Event, This event triggers as a result of starting of an Ajax request, provided no other Ajax request currently running.

2. beforeSend() : It is a Local Event, as the name indicates, this event gets invoked before Ajax request starts, thereby allowing to modify XMLHttpRequest objects.

3. ajaxSend() : It is a Global Event, and this event gets called before the Ajax request is run.

4. success() : It is a Local Event. This event triggers only if the Ajax request was successfully sent ( i.e. while sending Ajax request, the event does not display any error from the server or from data).

5. ajaxSuccess() : It is a Global Event, triggers only if the request sent was successful.

6. error() : It is a Local Event, that gets triggered if an error occurs while executing the request. (You can have either error or a success callback while sending Ajax request)

7. ajaxError() : It is a Global Event, which behaves the same as its local counterpart error() event.

8. complete() : It is a Local Event. This event gets called regardless of the request being successful or result in an error, and complete callbacks are received, even for synchronous requests.

9. ajaxComplete() : It is a Global Event, which behaves the same as its local counterpart complete() event, even for synchronous requests.

10. ajaxStop() : It is a Global Event, that gets triggered when no Ajax requests are still being processed/ pending for processing.
9 .
Explain the different ways in which we can debug jQuery.
There are few ways in which we can debug jQuery code.
 
Modern-day browsers such as Google Chrome, Mozilla Firefox, Opera and Safari have built-in Javascript debugger. To debug the jQuery code, Press F12 from your keyboard and the browser with the built-in debugger will open a UI, wherein select the ‘Console’ menu. The error will be displayed in the console menu if any.
 
You can write console.log() into the code to get the error text, you can also write debugger; in between the code line, due to debugger the script will start in debug mode, pressing F12 into the browser will open console which will debug the code, pressing F10 will read values of the jQuery objects, and this is how we can debug jQuery code.
10 .
How jQuery stores data related to an element?
jQuery.data() method aids in attaching any type of data to DOM elements, free from memory leaks. jQuery makes sure that data is removed along with the DOM elements removed via jQuery methods.
 
Code for Storing and retrieving data related to an element.
$('#myDiv').data('keyName', { foo : 'bar'});
$('#myDiv').data('keyName'); // { foo : 'bar'}