JQuery Interview Questions and Answers

1. What is JQuery?

JQuery is a fast, lightweight, open source and feature rich JavaScript library which helps in interaction between JavaScript and HTML. It simplifies using JavaScript on your website. It is helpful in making interactive and creative web pages easily. It contains all the common DOM, event, effects, and Ajax functions in a single JavaScript file. JQuery file needs to be included from a CDN if you want to use JQuery functionality in your program.

2. What are the features of JQuery library?

Effects and animations, Ajax, Extensibility, DOM element selections functions, Events, CSS manipulation, Utilities - such as browser version and the each function, JavaScript Plug-ins, DOM traversal and modification.

3. Which is better between JQuery and javascript?

JQuery is a concise library for developing Javascript and Ajax programming. With its use, you can make the code simple and reusable. JQuery can also manipulate CSS, quickly handle events, make animations etc. in web applications.

4. Is fade effect possible in JQuery?

Yes, in JQuery there are three methods for the same which are fadeIn(), fadeout() and fadeTo(). For changing the opacity of elements in animation, we use them.

5. What are bind(), live() and delegate() methods?

The bind() method will attach one or more event handler to the elements. This 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. live() function will not work in chaining. It will work only on an selector or an element. delegate() method can work in chaining.

6. JQuery provides various methods to remove elements from DOM. Which are those methods?

These methods are.empty(), .remove() and .detach() . In JQuery, 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 removes all the JQuery data associated with the matched element. detach() method removes selected elements no matter they are text or child nodes but it does not remove JQuery data associated with the matched elements. remove() is faster than empty() or detach() methods.

7. Explain resize() function.

The resize() function is called whenever the browser size is changed. This event can be only used with $(window). Its syntax is .resize([event_data], handler(event_object)). The 'event_data' is the data to be sent to the handler. The 'handler(event_object)' is a function to be called each time when the window is resized.

8. Explain the difference between find() and children() methods.

Find() method is used whenever you want to search more than one level in DOM tree as it can traverse multiple or all levels down the DOM tree but children() can travel only single level down in the DOM tree.

9. What is the difference between size() and length of JQuery?

The basic difference is that size() is a method and length is a property however, both size() and length return the number of elements in an object.

10. What are the 4 parameters used for JQuery Ajax method?

The four parameters which are used are: URL where we need to specify the URL to send the request, type which specifies type of request(Get or Post), data which specifies data to be sent to server and Cache tells us whether the browser should cache the requested page.