jQuery Interview Questions
1 .
What is Qunit?
QUnit is a powerful, easy-to-use JavaScript unit testing framework. It's used by the jQuery, jQuery UI, and jQuery Mobile projects and is capable of testing any generic JavaScript code.
2 .
What is jQuery.noConflict?
Usually, JS functions and variables use $ as a name. In jQuery, $ is just an alias for jQuery, so we don’t need to use $. If we have to use a JS library along with jQuery, the control of $ is given to the JS library. To give this control, we use jQuery.noConflict(). It is also used to assign a new name to a variable.
 
var newname = jQuery.noConflict();
3 .
Explain the various Ajax functions available in jQuery?
There are many methods like :
 
.ajaxStart() : register the handler to be called when the first Ajax request begins.
.ajaxStop() : register the handler to be called when all requests are complete.
.ajaxSuccess() : register the handler to be called when an Ajax request is successfully completed..
4 .
What is the difference between width() vs css(‘width’) in jQuery?
CSS(‘width’) returns the width value in pixels, whereas width() returns the integer (without the unit values). For example:
 
div{
width: 20cm;
}
If you print the values:
 
$(this).width();
$(this).css(‘width’);
 
you will get the values like 756 and 756px respectively. Note that though we specified width in cm, it is converted to pixel (px) for output purposes.
5 .
What is the difference between bind() vs live() vs delegate() methods in jQuery?
bind() : this method registers the event handler directly to the required DOM element.
$(“#members a”).bind(“click”, function(f){….});
This means any matching anchors will have this event handler attached!
 
live() : this method attaches the event handler to the root of the document. This means one handler can be used for all events that propagated to the root. The handler is thus attached only once.
 
delegate() : in this method, you can choose where to attach the handler. This is the most efficient and robust method for delegation.
 
Eg:
$(“#members”).delegate(“ul li a”, “click”, function(f){….});
6 .
Explain the difference between jquery.size() and jquery.length?
In jquery both works and gives the same result but now the time in current version of jquery we use the jquery.length because jquery.size is depreciated.
 
Below is the some points about this properties :
 
jquery.size() and jquery.length() both returns the number of element in an object.
 
jquery.length() property is faster as compared to jquery.size() method.
 
jquery.length() property prefered compared to size() because it does not have overhead of a function call.
 
Very significant difference is that jquery.size() is depreciated so we always use jquery.length() instead of jquery.size().
 
For Examples: Counts the number of unordered list li on the page to demonstrate the same according to the jQuery documentation.
 
$('li').size();

$('li').length;// faster
 
7 .
What is jQuery Datepicker in jQuery?
 It is a plugin/widget that adds datepicker functionality in HTML pages. It is highly configurable and can be customized for date format, language, restricting date selection, etc. Refer to this jQuery documentation for datepicker options.
8 .
Difference between Map and Grep function in jQuery?
Map function translates a set of elements into another set of values in a jQuery array that may or may not have the elements. The map is called as :
$(“<element>”).map(<function to execute for elements in the object>)

Grep, on the other hand, finds an element in an array.
jQuery.grep(myArr, function(){}
9 .
Difference between prop and attr?
Both attr() and prop() can be used to set or get an element’s value, however attr() returns the original (default) value whereas prop() returns the most recent (current) value. For example, if a text input had an initial value of ‘Male,’ and later it was changed by the user to ‘female,’ attr() will return the value as ‘Male’ whereas prop() will return the value as ‘female.’
10 .
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