Essential jQuery Interview Questions - IT and Government Jobs @ career updates latest

Thursday, 13 August 2015

Essential jQuery Interview Questions

1.Explain what the following code will do

$( "div#first, div.first, ol#items > [name$='first']" )

2.What’s the deal with the $ in jQuery? What is it and what does it mean?

3.Given the following HTML:

<div id="expander"></div>
and the following CSS:

div#expander{
  width: 100px;
  height: 100px;
  background-color: blue;
}
Write code in jQuery to animate the #expander div, expanding it from 100 x 100 pixels to 200 x 200 pixels over the course of three seconds.


4.What is method chaining in jQuery? Provide an example.

What advantages does it offer?


5.Explain what the following code does:

$( "div" ).css( "width", "300px" ).add( "p" ).css( "background-color", "blue" );

6.What is the difference between jQuery.get() and jQuery.ajax()?

7.Which of the two lines of code below is more efficient? Explain your answer.

document.getElementById( "logo" );

8.Explain and contrast the usage of event.preventDefault() and event.stopPropagation(). Provide an example.

9.What selector would I use to query for all elements with an ID that ends with a particular string? Also, how would I modify the selector to retrieve only <div> elements whose IDs end with that same string? Provide an example.

10.jQuery provides a useful .clone() method to create a deep copy of matching elements.

11.Explain the .promise() method in jQuery, including how and why it would be used.

12.What is the proper way in jQuery to remove an element from the DOM before its Promise is resolved?


13.Explain the difference between the .detach() and .remove() methods in jQuery.