JQUERY Interview Questions and Answers

jQuery is the lightweight, write less and do more JavaScript library.The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation..

1) What is the difference between jquery.size() and jquery.length?

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.

2) Explain .empty() vs .remove() vs .detach()?

.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.

But From these three methods : .remove() is faster than .empty() or .detach() method.

Syntax : $(selector).empty();



3) What is the use of param() method?

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.

Syntax : $.param(object | array, boolValue)

4) 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.

2) jQuery support all the CSS selectors as well as many additional custom selectors.

3) jQuery selectors always start with dollar sign and parentheses: $().

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

i) Select elements by tag name Example : $(div)

ii) Select elements by ID Example : $(“#abc”)

iii) Select elements by Class Example : $(“.xyzClass”)

5) Explain width() vs css(‘width’)?

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 : $('#mydiv').css('width','300px');


6) What are the methods used to provide effects?

Some of the effects methods are:

1) Show()

2) Hide()

3) Toggle()

4) FadeIn()

5) FadeOut()

7) 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.

8) What are the basic selectors in jQuery?

Following are the basic selectors in jQuery:

  • Element ID
  • CSS Name
  • Tag Name
  • DOM hierarchy

9) How JavaScript and jQuery are different?

JavaScript is a language While jQuery is a library built in the JavaScript language that helps to use the JavaScript language.

10) Is jQuery a library for client scripting or server scripting?

It is for Client side scripting.