jQuery interview questions and answers – Part8

71. What is the use of jquery .each() function?
The $.each() function is used to iterate over a jQuery object. The $.each() function can be used to iterate over any collection, whether it is an object or an array.

72. What is the difference between jquery.size() and jquery.length?
jQuery .size() method returns number of element in the object. But it is not preferred to use the size()method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call.

73. What is the difference between $(‘div’) and $(‘<div/>’) in jQuery?
$(‘<div/>’) : This creates a new div element. However this is not added to DOM tree unless you don’t append it to any DOM element.
$(‘div’) : This selects all the div element present on the page.

74. How do you select elements with classes?
//use a dot (.) prefix before the class name

75. What selectors are faster? ID or Class?
ID selectors are known to be faster than Class and Element selectors

76. Can you check if an element exists and if so, how?
Yes you can check if an element exists. Here is how:
if($(“#someElement”).length > 0){
//it means it exists if length is greater than 0

77. What are jQuery Methods?
The question on selectors naturally leads to the question on methods. Methods are basically triggers for functions. They can be attached to event handlers to carry out some action.
For example, if you want to add some text after a class – say, an alert to a discount following a paragraph – you can use the after() event handler, like this:
$(“.discount”).after(“<p>Huge discounts on selected merchandize!</p>”);
jQuery is relatively easy to program in and should be easy to clear in an interview for any experienced candidate. However, you will rarely be asked jQuery questions in isolation; you will also need to be thorough with front-end development fundamentals, including a knowledge of advanced CSS3, HTML5, JavaScript, etc.

78. What is the basic used of jQuery() function
->Establish code to be executed when the DOM is ready for manipulation.
->Help as a namespace for global utility functions.
->Create DOM elements from HTML markup.
->Select and wrap DOM elements to operate upon

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

80. What is the difference between parent() and parents() methods in jQuery?
The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree.

Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)

Leave a Reply

Your email address will not be published. Required fields are marked *

4 − = two

Popup Dialog Box Powered By : XYZScripts.com
  • RSS
  • Facebook
  • Google+
  • Twitter