jQuery interview questions and answers – Part9
81. What is the difference between eq() and get() methods in jQuery?
eq() returns the element as a jQuery object. This method constructs a new jQuery object from one element within that set and returns it. That means that you can use jQuery functions on it.
get() return a DOM element. The method retrieve the DOM elements matched by the jQuery object. But as it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can’t be used. Find out more here.
82. What is called chaining?
Chaining is used to connect multiple events and functions in a selector.
83. How method can be called inside code behind using jQuery?
$.ajax can be called and by declaring WebMethod inside code behind using jQuery.
84. Can we call C# code behind using jQuery?
Yes, we can call C# code from jQuery as it supports .net application.
85. What is the use jQuery.data method?
jQuery.data methods is used to associate the data with the DOM nodes and the objects. This data method makes the jQuery code clear and concise.
86. What is the use of each function in jQuery?
Each function is used to iterate each and every element of an object. It is used to loop DOM elements, arrays and the object properties.
87. What is the difference between size and length of jQuery?
Size and length both returns the number of element in an object. But length is faster than the size because length is a property and size is a method.
88. What is event.preventDefault()?
This is a method that stops the default action of an event from happening – for instance stops a link from following the URL.
89. What do you know about chaining in jQuery?
It is a feature of jQuery that allows you to connect multiple functions and events on selectors. Although it makes your code shorter and maybe easier to manage, it makes testing a little bit challenging. It is advisable to use it with caution.
90. How did you become the creator of jQuery UI? Whats the story behind that?
I initially came to the jQuery project while searching for a good solution to power the web applications of a big german client. As I was specifically responsible for building out a lot of the frontend logic and interaction, I quickly found out about Interface, a collection of interface plugins developed by Stefan Petre. I soon realized there was a lot of work involved to make it stable for our environment, so I invested a lot of time into bugfixes and feature stabilization, and later even planned the next generation of Interface, Interface 2 with Stefan. However, it was then that Stefan moved on with founding his own business and ran out of time, so Interface was discontinued.
I would build the first version of an official jQuery interface addition, since I already had quite some experience from working on Interface. He and the jQuery community wanted to have it done in three months for the Ajax Experience conference in Boston, which was nearly impossible after a quick analysis of my workload. I had a day job, and I estimated I would need to work on it 3-4 hours everyday. After some days of consideration, I finally said ‘yes’, and for a three month period woke up every day at 6am to work for 3 hours on jQuery UI and then go to my day job. Now I can say that it was worth it.