1. What is jQuery?
jQuery is not a programming language but a well written JavaScript code. It is a JavaScript code, which do document traversing, event handling, Ajax interactions and Animations.

2. Why jQuery is needed?
jQuery is needed for the following list:

Used to develop browser compatible web applications
Improve the performance of an application
Very fast and extensible
UI related functions are written in minimal lines of codes

3. What is $() in jQuery library?
The $() function is an alias of jQuery() function, at first it looks weird and makes jQuery code cryptic, but once you get used to it, you will love it’s brevity. $() function is used to wrap any object into jQuery object, which then allows you to call various method defined jQuery object. You can even pass a selector string to $() function, and it will return jQuery object containing an array of all matched DOM elements.

4. You have five <span> element in your page? How do you change font color and size using jQuery?
Another fundamental jQuery question based on selector. jQuery supports different kinds of selector e.g. ID selector, class selector and tag selector. Since in this question nothing has been mentioned about ID and class, you can use tag selector to change color and size of text using elements. Example


$( “span” ).css( “color”, “red” );
$( “span” ).css( “font-size”, “20px” );

5. How to use comments in JQuery?
There is two type of comments 1. Single line comment and 2. Multiline comment
Single line comments start with //.
Multi-line comments start with /* and end with */.

6. How do you hide an image on a button click using jQuery?
jQuery provides good support for handling events like button click. You can use following code to hide an image, found using Id or class. You can use object hide() method. Example

7. Difference between $(this) and this keyword in jQuery?
$(this) returns a jQuery object, on which you can call several jQuery methods e.g. text() to retrieve text, val() to retrieve value etc, while this represent current element, and it’s one of the JavaScript keyword to denote current DOM element in a context. You can not call jQuery method on this, until it’s wrapped using $() function i.e. $(this).

8. What is difference between hide(), detach() and remove() method in jQuery?
hide() sets the matched elements’ CSS display property to none.
remove() removes the matched elements from the DOM completely.
detach() is like remove(), but keeps the stored data and events associated with the matched elements.

To re-insert a detached element into the DOM, simply insert the returned jQuery set from detach():
var span = $(‘span’).detach();

9. What is main advantage of loading jQuery library using CDN?
CDN has many advantages including reducing server bandwidth and faster download, one of the most important is that, if browser has already downloaded same jQuery version from same CDN, than it won’t download it again. Since now days, almost many public websites use jQuery for user interaction and animation, there is very good chance that browser already have jQuery library downloaded.

10. What is the advantage of using minimised version of jQuery?
Efficiency of web page increases when minimised version of jQuery is used.min.js file will be more than 50% less than the normal js file. Reduction in the file size makes the web page faster.

11. Which operating system is more compatible with jQuery?
Mac, Windows and Linux are more compatible with the jQuery.

12. Which command will give a version of jQuery?
The command $.ui.version returns jQuery UI version.

13. What is the difference between find and children methods?
Find method is used to find all levels down the DOM tree but children find single level down the DOM tree.

14. What are the basic selectors in jQuery?
Following are the basic selectors in jQuery:

Element ID
CSS Name
Tag Name
DOM hierarchy

15. 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.
Example: Here we are traversing the collection object by key , value

var obj = {
“flammable”: “inflammable”,
“duh”: “no duh”

$.each( obj, function( key, value ) {
alert( key + “: ” + value );

16. Which one is more efficient, document.getElementbyId( “myId”) or $(“#myId)?
First one because its direct call to JavaScript engine.

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

18. What is CDN?
CDN is abbreviated as Content Distribution network and it is said to be a group of companies in different location with network containing copies of data files to maximise bandwidth in accessing the data.

19. What are the two types of CDNs?
There are two types of CDNs:

Microsoft – Load jQuery from Ajax CDN
Google – Load jQuery from Google libraries API
20. What are the four parameters used for jQuery Ajax method?
The four parameters are
URL – Need to specify the URL to send the request
type – Specifies type of request(Get or Post)
data – Specifies data to be sent to server
Cache – Whether the browser should cache the requested page

21. How can we debug jQuery?
There are two ways to debug jQuery:

Debugger keyword
Add the debugger to the line from where we have to start debugging and then run Visual Studio in Debug mode with F5 function key.
Insert a break point after attaching the process.

22. What is the difference between onload() and document.ready()?
In a page, we can have only one onload function but we can have more than one document.ready function. Document.ready function is called when DOM is loaded but onload function is called when DOM and images are loaded on the page.

58 total views, 1 views today