JQuery Interview Questions

JQuery Interview Questions

What is Jquery

A lightweight JavaScript library which gives a quick and simple method for HTML DOM traversing and manipulation, its event handling, its client-side animations, and so on.

Quick Questions About Jquery
 is written InJava Script
is aJavascript library designed to simplify HTML DOM, tree traversal and manipulation.
 is developed ByJohn Resig
Designed forSelect DOM elements,Create Animations,Handle events,develop Ajax applications
 Current Stable release3.4.1
Download JQuery Interview Questions PDF

Below are the list of Best JQuery Interview Questions and Answers

jQuery is a lightweight JavaScript library which gives a quick and simple method for HTML DOM traversing and manipulation, its event handling, its client-side animations, and so on. One of the best features of jQuery is that jQuery supports an efficient way to implement AJAX applications because of its lightweight nature and make normalize and efficient web programs.

There are many advantages of using JQuery. Some of them are :

  • It is more like a JavaScript enhancement so there is no overhead in learning a new syntax.
  • It has the ability to keep the code simple, readable, clear and reusable.
  • Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
  • It would eradicate the requirement for writing complex loops and DOM scripting library calls.
  • Event detection and handling.
  • Tons of plug-ins for all kind of needs.

There are 3 types of selectors in Jquery

  • CSS Selector
  • XPath Selector
  • Custom Selector
  • jQuery Selectors are used to select one or a group of HTML elements from your web page.
  • jQuery support all the CSS selectors as well as many additional custom selectors.
  • jQuery selectors always start with dollar sign and parentheses: $()

There are three building blocks to select the elements in a web document.

1. Select elements by tag name


It will select all the div elements in the document.

2. Select elements by ID


It will select single element that has an ID of abc.

3. Select elements by Class


It will select all the elements having class xyzClass.

jQuery is very compact and well-written JavaScript code that increases the productivity of the developer by enabling them to achieve critical UI functionality by writing very less amount of code.

It helps to

  • Improve the performance of the application
  • Develop most browser compatible web page
  • Implement UI related critical functionality without writing hundreds of lines of codes
  • Fast
  • Extensible – jQuery can be extended to implement customized behavior

Other advantages of jQuery are

  • No need to learn fresh new syntax’s to use jQuery, knowing simple JavaScript syntax is enough
  • Simple and Cleaner code, no need to write several lines of codes to achieve complex functionality.

In jQuery, there is two way to change the width of an element. One way is using .css(‘width’) and other way is using .width().

For example

  • The difference in .css(‘width’) and .width() is the data type of value we specify or return from the both functions.
  • In .css(‘width’) we have to add “px” in the width value while in .width() we don’t have to add.
  • When you want to get the width of “mydiv” element then .css(‘width’) will return ‘300px’ while .width() will return only integer value 300.

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.

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.

For example


Above code will not work using live() method. But using delegate() method we can accomplish this.


The param() method is used to represent an array or an object in serialize manner.
While making an ajax request we can use these serialize values in the query strings of URL.


$.param(object | array, boolValue)

“object | array” specifies an array or an object to be serialized.

“boolValue” specifies whether to use the traditional style of param serialization or not.


personObj=new Object();

It will set the text of span to “name=Ravi&age=28&dep=IT”

jQuery .size() method returns number of element in the object. But it is not preferred to use the size() method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call.

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:
  • Delete cookie:
    $.dough(“cookie_name”, “remove”);

this and $(this) references the same element but the difference is that “this” is used in traditional way but when “this” is used with $() then it becomes a jQuery object on which we can use the functions of jQuery.?

In the example given, when only “this” keyword is used then we can use the jQuery text() function to get the text of the element, because it is not jQuery object. Once the “this” keyword is wrapped in $() then we can use the jQuery function text() to get the text of the element.

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:

$.ajax(): This is considered to be the most low level and basic of functions. It is used to send requests . This function can be performed without a selector.

$.ajaxSetup(): This function is used to define and set the options for various ajax calls.

For example.


Shorthand ajax methods: They comprise of simply the wrapper function that call $.ajax() with certain parameters already set.

$.getJSON(): this is a special type of shorthand function which is used to accept the url to which the requests are sent. Also optional data and optional callback functions are possible in such functions.

  • .empty() method is used to remove all the child elements from matched elements.
  • .remove() method is used to remove all the matched element. This method will remove all the jQuery data associated with the matched element.
  • .detach() method is same as .remove() method except that the .detach() method doesn’t remove jQuery data associated with the matched elements.

.remove() is faster than .empty() or .detach() method.



There are two ways to handle this issue:
Use of event delegation: The event delegation technique works on principle by exploiting the event bubbling. It uses event bubbling to capture the events on elements which are present anywhere in the domain object model. In jquery the user can make use of the live and die methods for the events delegation which contains a subset of event types.
For example. handling even delegation, handling of clicks on any <a> element:

if( $(e.target).is('a') )

Event rebinding usage: When this method is used it requires the user to call the bind method and the added new elements.

$('#mydiv a').click(fn);

Document.ready() function is different from body onload() function because off 2 reasons.

  • We can have more than one document.ready() function in a page where we can have only one onload function.
  • Document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.

Features of Jquery

  • One can easily provide effects and can do animations.
  • Applying / Changing CSS.
  • Cool plugins.
  • Ajax support
  • DOM selection events
  • Event Handling