jQuery Interview Questions and answers Set – 2

In this tutorial we are providing some set of jQuery Interview Questions and answers and explanation for freshers and professionals, which will help to prepare for technical interviews.

  1. What is the use of jQuery.ajax method ()?

    jQuery.ajax method is used for asynchronous HTTP requests.

  2. Is jQuery is a replacement of JavaScript?

    No, jQuery is not a replacement of JavaScript.

  3. What is the use of jQuery each function?

    jQuery each function is used to loop through each and every element of the target jQuery object. It is also useful for multi element DOM, looping arrays and object properties.

  4. How method can be called inside code behind using jQuery?

    $.ajax can be called and by declaring WebMethod inside code behind using jQuery.

  5. Which is the fastest selector in jQuery?

    ID and Element are the fastest selectors in jQuery.

  6. What is the slowest selector in jQuery?

    Class selectors are the slowest selectors in jQuery.

  7. Where jQuery code is getting executed?

    jQuery code is getting executed on a client browser.

  8. What is the method used to define the specific character in place of $ sign?

    ‘NoConflict’ method is used to reference a jQuery and save it in a variable. That variable can be used instead of Sign.

  9. Why jQuery is better than JavaScript?

    jQuery is a library used for developing Ajax application and it helps to write the code clean and concise. It also handles events, animation and Ajax support applications.

  10. How can jquery library be added to pages? Write a basic jquery code?

    The jquery library is a collection of all the jquery methods. It is stored in the form of a single java script file. The format of adding a jquery file to an html page is:

    <script type="text/javascript" src="jquery.js"></script>

    An example of a JavaScript that will hide all the “p” elements in the page.

    		<script type="text/javascript" src="jquery.js"></script>
     <script type="text/javascript">
     $(document).ready(function() {
     $("button").click(function() {
    <h2>This is a heading</h2>
    This is a paragraph.
    This is another paragraph.
    		<button>Click here</button>
  11. What are the types of selectors that are used in jquery? Give examples.

    – Jquery enables the user to select specifically the element that is to be effected. jquery allows the user to select in the following ways:
    – jquery element selectors : With the use of css selectors the users can select the elements of an html document.

    For ex.

    $("p") will select all the 
    $("p.intro") will select all 
     elements with class="intro" defined in them.
    $("p#demo") this will select all 
     elements with id="demo".

    – jquery attribute selectors: the xpath expressions are used by jquery to select elements of an html document with defined attributes.
    For ex.

    $("[href]") is used to select all elements which have an href attribute.
    $("[href$='.jpg']") can select all elements with an href attribute which will end with ".jpg".
  12. How can images be made to appear scrolling one over another?

    – Jquery provides the user with the ability to change the attributes of a property dynamically. The jquery slide method can be used to change the height of elements gradually. This can be used to give the scroll effect of an image over image.
    The jquery comprises of the following slide methods:

    1. $(selector).slideDown(speed, callback)
    2. $(selector).slideUp(speed, callback)
    3. $(selector).slideToggle(speed, callback)

    – The speed parameter is used to effect the speed of change of the jquery. The parameters for it can be slow, fast , normal and time in milliseconds. The parameter of callback is used to refer to the name of the function to be executed once the completion of function occurs.

  13. What are the various ajax functions?

    Ajax allows the user to exchange data with a server and update parts of a page without reloading the entire page. Some of the functions of ajax are as follows:

    1. $.ajax() : This is considered to be the most low level and basic of functions. It is used to send requests . This function can be performed without a selector.
    2. $.ajaxSetup() : This function is used to define and set the options for various ajax calls.
    For ex.

    	"success":function(data) {

    3. Shorthand ajax methods : They comprise of simply the wrapper function that call $.ajax() with certain parameters already set.
    4. $.getJSON() : This is a special type of shorthand function which is used to accept the url to which the requests are sent. Also optional data and optional callback functions are possible in such functions.