Interview Questions

These are very common jQuery interview questions which is generally asked in interview. I try to answer very sort and correct that's why you can remember it easily.

What is jQuery?

jQuery is a fast, small, and feature-rich JavaScript library. jQuery simplifies HTML document traversing, event handling, animating, and Ajax request for website development.

Why we use jquery

jQuery is easy to learn as well as very simple to use. It is browser independent. It makes your application dynamic at client side. jQuery is a very fast and small. It save dozens of lines of code.

What are jQuery Selectors?

jQuery selectors used to catch the particular html element which we will manipulate.

What is callback?

A callback is a plain JavaScript function passed to some method as an argument or option. Generally we called this function when a certain task has been completed.

What is difference between .on() and .bind()?

The .bind() method attach the same event handler to every matched element by the selector. It doesn't work for dynamically added elements. Where as .on() method work for dynamically added elements. It is good when dealing with a large selection.

What are the different type of selectors in jquery?

There are many type selectors in jQuery but the most popular are:
1. ID selector
2. Class selector
3. Element selector
4. Attribute selector
5. :checked selector

What is difference between $(this) and this keyword in jQuery?

this refers to a to a DOM element and $(this) refers to a jQuery object.

What is difference between detach() and remove() method in jQuery?

This function remove all elements in the wrapped set from the page DOM.
This function work same like remove() method but it not remove the event of that element.

How do you add and remove class to an element using jQuery?

To add a class we use addClass('classname') method and to remove a class we use removeClass('classname') method.

What is difference between == and ===

When we use triple equal it also check the their type(data type).
1 == "1" // true.
1 === "1" // false

What is difference between parents and closest in jquery?

closest() return the first element that matches the selector where as parents return all element that matches the selector
. Both travel up the DOM tree.

What is difference between parent and parents in jquery

parent() return just the parent element where as parents return all element that matches the selector.

What is event bubbling?

When any event fire on a particular element it start to fire same event on its parent element is called event bubbling. stopPropagation() is used to prevent the event bubbling.

What are some of the common methods in jQuery

There are various method in jQuery. Some popular are:
1. val()
2. height()
3. width()
4. remove()
5. html()
6. css()
7. addClass
8. attr()
9. find()
10. bind()