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


11) Can we have multiple document.ready() function on the same page?

 YES. We can have any number of document.ready() function on the same page.


12) Can we use our own specific character in the place of $ sign in jQuery?

Yes. It is possible using jQuery.noConflict().


13) What is jQuery.noConflict?

As other client side libraries like MooTools, Prototype can be used with jQuery and they also use $() as their global function and to define variables.

This situation creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations,

jQuery has introduced jQuery.noConflict().

Syntax:

jQuery.noConflict();  // Use jQuery via jQuery(...)

jQuery(document).ready(function(){

jQuery("div").hide();

});

You can also use your own specific character in the place of $ sign in jQuery.

var $j = jQuery.noConflict(); // Use jQuery via jQuery(...)
$j(document).ready(function(){
   $j("div").hide();
});


14) Is there any difference between onload() and document.ready() function?

document.ready() function is different onload() function for 2 reasons:

We can have more than one document.ready() in a page where we can have only one onload().

document.ready() is called as soon as DOM is loaded where onload() is called when everything

gets loaded on the page that includes DOM,images and all associated resources of the page.


15) What is the difference between .js and .min.js?

jQuery library comes in 2 different versions Development and Production/Deployment. The deployment version is also known as minified version. So .min.js is basically the minified version of jQuery library file. Both the files are same as far as functionality is concerned. but .min.js is quite small in size so it loads quickly and saves bandwidth.


16) Why there are two different version of jQuery library?

 jQuery library comes in 2 different versions:

  1. Development 
  2. Production/Deployment

The development version is quite useful at development time as jQuery is open source and if you want to change something then you can make those changes in development version. But the deployment version is minified version or compressed version so it is impossible to make changes in it. Because it is compressed, so its size is very less than the production version which affects the page load time.


17) What is a CDN?

A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance.


18) Which are the popular jQuery CDN? and what is the advantage of using CDN?

There are 3 popular jQuery CDNs.

      1. Google.

      2. Microsoft

      3. jQuery.

Advantage of using CDN:

  • It reduces the load from your server.
  • It saves bandwidth. jQuery framework will load faster from these CDN.
  • The most important benefit is it will be cached, if the user has visited any site which is using jQuery framework from any of these CDN.


19) What are selectors in jQuery and how many types of selectors are there?

 To work with an element on the web page, first we need to find them. To find the html element in jQuery we use selectors. There are many types of selectors but basic selectors are:

  1. Name: Selects all elements which match with the given element Name.
  2. #ID: Selects a single element which matches with the given ID
  3. .Class: Selects all elements which match with the given Class.
  4. Universal (*): Selects all elements available in a DOM.
  5. Multiple Elements E, F, G: Selects the combined results of all the specified selectors E, F or G.
  6. Attribute Selector: Select elements based on its attribute value.


20) How do you select element by ID in jQuery?

To select element use ID selector. We need to prefix the id with "#" (hash symbol). For example, to select element with ID "txtName" .

Syntax:

$('#txtName')