{"id":10375,"date":"2016-02-02T15:23:31","date_gmt":"2016-02-02T13:23:31","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=10375"},"modified":"2017-12-21T15:35:06","modified_gmt":"2017-12-21T13:35:06","slug":"jquery-interview-questions-answers","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/","title":{"rendered":"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List"},"content":{"rendered":"<p>Without a doubt, jQuery has given a much needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery came into the picture, we used to write lengthy JavaScript code not just for bigger but even for smaller functionality. That code was at times both difficult to read and maintain. Having written JavaScript before using this excellent library, we realized the true power of jQuery.<\/p>\n<p>This article has been designed specially to get you acquainted with the nature of questions you may encounter during your interview. Normally questions start with some basic concept of the subject and later continue based on further discussion and what the candidate answers. I hope these questions serve as a quick revision to provide strength to your skills.<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;qGGDqWnle19VavkM&#8217;]<\/p>\n<div class=\"toc\">\n<h3 style=\"margin-top: 0\"><strong>Table Of Contents<\/strong><\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. jQuery: An Overview<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#what-is-jquery\">1.1 What is jQuery?<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#why-use-jquery\">1.2 Why you should be using jQuery?<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#jquery-selectors\">1.3 jQuery Selectors<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#jquery-workflow\">1.4 Basic Workflow<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#jquery-family\">1.5 The jQuery Family<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#introductory\">2. Introductory Questions<\/a><\/dt>\n<dt><a href=\"#methods-functions\">3. Methods\/Functions Questions<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#similar-methods\">3.1 Similar Methods Comparison<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#explain-methods\">3.2 Function Explanations<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#find-methods\">3.3 What is the method we use to&#8230;?<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#code\">4. Code Questions<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#given-code\">4.1 Given Code Questions<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#write-code\">4.2 Writing Code Questions<\/a><\/dt>\n<\/dl>\n<\/dd>\n<\/dl>\n<dl>\n<dt><a href=\"#ajax\">5. AJAX Related Questions<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#general-ajax\">5.1 General AJAX Questions<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#technical-ajax\">5.2 Technical AJAX Questions<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#important\">6. Questions on Important Concepts<\/a><\/dt>\n<dt><a href=\"#general\">7. General Questions<\/a><\/dt>\n<dt><a href=\"#conclusion\">8. To Conclude<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><strong><a name=\"introduction\"><\/a>1. jQuery: An Overview<\/strong><\/h2>\n<h3><strong><a name=\"what-is-jquery\"><\/a>1.1 What is jQuery?<\/strong><\/h3>\n<p>JQuery is a cross-browser lightweight JavaScript library. In simple words jQuery has been designed to make navigation to any element easier, or adding\/invoking event handlers on your HTML page and also simplify the way you access the elements in your web pages, provide help in working with client-side events, enable visual effects like animation, and make it easier to use Ajax in your applications.<\/p>\n<p>A quick look at what is available in jQuery:<\/p>\n<p>\u2022 Cross-browser support and detection.<br \/>\n\u2022 AJAX functions<br \/>\n\u2022 CSS functions<br \/>\n\u2022 DOM manipulation<br \/>\n\u2022 DOM transversal<br \/>\n\u2022 Attribute manipulation<br \/>\n\u2022 Event detection and handling.<br \/>\n\u2022 JavaScript animation<br \/>\n\u2022 Hundreds of plugins for pre-built user interfaces, advanced animations, form validation, etc.<br \/>\n\u2022 Expandable functionality using custom plugins.<\/p>\n<figure id=\"attachment_10415\" aria-describedby=\"caption-attachment-10415\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-1.jpg\" rel=\"attachment wp-att-10415\"><img decoding=\"async\" class=\"wp-image-10415 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-1.jpg\" alt=\"jquery-qa-1\" width=\"820\" height=\"600\" \/><\/a><figcaption id=\"caption-attachment-10415\" class=\"wp-caption-text\">jQuery &#8211; Write Less, Do More!<\/figcaption><\/figure>\n<p>jQuery is fast, lightweight and feature-rich client side JavaScript Library\/Framework which helps in to traverse HTML DOM, make animations, add Ajax interaction, manipulate the page content, change the style and provide cool UI effect.<\/p>\n<h3><strong><a name=\"why-use-jquery\"><\/a>1.2 Why you should be using jQuery?<\/strong><\/h3>\n<p>Based on the manipulation of the HTML DOM (Document Object Model) and designed to simplify the client-side scripting of HTML, jQuery incorporates parts of HTML and CSS. Thousands of companies and individuals are on the jQuery bandwagon, and you should be, too.<\/p>\n<h4><strong>1. jQuery promotes simplicity<\/strong><\/h4>\n<p>Developers find jQuery intuitive and easy to learn &#8212; this library is built on shorter, simpler code, after all. With simple syntax and open coding standards, developers can shorten the time it takes to deploy an application or site.<\/p>\n<p>In addition, developers don&#8217;t have to be experts in programming or Web design to create great styles for their sites. Any developer who has spent hours coding and testing CSS files will surely appreciate the simple implementation that jQuery brings to the table.<\/p>\n<h4><strong>2. jQuery elements display even when JavaScript is disabled<\/strong><\/h4>\n<p>If Adobe Flash isn&#8217;t installed on any given browser, certain parts of the page may render incorrectly, if they render at all. This is not only unpleasant for the user; it forces developers to spend extra time coding for the browsers that lack the Flash plug-in, which adds to development time.<\/p>\n<p>Not so with jQuery. Manipulating the HTML DOM has become the most widely accepted practice of manipulating a Web page so content will be rendered even if JavaScript is disabled in the browser. Since the HTML DOM is always present, there&#8217;s no more worrying about browser settings either.<\/p>\n<h4><strong>3. jQuery pages load faster<\/strong><\/h4>\n<p>Google and other search engines using page load time as one of the many factors affecting SEO. For this, and many other reasons, every developer should strive to make code as light and concise as possible.<\/p>\n<p>The best way to do this is to reduce the size of your code. If your site is coded with an HTML and CSS base, you can easily make uniform adjustments to your code that will reduce the size. Like CSS, jQuery files are generally stored separately from the Web page itself. This lets developers make modifications across the entire site through one central repository instead of search through folder structures. This is a core benefit of CSS coding, and it is a proven success.<\/p>\n<p>In addition, jQuery gives you the option of loading div tags only when you need them. If you are taking measures to improve the speed of your website, then you may consider loading only the necessary div tags needed for your page load event. This way, you can display only what a user needs to see right away and have the rest of your division elements load as they are needed.<\/p>\n<h4><strong>Moreover<\/strong><\/h4>\n<p>\u2022 The price is right. The jQuery library is free.<br \/>\n\u2022 It&#8217;s light. Since jQuery pushes content to the client, it therefore reduces the wait time for server response.<br \/>\n\u2022 It works anywhere. HTML5 is cross-browser compatible-it will work on any browser, mobile phone or tablet.<br \/>\n\u2022 There&#8217;s a low learning curve. Since it&#8217;s based on plain old JavaScript, developers can learn jQuery fast.<br \/>\n\u2022 Finally, jQuery is SEO friendly and CSS3 compliant.<\/p>\n<h3><strong><a name=\"jquery-selectors\"><\/a>1.3 jQuery Selectors<\/strong><\/h3>\n<p>jQuery selectors are one of the most important parts of the jQuery library.<\/p>\n<p>jQuery selectors allow you to select and manipulate HTML element(s). They are used to &#8220;find&#8221; (or select) HTML elements based on their id, classes, types, attributes, values of attributes and much more. It&#8217;s based on the existing CSS Selectors, and in addition, it has some own custom selectors. All selectors in jQuery start with the dollar sign and parentheses: <code>$()<\/code>.<\/p>\n<figure id=\"attachment_10429\" aria-describedby=\"caption-attachment-10429\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-3.jpg\" rel=\"attachment wp-att-10429\"><img decoding=\"async\" class=\"wp-image-10429 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-3.jpg\" alt=\"jquery-qa-3\" width=\"820\" height=\"324\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-3.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-3-300x119.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-3-768x303.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-10429\" class=\"wp-caption-text\">An example of how a DOM element can be selected using jQuery!<\/figcaption><\/figure>\n<h4><strong>\u2022 All Selectors<\/strong><\/h4>\n<p><code>$(\"*\")<\/code> \/\/ find everything (Selectors return a pseudo-array of jQuery elements)<\/p>\n<h4><strong>\u2022 Basic Selectors<\/strong><\/h4>\n<p>1. By Tag:<br \/>\n<code>$(\"h1\")<\/code> \/\/ &lt;h1&gt;Web Code Geeks&lt;\/h1&gt;<\/p>\n<p>2. By ID:<br \/>\n<code>$(\"#username\")<\/code> \/\/ <span id=\"username\">Pete<\/span><\/p>\n<p>3. By Class:<br \/>\n<code>$(\".menu\")<\/code><\/p>\n<h4><strong>\u2022 More Precise Selectors<\/strong><\/h4>\n<p><code>$(\"div.main\")<\/code> \/\/ tag and class<br \/>\n<code>$(\"table#main\")<\/code> \/\/ tag and id<\/p>\n<h4><strong>\u2022 Combination of Selectors<\/strong><\/h4>\n<p><code>$(\"#container, .f_left\")<\/code> \/\/ find by id + by class<br \/>\n<code>$(\"h1, h2, h3, div.container\")<\/code> \/\/ multiple combination<\/p>\n<h4><strong>\u2022 Hierarchy Selectors<\/strong><\/h4>\n<p><code>$(\"table td\")<\/code> \/\/ descendants<br \/>\n<code>$(\"tr &gt; td\")<\/code> \/\/ children<br \/>\n<code>$(\"label + input\")<\/code> \/\/ next<br \/>\n<code>$(\"#content ~ div\")<\/code> \/\/ siblings<\/p>\n<h4><strong>\u2022 Selection Index Filters <\/strong><\/h4>\n<p><code>$(\"tr:first\")<\/code> \/\/ first element<br \/>\n<code>$(\"tr:last\")<\/code> \/\/ last element<br \/>\n<code>$(\"tr:lt(2)\")<\/code> \/\/ index less than<br \/>\n<code>$(\"tr:gt(2)\")<\/code> \/\/ index gr. than<br \/>\n<code>$(\"tr:eq(2)\")<\/code> \/\/ index equals<\/p>\n<h4><strong>\u2022 Attribute Filters<\/strong><\/h4>\n<p><code>$(\"div[id]\")<\/code> \/\/ has attribute<br \/>\n<code>$(\"div[dir='rtl']\")<\/code> \/\/ equals to<br \/>\n<code>$(\"div[id^='name]\")<\/code> \/\/ starts with<br \/>\n<code>$(\"div[id$='main]\")<\/code> \/\/ ends with<br \/>\n<code>$(\"a[href*='corner]\")<\/code> \/\/ contains<\/p>\n<h4><strong>\u2022 Form Selectors<\/strong><\/h4>\n<p><code>$(\"input:checkbox\")<\/code> \/\/ checkboxes<br \/>\n<code>$(\"input:radio\")<\/code> \/\/ radio buttons<br \/>\n<code>$(\":button\")<\/code> \/\/ buttons<br \/>\n<code>$(\":text\")<\/code> \/\/ text inputs<\/p>\n<p>To find out more about selectors, have a look at a more detailed article of ours about selectors <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-selector-example\/\" target=\"_blank\">here<\/a>.<\/p>\n<h3><strong><a name=\"jquery-workflow\"><\/a>1.4 Basic Workflow<\/strong><\/h3>\n<p>When you use JQuery, you typically follow these steps of action:<\/p>\n<p>1. Wait for the page to be ready.<br \/>\n2. Select some HTML elements to modify.<br \/>\n3. Traverse the selected HTML elements.<br \/>\n4. Modify the HTML element attributes, CSS styles etc.<br \/>\n5. Add listener functions, e.g. click() or wait for a JQuery effect to finish etc.<\/p>\n<pre class=\"brush:js\">\/\/ 1. Wait for the page to be ready.\r\n$(document).ready(function() {\r\n\r\n\r\n\/\/ 2. select the HTML element with id 'theDiv'\r\nvar theDiv = $('#theDiv');\r\n\r\n\/\/ 3. since only 1 element was selected, no traversal is necessary\r\n\r\n\/\/ 4. modify the HTML elements CSS attributes\r\ntheDiv.css(\"border\", \"1px solid black\");\r\n\r\n\/\/ 5. add a click-listener function to it.\r\ntheDiv.click(function() {\r\n    $('#theDiv').show(300);\r\n});\r\n}\r\n<\/pre>\n<p>First the example calls jQuery&#8217;s <code>$(document).ready()<\/code> function, passing a function as parameter. The function passed as parameter is executed when the page is ready.<\/p>\n<p>Second, the example selects the HTML element with the id &#8220;theDiv&#8221;. It does so by calling JQuery&#8217;s selection function, the <code>$()<\/code> function, passing a selection string as parameter.<\/p>\n<p>Third, the example modifies the CSS attribute &#8220;border&#8221; of the HTML element. This is done by calling the <code>css()<\/code> function on the selected HTML element.<\/p>\n<p>Fourth, the example adds a click listener function to the HTML element. It does so by calling the <code>click()<\/code> function on the selected element. When the HTML element is clicked, this function is executed.<\/p>\n<h3><strong><a name=\"jquery-family\"><\/a>1.5 The jQuery Family<\/strong><\/h3>\n<p>You might get surprised, but jQuery is not alone. What that means is that along with the development of jQuery, there are also similar libraries initialized by the very same principles and core (Javascript) which are focused in more particular applications. The graphic below gives you a short introduction to each of them!<\/p>\n<figure id=\"attachment_10425\" aria-describedby=\"caption-attachment-10425\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-2.jpg\" rel=\"attachment wp-att-10425\"><img decoding=\"async\" class=\"wp-image-10425 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-2.jpg\" alt=\"jquery-qa-2\" width=\"820\" height=\"706\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-2.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-2-300x258.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-2-768x661.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-10425\" class=\"wp-caption-text\">The jQuery Family<\/figcaption><\/figure>\n<h2><strong><a name=\"introductory\"><\/a>2. Introductory Questions<\/strong><\/h2>\n<h4><strong>1. What is jQuery?<\/strong><\/h4>\n<p>jQuery is a fast, lightweight and feature-rich client side JavaScript Library\/Framework which helps in to traverse HTML DOM, make animations, add Ajax interaction, manipulate the page content, change the style and provide cool UI effect. It is one of the most popular client side library and as per a survey it runs on every second website.<\/p>\n<h4><strong>2. How JavaScript and jQuery are different?<\/strong><\/h4>\n<p>jQuery is not a programming language but a well written JavaScript code. It is a library\/framework built with Javascript. It is very popular because it (nearly universally) abstracts away cross-browser compatibility issues and it emphasises unobtrusive and callback-driven Javascript programming. Javascript is the core programming language.<\/p>\n<h4><strong>3. What is the advantage of using the minimized version of jQuery?<\/strong><\/h4>\n<p>Efficiency of web page increases when minimized version of jQuery is used. jQuery&#8217;s min.js file will be more than 50% less than the normal js file. Reduction in the file size makes the web page faster. They are both the same functionally but the .min one has all unnecessary characters removed in order to make the file size smaller.<\/p>\n<h4><strong>4. What are all the ways to include jQuery in a page?<\/strong><\/h4>\n<p>Following are the ways to include jQuery in a page:<\/p>\n<p>\u2022 Local copy inside script tag<br \/>\n\u2022 Remote copy of jQuery.com<br \/>\n\u2022 Remote copy of Ajax API<br \/>\n\u2022 Local copy of script manager control<br \/>\n\u2022 Embedded script using client script object<\/p>\n<h4><strong>5. What is $() in jQuery library?<\/strong><\/h4>\n<p>The <code>$()<\/code> function is an alias of <code>jQuery()<\/code> function. <code>$()<\/code> 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 <code>$()<\/code> function, and it will return jQuery object containing an array of all matched DOM elements.<\/p>\n<h4><strong>6. Can we use our own specific character in the place of $ sign in jQuery?<\/strong><\/h4>\n<p>Yes. It is possible using <code>jQuery.noConflict()<\/code> method. If we need to use another JavaScript library alongside jQuery, we return control of $ back to the other library with a call to <code>$.noConflict()<\/code>. Old references of $ are saved during jQuery initialization; <code>noConflict()<\/code> simply restores them.<\/p>\n<p>Find out more on this method <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-noconflict-example\/\" target=\"_blank\">here<\/a>.<\/p>\n<h4><strong>7. What is AJAX in jQuery?<\/strong><\/h4>\n<p>AJAX stands for \u201cAsynchronous JavaScript and XML\u201d. AJAX is about exchanging data with a server, without reloading the whole page. It is a technique for creating fast and dynamic web pages.<br \/>\n<code>$.ajax ()<\/code> is JQuery\u2019s core method for creating Ajax requests. Some jQuery AJAX methods are:<\/p>\n<p><code>$.ajax()<\/code> &#8211; Performs an async AJAX request.<br \/>\n<code>$.get()<\/code> &#8211; Loads data from a server using an AJAX HTTP GET request.<br \/>\n<code>$.post()<\/code> &#8211; Loads data from a server using an AJAX HTTP POST request.<\/p>\n<h4><strong>8. What is $(document).ready() function? Why should you use it?<\/strong><\/h4>\n<p>This is one of the most important and frequently asked jQuery Interview question. The <code>ready()<\/code> function is used to execute code when document is ready for manipulation. jQuery allows you to execute code, when DOM is fully loaded i.e. HTML has been parsed and DOM tree has been constructed. Main benefit of <code>$(document).ready()<\/code> function is that, it works in all browsers, jQuery handles cross browser difficulties for you.<\/p>\n<p>Read more about the <code>.ready()<\/code> function <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-document-ready-example\/\" target=\"_blank\">here<\/a>.<\/p>\n<h4><strong>9. Tell the difference between JavaScript window.onload event and jQuery ready function?<\/strong><\/h4>\n<p>Main difference between JavaScript <code>onload<\/code> event and jQuery <code>ready<\/code> function is that former not only waits for DOM to be created but also waits until all external resources are fully loaded including heavy images, audios and videos. If loading images and media content takes a lot of time, the user can experience significant delay on execution of code defined in <code>window.onload<\/code> event.<\/p>\n<p>On the other hand jQuery <code>ready()<\/code> function only waits for the DOM tree, and does not wait for images or external resource loading, which means faster execution. Another advantage of using jQuery <code>$(document).ready()<\/code> is that you can use it multiple times in your page, and browser will execute them in the order they appear in HTML page, as opposed to <code>onload<\/code> technique, which can only be used for a single function. Given this benefits, it&#8217;s always better to use jQuery <code>ready()<\/code> function than JavaScript <code>window.onload<\/code> event.<\/p>\n<h4><strong>10. What are jQuery Events?<\/strong><\/h4>\n<p>Events are actions performed on a specific condition that are used for dynamic web pages. When we perform these actions on an HTML page, we can do whatever we want. We use some event handlers to perform the action. Some important handlers are <code>bind()<\/code>, <code>unbind()<\/code>, <code>blur()<\/code>, <code>off()<\/code>, <code>hover()<\/code>, <code>on()<\/code>, <code>one()<\/code>, <code>ready()<\/code>, <code>trigger()<\/code> etc.<\/p>\n<h4><strong>11. What are jQuery plugins and what is the advantage of using a plugin?<\/strong><\/h4>\n<p>A plug-in is piece of code written in a standard JavaScript file. These files provide useful jQuery methods which can be used along with jQuery library methods. jQuery plugins are quite useful as its piece of code which is already written by someone and re-usable, which saves your development time.<\/p>\n<h4><strong>12. Mention some of the interactions available in the jQuery UI library.<\/strong><\/h4>\n<p>We can use interactions for basic mouse-based behaviours to any element. Examples of Interactions are the following:<\/p>\n<p>\u2022 Draggable<br \/>\n\u2022 Droppable<br \/>\n\u2022 Resizable<br \/>\n\u2022 Selectable<br \/>\n\u2022 Sortable<\/p>\n<figure id=\"attachment_10507\" aria-describedby=\"caption-attachment-10507\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-4.jpg\" rel=\"attachment wp-att-10507\"><img decoding=\"async\" class=\"wp-image-10507 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-4.jpg\" alt=\"jquery-qa-4\" width=\"820\" height=\"571\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-4.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-4-300x209.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-4-768x535.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-10507\" class=\"wp-caption-text\">jQuery UI Interactions Branch<\/figcaption><\/figure>\n<h2><strong><a name=\"methods-functions\"><\/a>3. Methods\/Functions Questions<\/strong><\/h2>\n<h3><strong><a name=\"similar-methods\"><\/a>3.1 Similar Methods Comparison<\/strong><\/h3>\n<h4><strong>13. What is the difference between .empty(), .remove() and .detach() methods in jQuery?<\/strong><\/h4>\n<p>All these methods <code>.empty()<\/code>, <code>.remove()<\/code> and <code>.detach()<\/code> are used for removing elements from DOM but they all are different.<\/p>\n<p><code>.empty()<\/code>: This method removes all the child element of the matched element while <code>remove()<\/code> method removes set of matched elements from DOM.<\/p>\n<p><code>.remove()<\/code>: We use <code>.remove()<\/code> when we want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.<\/p>\n<p><code>.detach()<\/code>: This method is the same as <code>.remove()<\/code>, except that <code>.detach()<\/code> keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.<\/p>\n<h4><strong>14. What is the difference between bind() and live() method in jQuery?<\/strong><\/h4>\n<p>The binding of event handlers are the most confusing part of jQuery for many developers working on jQuery projects. Many of them unsure of which is better to use. In this article we will see the main differences between Bind and Live methods in jQuery.<\/p>\n<h5><strong>Bind() Method<\/strong><\/h5>\n<p>The bind method will only bind event handlers for currently existing items. That means this works for the current element.<\/p>\n<pre class=\"brush:js\">$(document).ready(function () {   \r\n   $('p').bind('click', function () {  \r\n      alert(\"Example of Bind Method\");  \r\n      e.preventDefault();  \r\n   });   \r\n});  \r\n<\/pre>\n<h5><strong>Live() Method<\/strong><\/h5>\n<p>The Live method can bind event handlers for currently existing items or future items.<\/p>\n<pre class=\"brush:js\">$(document).ready(function() {  \r\n    $('P').live('click', function() {  \r\n        alert(\"Example of live method\");  \r\n        e.preventDefault();  \r\n    });  \r\n    $('body').append(''); });\r\n<\/pre>\n<h4><strong>15. A bigger picture comparison of .bind() vs .live() vs .delegate() vs .on()?<\/strong><\/h4>\n<p>All these 4 jQuery methods are used for attaching events to selectors or elements. But they all are different from each other.<\/p>\n<p><code>.bind()<\/code>: This is the easiest and quick method to bind events. But the issue with bind() is that it doesn&#8217;t work for elements added dynamically that matches the same selector. bind() only attach events to the current elements not future element. Above that it also has performance issues when dealing with a large selection.<\/p>\n<p><code>.live()<\/code>: This method overcomes the disadvantage of bind(). It works for dynamically added elements or future elements. Because of its poor performance on large pages, this method is deprecated as of jQuery 1.7 and you should stop using it. Chaining is not properly supported using this method.<\/p>\n<p><code>.delegate()<\/code>: The .delegate() method behaves in a similar fashion to the .live() method, but instead of attaching the selector\/event information to the document, you can choose where it is anchored and it also supports chaining.<\/p>\n<p><code>.on()<\/code>: Since live was deprecated with 1.7, so new method was introduced named &#8220;.on()&#8221;. This method provides all the goodness of previous 3 methods and it brings uniformity for attaching event handlers.<\/p>\n<h4><strong>16. What is difference between prop and attr?<\/strong><\/h4>\n<p><code>attr()<\/code>: Gets the value of an attribute for the first element in the set of matched elements. Whereas, <code>.prop()<\/code>: will get the value of a property for the first element in the set of matched elements.<\/p>\n<p>Attributes carry additional information about an HTML element and come in <code>name=\"value\"<\/code> pairs. Where Property is a representation of an attribute in the HTML DOM tree. Once the browser parse your HTML code, corresponding DOM node will be created which is an object thus having properties.<\/p>\n<p><code>attr()<\/code> gives you the value of an element as it was defined in the html on page load. It is always recommended to use <code>prop()<\/code> to get values of elements which is modified via javascript\/jquery, as it gives you the original value of an element&#8217;s current state.<\/p>\n<h4><strong>17. What is the difference between event.stopPropagation and event.stopImmediatePropagation?<\/strong><\/h4>\n<p><code>event.stopPropagation()<\/code> allows other handlers on the same element to be executed, while <code>event.stopImmediatePropagation()<\/code> prevents every event from running. For example, see below jQuery code block:<\/p>\n<pre class=\"brush:js\">$(\"p\").click(function(event){\r\n  event.stopImmediatePropagation();\r\n});\r\n$(\"p\").click(function(event){\r\n  \/\/ This function won't be executed\r\n  $(this).css(\"background-color\", \"#f00\");\r\n}); \r\n<\/pre>\n<p>If <code>event.stopPropagation<\/code> was used in previous example, then the next click event on <code>p<\/code> element which changes the css will fire, but in case <code>event.stopImmediatePropagation()<\/code>, the next <code>p<\/code> click event will not fire.<\/p>\n<h4><strong>18. Explain width() vs css(\u2018width\u2019)?<\/strong><\/h4>\n<p>In jQuery, there are two way to change the width of an element.<br \/>\nOne way is using <code>.css(\u2018width\u2019)<\/code> and other way is using <code>.width()<\/code>.<\/p>\n<p>For example:<\/p>\n<pre class=\"brush:js\">$(\u2018#mydiv\u2019).css(\u2018width\u2019,\u2019300px\u2019);\r\n$(\u2018#mydiv\u2019).width(100);\r\n<\/pre>\n<p>The difference in <code>.css(\u2018width\u2019)<\/code> and <code>.width()<\/code> is the data type of value we specify or return from the both functions. In <code>.css(\u2018width\u2019)<\/code> we have to add \u201cpx\u201d in the width value while in <code>.width()<\/code> we don\u2019t have to add. When you want to get the width of <code>\u201cmydiv\u201d<\/code> element then <code>.css(\u2018width\u2019)<\/code> will return <code>\u2018300px\u2019<\/code> while <code>.width()<\/code> will return only integer value <code>300<\/code>.<\/p>\n<h4><strong>19. What is the difference between event.PreventDefault and event.stopPropagation?<\/strong><\/h4>\n<p><code>preventDefault()<\/code>: Stops the default action of an element from happening.<br \/>\n<code>event.stopPropagation()<\/code>: Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing. You can check out <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-preventdefault-example\/\" target=\"_blank\">this<\/a> article to have a closer look at the <code>.preventDefault()<\/code> method.<\/p>\n<h4><strong>20. What is the difference between calling stop(true,true) and finish method?<\/strong><\/h4>\n<p>The <code>.finish()<\/code> method is similar to <code>.stop(true, true)<\/code> in that it clears the queue and the current animation jumps to its end value. It differs, however, in that <code>.finish()<\/code> also causes the CSS property of all queued animations to jump to their end values, as well.<\/p>\n<h4><strong>21. What is the difference between parent() and parents() methods in jQuery?<\/strong><\/h4>\n<p>The basic difference is the <code>parent()<\/code> function travels only one level in the DOM tree, where <code>parents()<\/code> function search through the whole DOM tree.<\/p>\n<h4><strong>22. What is the difference between eq() and get() methods in jQuery?<\/strong><\/h4>\n<p><code>eq()<\/code> returns the element as a jQuery object. This method constructs a new jQuery object from one element within that set and returns it. That means that you can use jQuery functions on it.<\/p>\n<p><code>get()<\/code> returns a DOM element. The method retrieves the DOM elements matched by the jQuery object. But it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can&#8217;t be used.<\/p>\n<h3><strong><a name=\"explain-methods\"><\/a>3.2 Function Explanations<\/strong><\/h3>\n<h4><strong>23. How do you implement animation functionality?<\/strong><\/h4>\n<p>The <code>.animate()<\/code> method allows us to create animation effects on any numeric CSS property. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Syntax is:<\/p>\n<pre class=\"brush:js\">(selector).animate({styles},speed,easing,callback)\r\n<\/pre>\n<p>\u2022 styles: Specifies one or more CSS properties\/values to animate.<br \/>\n\u2022 duration: Optional. Specifies the speed of the animation.<br \/>\n\u2022 easing: Optional. Specifies the speed of the element in different points of the animation. Default value is &#8220;swing&#8221;.<br \/>\n\u2022 callback: Optional. A function to be executed after the animation completes.<\/p>\n<pre class=\"brush:js\">$(\"btnClick\").click(function(){\r\n  $(\"#dvBox\").animate({height:\"100px\"});\r\n});\r\n<\/pre>\n<h4><strong>24. What is .siblings() method in jQuery?<\/strong><\/h4>\n<p>When we want to fetch siblings of every elements in the set of matched elements then we can use siblings() method. We filter the elements fetched by an optional selector.<br \/>\nThe syntax is: <code>.siblings([selector])<\/code> where \u201cselector\u201d is the selector expression which specify the matched elements.<\/p>\n<pre class=\"brush:xml\">&lt;ul&gt;\r\n&lt;li&gt; item 1 &lt;\/li&gt;\r\n&lt;li id=\u201dsecond_item\u201d&gt; item 2 &lt;\/li&gt;\r\n&lt;li class=\u201dmyitem\u201d&gt; item 3 &lt;\/li&gt;\r\n&lt;li class=\u201dmyitem\u201d&gt; item 4 &lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n<\/pre>\n<p>Now we want to find the siblings of the element of id \u201csecond_item\u201d and change the text color to Blue:<\/p>\n<pre class=\"brush:js\">$(\u2018li.second_item\u2019).siblings().css(\u2018color\u2019,\u2019blue\u2019);\r\n<\/pre>\n<p>If we want specific sibling elements for example the elements having class \u201cmyitem\u201d then we can pass a optional selector:<\/p>\n<pre class=\"brush:js\">$(\u2018li.second_item\u2019).siblings(\u2018.myitem\u2019).css(\u2018color\u2019,\u2019blue\u2019);\r\n\r\nRead more about the <code>siblings()<\/code> method <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-siblings-example\/\" target=\"_blank\">here<\/a>.<\/pre>\n<h4><strong>25. What is the use of jQuery.data()?<\/strong><\/h4>\n<p>jQuery <code>.data()<\/code> is used to set\/return arbitrary data to\/from an element.<br \/>\nSyntax: <code>jQuery.data(element, key, value)<\/code> where:<br \/>\n&#8211; \u201celement\u201d is the DOM element to which the data is associated.<br \/>\n&#8211; \u201ckey\u201d is an arbitrary name of the piece of data.<br \/>\n&#8211; \u201cvalue\u201d is value of the specified key.<br \/>\nSuppose we want to set the data for a span element:<\/p>\n<pre class=\"brush:js\">jQuery.data(span, \u201citem\u201d, { val1: 10, val2: \"myitem\" });\r\n<\/pre>\n<p>If we want to retrieve the data related to div element and set it to label\u2019s data:<\/p>\n<pre class=\"brush:js\">$(\"label:val1\").text(jQuery.data(div, \"item\").val1);\r\n$(\"label:val2\").text(jQuery.data(div, \"item\").val2);\r\n<\/pre>\n<h4><strong>26. What is jQuery.holdReady() function?<\/strong><\/h4>\n<p>jQuery <code>.data()<\/code> is used to set\/return arbitrary data to\/from an element.<br \/>\nBy using <code>jQuery.holdReady()<\/code> function we can hold or release the execution of jQuery\u2019s ready event.<br \/>\nThis method should be call before we run ready event.<br \/>\nTo delay the ready event, we have to call<\/p>\n<pre class=\"brush:js\">Query.holdReady(true);\r\n<\/pre>\n<p>When we want to release the ready event then we have to call<\/p>\n<pre class=\"brush:js\">jQuery.holdReady(false);\r\n<\/pre>\n<p>This function is helpful when we want to load any jQuery plugins before the execution of ready event. For example:<\/p>\n<pre class=\"brush:js\">$.holdReady(true);\r\n$.getScript(\"xyzplugin.js\", function() \r\n{\r\n     $.holdReady(false);\r\n});\r\n<\/pre>\n<h4><strong>27. What is the use of param() method?<\/strong><\/h4>\n<p>The param() method is used to represent an array or an object in serialize manner.<br \/>\nWhile making an ajax request we can use these serialize values in the query strings of URL.<br \/>\nSyntax: <code>$.param(object | array, boolValue)<\/code>.<br \/>\nFor example:<\/p>\n<pre class=\"brush:js\">personObj=new Object();\r\nempObject.name=\"Arpit\";\r\nempObject.age=\"24\";\r\nempObject.dept=\u201dIT\u201d;\r\n$(\"#clickme\").click(function()\r\n{\r\n     $(\"span\").text($.param(empObject));\r\n});\r\n<\/pre>\n<h4><strong>28. Explain the resize() function in jQuery.<\/strong><\/h4>\n<p>The <code>resize()<\/code> function is called whenever the browser size is changed. This event can be only used with <code>$(window)<\/code>.<br \/>\nSyntax: <code>.resize([event_data], handler(event_object))<\/code>. For example:<\/p>\n<pre class=\"brush:js\">$(window).resize(function() \r\n{\r\n$('#message).text('window is resized to ' + $(window).width() + \u2018x\u2019 + $(window).height());\r\n});\r\n<\/pre>\n<h4><strong>29. How is the deferred method in jquery important in relation to animate method?<\/strong><\/h4>\n<p>The <code>.animate()<\/code> method is used to create animations with other shorthands using it. The <code>queue()<\/code> method can be used to link together multiple animation methods to create an unique effect. These methods are effective when all the data is available locally and all the methods are executed on as single system only. In case the user wants to use the animation methods on a data that resides on the server and wants to handle at a single go the user can make used of the .deferred method.<\/p>\n<pre class=\"brush:js\">var my$ = $.sub();\r\nmy$.fn.animate = function( props, speed, easing, callback ) \r\n{\r\nvar options = speed &amp;&amp; typeof speed === \"object\" ?\r\njQuery.extend({}, speed) : \r\n{\r\n     complete: callback || !callback &amp;&amp; easing ||\r\n     jQuery.isFunction( speed ) &amp;&amp; speed,\r\n     duration: speed,\r\n     easing: callback &amp;&amp; easing || easing &amp;&amp;\r\n     !jQuery.isFunction(easing) &amp;&amp; easing\r\n};\r\nvar dfd = my$.Deferred(),\r\ncomplete = options.complete,\r\ncount = this.length;\r\noptions.complete = function() \r\n{\r\n     complete &amp;&amp; complete.call( this );\r\n     if ( !--count ) \r\n{\r\n     dfd.resolve();\r\n}}};\r\n<\/pre>\n<h4><strong>30. Explain the use of the .pushStack() method?<\/strong><\/h4>\n<p>The <code>pushStack()<\/code> method works by accepting an array of DOM elements and pushes them into a stack. This is done so that call to methods like <code>.end()<\/code> and <code>.andSelf<\/code> are able to behave correctly. The jquery internally uses this method to keep track of all the previous collections of jquery while using a chain traversing method. Good examples of such methods could be <code>.parents()<\/code> and <code>.filter()<\/code>. For example:<\/p>\n<pre class=\"brush:js\">\/\/ select some divs\r\n$('div.container')\r\n\/\/ find some spans inside those divs and add a class to them\r\n.find('span').addClass('baby')\r\n\/\/ pop those spans off the \"stack\",\r\n\/\/ returning to the previous collection (div.container)\r\n.end()\r\n\/\/ add a class to the parent of each div.container\r\n.parent().addClass('daddy');\r\n<\/pre>\n<h3><strong><a name=\"find-methods\"><\/a>3.3 What is the method we use to&#8230;?<\/strong><\/h3>\n<h4><strong>31. In jQuery, the method we use to check whether an element is empty or not is..?<\/strong><\/h4>\n<p>1. Using &#8220;:empt&#8221; selector<br \/>\n2. $.trim()<br \/>\n3. $.empty()<br \/>\n4. Both 1 &amp; 2<br \/>\n5. All Above<\/p>\n<p>The correct answer is: <strong>4. Both 1 &amp; 2<\/strong>.<\/p>\n<h4><strong>32. In jQuery, the method we use to create a new &#8216;div&#8217; element is..?<\/strong><\/h4>\n<p>1. $(&#8216;div&#8217;)<br \/>\n2. $(&#8216;&lt;div \/&gt;&#8217;)<br \/>\n3. $.create(&#8216;&lt;div \/&gt;&#8217;)<br \/>\n4. $.create(&#8216;div&#8217;)<br \/>\n5. All Above<\/p>\n<p>The correct answer is: <strong>2. $(&#8216;&lt;div \/&gt;&#8217;)<\/strong><\/p>\n<h4><strong>33. In jQuery, the method we use to stop the default action of the event from triggering is..?<\/strong><\/h4>\n<p>1. event.stopPropagation()<br \/>\n2. event.preventDefault()<br \/>\n3. event.stopImmediatePropagation()<br \/>\n4. event.isDefaultPrevented()<br \/>\n5. All Above<\/p>\n<p>The correct answer is: <strong>2. event.preventDefault()<\/strong><\/p>\n<h4><strong>34. In jQuery, the method used to stop the running animation is..?<\/strong><\/h4>\n<p>1. .stopAnimation()<br \/>\n2. .stopAnimate()<br \/>\n3. .stop()<br \/>\n4. None of the above<br \/>\n5. All Above<\/p>\n<p>The correct answer is: <strong>3. stop()<\/strong><\/p>\n<h4><strong>35. In jQuery, the method used to create a copy of the set of matched elements is..?<\/strong><\/h4>\n<p>1. .copy()<br \/>\n2. .create()<br \/>\n3. .clode()<br \/>\n4. .createCopy()<br \/>\n5. All Above<\/p>\n<p>The correct answer is: <strong>3. clone().<\/p>\n<p><\/strong>Find out more about this method <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-clone-example\/\" target=\"_blank\">here<\/a>.<\/p>\n<h2><strong><a name=\"code\"><\/a>4. Code Questions<\/strong><\/h2>\n<h3><strong><a name=\"given-code\"><\/a>4.1 Given Code Questions<\/strong><\/h3>\n<h4><strong>36. Explain what the following code will do?<\/strong><\/h4>\n<pre class=\"brush:js\">$( \"div#first, div.first, ol#items &gt; [name$='first']\" )\r\n<\/pre>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>This code performs a query to retrieve any <code>&lt;div&gt;<\/code> element with the id first, plus all <code>&lt;div&gt;<\/code> elements with the class first, plus all elements which are children of the <code>&lt;ol id=\"items\"&gt;<\/code> element and whose name attribute ends with the string &#8220;first&#8221;. This is an example of using multiple selectors at once. The function will return a jQuery object containing the results of the query.<\/p>\n<h4><strong>37. The code below is for an application that requires defining a click handler for all buttons on the page, including those buttons that may be added later dynamically. What is wrong with this code, and how can it be fixed to work properly even with buttons that are added later dynamically?<\/strong><\/h4>\n<pre class=\"brush:js\">\/\/ define the click handler for all buttons\r\n$( \"button\" ).bind( \"click\", function() {\r\n    alert( \"Button Clicked!\" )\r\n});\r\n\r\n\/* ... some time later ... *\/\r\n\r\n\/\/ dynamically add another button to the page\r\n$( \"html\" ).append( \"<button>Click Alert!<\/button>\" );\r\n<\/pre>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>The button that is added dynamically after the call to <code>bind()<\/code> will not have the click handler attached. This is because the <code>bind()<\/code> method only attaches handlers to elements that exist at the time the call to <code>bind()<\/code> is made. Find out more about <code>bind()<\/code> in this <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-bind-example\/\" target=\"_blank\">article<\/a>.<\/p>\n<p>This problem is solved with functions that use \u201cevent bubbling\u201d to match events on both current and future elements. In the past, this was done by replacing <code>bind()<\/code> with <code>live()<\/code>. <code>live()<\/code> was deprecated in jQuery 1.7 though. <code>delegate()<\/code> works similarly to <code>live()<\/code> but also provides control over how far an event must bubble up the DOM.<\/p>\n<p>However, the recommended method is to use <code>on()<\/code>, which can behave like <code>bind()<\/code>, <code>live()<\/code>, or <code>delegate()<\/code> depending on syntax. The following code attaches the handler to all current and future buttons:<\/p>\n<pre class=\"brush:js\">\/\/ define the click handler for all buttons\r\n$( document ).on( \"click\", \"button\", function() {\r\n    alert( \"Button Clicked!\" )\r\n});\r\n\r\n\/* ... some time later ... *\/\r\n\r\n\/\/ dynamically add another button to the page\r\n$( \"html\" ).append( \"<button>Click Alert!<\/button>\" );\r\n<\/pre>\n<h4><strong>38. Given the following HTML:<\/strong><\/h4>\n<pre class=\"brush:xml\">&lt;div id=\"expander\"&gt;&lt;\/div&gt;<\/pre>\n<p>and the following CSS:<\/p>\n<pre class=\"brush:css\">div#expander{\r\n  width: 100px;\r\n  height: 100px;\r\n  background-color: blue;\r\n}\r\n<\/pre>\n<p>Write code in jQuery to animate the <code>#expander<\/code> div, expanding it from 100 x 100 pixels to 200 x 200 pixels over the course of three seconds.<\/p>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>This could be done in jQuery as follows:<\/p>\n<pre class=\"brush:js\">$( \"#expander\" ).animate(\r\n  {\r\n    width: \"200px\", \/\/ new width\r\n    height: \"200px\", \/\/ new height\r\n  },\r\n  3000 ); \/\/ timeframe\r\n<\/pre>\n<h4><strong>39. What does the following code do?<\/strong><\/h4>\n<pre class=\"brush:js\">$( \"div\" ).css( \"width\", \"300px\" ).add( \"p\" ).css( \"background-color\", \"blue\" );<\/pre>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>This code uses method chaining to accomplish a couple of things. First, it selects all the <code>&lt;div&gt;<\/code> elements and changes their CSS width to 300px. Then, it adds all the <code>&lt;p&gt;<\/code> elements to the current selection, so it can finally change the CSS background color for both the <code>&lt;div&gt;<\/code> and <code>&lt;p&gt;<\/code> elements to blue.<\/p>\n<p>Read more about using the <code>.css()<\/code> method in jQuery <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-css-addremove-style-example\/\" target=\"_blank\">here<\/a>.<\/p>\n<h4><strong>40. Which of the two lines of code below is more efficient? Explain your answer?<\/strong><\/h4>\n<pre class=\"brush:js\">document.getElementById( \"logo\" );<\/pre>\n<p>or<\/p>\n<pre class=\"brush:js\">$( \"#logo\" );<\/pre>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>The first line of code, which is pure JavaScript without jQuery, is more efficient and faster. Executing the second line of code, which is jQuery, will trigger a call to the JavaScript version.<\/p>\n<p>jQuery is built on top of JavaScript and uses its methods under the hood to make DOM manipulation easier, at the cost of some performance overhead. It is a good idea to remember that jQuery is not always better than plain old JavaScript. Always consider whether using jQuery really provides a useful advantage for your project.<\/p>\n<h3><strong><a name=\"write-code\"><\/a>4.2 Writing Code Questions<\/strong><\/h3>\n<h4><strong>41. Consider the following situation:<\/strong><\/h4>\n<p>I need to query all elements with an ID that ends with a particular string. Also, I&#8217;d like to modify the selector to retrieve only <code>&lt;div&gt;<\/code> elements whose IDs end with that same string? Provide an example showing how you would have done this.<\/p>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>Let\u2019s say you want to retrieve all elements whose IDs end with \u201ctxtTitle\u201d. This could be done using the following selector:<\/p>\n<pre class=\"brush:js\">$(\"[id$='txtTitle']\")<\/pre>\n<p>To retrieve only <code>&lt;div&gt;<\/code> elements whose IDs end with \u201ctxtTitle\u201d, the selector would be:<\/p>\n<pre class=\"brush:js\">$(\"div[id$='txtTitle']\")<\/pre>\n<h4><strong>42. Create a plugin that would add and remove a class on hover.<\/strong><\/h4>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>The plugin can be considered to be simply a new method that can be used by a user to extend the prototype object of a jquery. A plugin performs some actions on a collection of elements. Each method that comes with the jquery core can be considered to be a plugin.<\/p>\n<p>The code for creating a plugin that would add and remove a class on hover would be as follows:<\/p>\n<pre class=\"brush:js\">(function($)\r\n{\r\n   $.fn.hoverClass = function(c) \r\n{\r\n     return this.hover(\r\n     function() { $(this).toggleClass(c); }\r\n);\r\n};\r\n})(jQuery);\r\n\r\n\/\/ using the plugin\r\n$('li').hoverClass('hover');\r\n<\/pre>\n<h4><strong>43. Write a code for the implementation of a module pattern.<\/strong><\/h4>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>The object literal does not provide any privacy for the methods or properties. The module pattern allows the user to offer privacy to functions and variables. It can be used to set to expose limited API.<\/p>\n<pre class=\"brush:js\">var feature =(function() \r\n{\r\nvar privateThing = 'secret',\r\npublicThing = 'not secret',\r\nchangePrivateThing = function() \r\n{\r\n     privateThing = 'super secret';\r\n},\r\nsayPrivateThing = function() \r\n{\r\n     console.log(privateThing);\r\n     changePrivateThing();\r\n};\r\nreturn \r\n{\r\n     publicThing : publicThing,\r\n     sayPrivateThing : sayPrivateThing\r\n}\r\n})();\r\nfeature.publicThing; \/\/ 'not secret'\r\nfeature.sayPrivateThing();\r\n<\/pre>\n<h4><strong>44. How to create clone of any object using jQuery?<\/strong><\/h4>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>jQuery provides <code>clone()<\/code> method which performs a deep copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes.<\/p>\n<pre class=\"brush:js\">$(document).ready(function(){\r\n  $('#btnClone').click(function(){\r\n     $('#dvText').clone().appendTo('body');\r\n     return false;\r\n  });\r\n});\r\n<\/pre>\n<h4><strong>45. How do you attach a event to element which should be executed only once?<\/strong><\/h4>\n<h5><strong>Answer:<\/strong><\/h5>\n<p>Using jQuery <code>one()<\/code> method. This attaches a handler to an event for the element. The handler is executed at most once per element. In simple terms, the attached function will be called only once.<\/p>\n<pre class=\"brush:js\">$(document).ready(function() {\r\n    $(\"#btnDummy\").one(\"click\", function() {\r\n        alert(\"This will be displayed only once.\");\r\n    });\r\n});\u200b\r\n<\/pre>\n<h2><strong><a name=\"ajax\"><\/a>5. AJAX Related Questions<\/strong><\/h2>\n<h3><strong><a name=\"general-ajax\"><\/a>5.1 General AJAX Questions<\/strong><\/h3>\n<h4><strong>46. What is the use of jQuery.ajax method()?<\/strong><\/h4>\n<p>The ajax() method is used to do an AJAX (asynchronous HTTP) request. It provides more control of the data sending and on response data. It allows the handling of errors that occur during a call and the data if the call to the ajax page is successful.<\/p>\n<p>Here is the list of some basic parameters required for jQuery.ajax Method:<br \/>\n\u2022 type: Specifies the type of request (GET or POST).<br \/>\n\u2022 url: Specifies the URL to send the request to. The default is the current page.<br \/>\n\u2022 contentType: The content type used when sending data to the server. The default is &#8220;application\/x-www-form-urlencoded&#8221;.<br \/>\n\u2022 dataType: The data type expected of the server response.<br \/>\n\u2022 data: Specifies data to be sent to the server.<br \/>\n\u2022 success(result,status,xhr): A function to run when the request succeeds.<br \/>\n\u2022 error(xhr,status,error): A function to run if the request fails.<\/p>\n<h4><strong>47. What are the advantages of Ajax?<\/strong><\/h4>\n<p>Following are the advantages of Ajax:<br \/>\n\u2022 Bandwidth utilization<br \/>\n\u2022 It saves memory when the data is fetched from the same page.<br \/>\n\u2022 More interactive<br \/>\n\u2022 Speeder retrieval of data<\/p>\n<h4><strong>48. What about the disadvantages of Ajax?<\/strong><\/h4>\n<p>\u2022 AJAX is dependent on Javascript. If there is some Javascript problem with the browser or in the OS, Ajax will not support.<br \/>\n\u2022 Ajax can be problematic in Search engines as it uses Javascript for most of its parts.<br \/>\n\u2022 Source code written in AJAX is easily human readable. There will be some security issues in Ajax.<br \/>\n\u2022 Debugging is difficult (not impossible)<br \/>\n\u2022 Increases size of the requests<br \/>\n\u2022 Slow and unreliable network connection.<br \/>\n\u2022 Problem with browser back button when using AJAX enabled pages.<\/p>\n<h4><strong>49. What are the technologies used by Ajax?<\/strong><\/h4>\n<p>AJAX uses following technologies:<\/p>\n<p>\u2022 JavaScript<br \/>\n\u2022 XMLHttpRequest<br \/>\n\u2022 Document Object Model (DOM)<br \/>\n\u2022 Extensible HTML (XHTML)<br \/>\n\u2022 Cascading Style Sheets (CSS)<\/p>\n<h4><strong>50. What Is the Format of an AJAX Request?<\/strong><\/h4>\n<p>An AJAX request can be in any of the following formats:<br \/>\n\u2022 Text File<br \/>\n\u2022 HTML<br \/>\n\u2022 JSON object<\/p>\n<h4><strong>51. How can you find out that an AJAX request has been completed?<\/strong><\/h4>\n<p>We use the ReadyState property to check whether AJAX request has been completed. If the property is equal to four, then the request has been completed and data is available.<\/p>\n<h4><strong>52. What is JSON in Ajax?<\/strong><\/h4>\n<p>JSON is abbreviated as JavaScript Object Notation. JSON is a safe and reliable data interchange format in JavaScript, which is easy to understand for both users and machines.<\/p>\n<h4><strong>53. How many types of triggers are present in update panel?<\/strong><\/h4>\n<p>There are two types of triggers used in update panel:<br \/>\n\u2022 PostBackTrigger : This works as full postback and it cannot work asynchronously<br \/>\n\u2022 AsyncPostBackTrigger : Partial post back asynchronously<\/p>\n<h4><strong>54. Which two methods are used for handling Cross-Domain Ajax Calls ?<\/strong><\/h4>\n<p>Cross-domain means the ability to manually or automatically access or transfer data between two or more differing security domain<br \/>\n1) CROS (Cross-Origin Resource Sharing) : Works with all HTTP verbs and Mos modern web browsers. Provides better support for error handling than JSONP.<br \/>\n2) JSONP (JSON with padding) : It is only works HTTP GET verb and on legacy browsers.<\/p>\n<h4><strong>55. When should AJAX NOT be used?<\/strong><\/h4>\n<p>It would not be appropriate to use AJAX when the \u201canswer\/result\u201d can be determinded by the client. Generally, the purpose of AJAX is to submit a short request to the server, and process the response in such a way as to add value to the currently displayed page.It would also not be appropriate to use AJAX when the magnitude of the response is such that it would be easier, and more clear to redisplay the page.<\/p>\n<h3><strong><a name=\"technical-ajax\"><\/a>5.2 Technical AJAX Questions<\/strong><\/h3>\n<h4><strong>56. How does AJAX work in simple steps?<\/strong><\/h4>\n<p>This graphic would certainly give you a clearer idea!<\/p>\n<figure id=\"attachment_10530\" aria-describedby=\"caption-attachment-10530\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-51.jpg\" rel=\"attachment wp-att-10530\"><img decoding=\"async\" class=\"wp-image-10530 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-51.jpg\" alt=\"jquery-qa-51\" width=\"820\" height=\"571\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-51.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-51-300x209.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-51-768x535.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-10530\" class=\"wp-caption-text\">AJAX Communication Flow<\/figcaption><\/figure>\n<h4><strong>57. How can AJAX response set a cookie?<\/strong><\/h4>\n<p>Here are two solutions:<br \/>\n1. After getting response, Make another ajax call with request where you can set the cookie.<br \/>\n2. Before sending the ajax response, make the cookie in Server.<br \/>\nUse setcookie function, to set the cookie, like below:<\/p>\n<pre class=\"brush:js\">$cookieValue='This is cookie value';\r\nsetcookie('name', $cookieValue, time() + 3600); \r\n<\/pre>\n<h4><strong>58. How can you send data in an Ajax call?<\/strong><\/h4>\n<p>You can send data in an AJAX call like this:<\/p>\n<pre class=\"brush:js\">$.ajax({ \r\n    url: '\/my\/site\/url',\r\n    data: { name: \"Arun\", location: \"Chandigarh\" },\r\n    type: 'post',\r\n    success: function(result) {\r\n              console.log(result);\r\n}\r\n});\r\n<\/pre>\n<h4><strong>59. How to submit entire form data with Ajax?<\/strong><\/h4>\n<p>In that case, we can consider using serialize to gather form data and then pass it to a variable like so:<\/p>\n<pre class=\"brush:js\">var formData = $('form#formId').serialize();\r\n$.ajax({ \r\n        url: '\/my\/site',\r\n         data: formData,\r\n         type: 'post',\r\n         success: function(result) {\r\n         console.log(result);\r\n   }\r\n});\r\n<\/pre>\n<h4><strong>60. How to URLencode a string before sending in Ajax?<\/strong><\/h4>\n<p>We use <code>encodeURIComponent<\/code> to encode a string. For Example:<\/p>\n<pre class=\"brush:js\"> $.ajax({\r\n        url: '\/ajax\/url',\r\n        dataType: \"json\",\r\n        data: name=encodeURIComponent('Test'),\r\n        success: function(response) {\r\n            if(response.success == 1){\r\n                offWords = response.data;\r\n            }\r\n        },\r\n        error: function(xhr, ajaxOptions, thrownError) {\r\n        }\r\n });\r\n<\/pre>\n<h4><strong>61. Do AJAX requests retain PHP Session info, when calling multiple times?<\/strong><\/h4>\n<p>Yes, PHP retains the session info over multiple ajax call. The duration of the php session depends on SESSION configuration.<\/p>\n<h4><strong>62. How to update the image source, if the original image fails to load?<\/strong><\/h4>\n<p>We use the <code>onError<\/code> attribute to update the image path, when failed to load.<\/p>\n<pre class=\"brush:js\">&lt;img alt=\"Image not found\" onerror=\"this.src='show_img_when_original_failed.gif';\" src=\"image.gif\" \/&gt;\r\n<\/pre>\n<h4><strong>63. Can you add headers in the AJAX Request?<\/strong><\/h4>\n<p>Yes, you can do it like so:<\/p>\n<pre class=\"brush:js\">$.ajax({\r\n    type:\"POST\",\r\n    beforeSend: function (request)\r\n    {\r\n        request.setRequestHeader(\"Header-Name\", \"Header Value\");\r\n    },\r\n    url: \"\/ajax\/url\/\",\r\n    data: \"name=web\",\r\n    processData: false,\r\n    success: function(msg) {\r\n        \/\/Success\r\n    }\r\n    });\r\n<\/pre>\n<h4><strong>64. How to do synchronous AJAX requests?<\/strong><\/h4>\n<p>Simply set the <code>async=false<\/code> in the AJAX call.<\/p>\n<pre class=\"brush:js\">function getRemote() {\r\n    return $.ajax({\r\n        type: \"GET\",\r\n        url: '\/ajax\/url',\r\n        async: false\r\n    }).responseText;\r\n}\r\n<\/pre>\n<h4><strong>65. How can we send ajax request to another domain using JSONP?<\/strong><\/h4>\n<p><strong>JSONP<\/strong> is simple way to overcome <em>XMLHttpRequest<\/em> same domain policy. Using JSONP you can send the request to another domain. JSONP is &#8220;<strong>JSON with Padding<\/strong>&#8220;. In JSONP we include another domain URL with a parameter i.e callback. The callback&#8217;s value has a function name which must be present in your webpage.<\/p>\n<pre class=\"brush:js\">&lt;script&gt;\r\nfunction myCalllbackFunction(data){\r\n  console.log(data);\r\n} \r\n&lt;\/script&gt;\r\n\r\n&lt;script src=\"http:\/\/twitter.com\/status\/user_timeline\/padraicb.json?count=10&amp;callback=myCalllbackFunction\" type=\"text\/javascript\"&gt;&lt;\/script&gt;<\/pre>\n<h4><strong>Learn more about AJAX techniques <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-ajax-example\/\" target=\"_blank\">in this article<\/a><\/strong><\/h4>\n<h2><strong><a name=\"important\"><\/a>6. Questions on Important Concepts<\/strong><\/h2>\n<h4><strong>66. What is difference between $(this) and \u2018this\u2019 in jQuery?<\/strong><\/h4>\n<p>Refer the following example:<\/p>\n<pre class=\"brush:js\">$(document).ready(function()\r\n{\r\n$(\u2018#clickme\u2019).click(function()\r\n{\r\n     alert($(this).text());\r\n     alert(this.innerText);\r\n});\r\n});\r\n<\/pre>\n<p>&#8211; <code>this<\/code> and <code>$(this)<\/code> references the same element but the difference is that \u201cthis\u201d is used in traditional way but when \u201cthis\u201d is used with $() then it becomes a jQuery object on which we can use the functions of jQuery.<br \/>\n&#8211; In the example given, when only \u201cthis\u201d keyword is used then we can use the jQuery <code>text()<\/code> function to get the text of the element, because it is not jQuery object. Once the \u201cthis\u201d keyword is wrapped in <code>$()<\/code> then we can use the jQuery function text() to get the text of the element.<\/p>\n<h4><strong>67. How to check data type of any variable in jQuery?<\/strong><\/h4>\n<p>We use <code>$.type(Object)<\/code> which returns the built-in JavaScript type for the object.<\/p>\n<h4><strong>68. What is Chaining in jQuery?<\/strong><\/h4>\n<p>Chaining is a very powerful feature of jQuery. Chaining means specifying multiple functions and\/or selectors to an element.<\/p>\n<p>For example:<\/p>\n<pre class=\"brush:js\">$(document).ready(function()\r\n{\r\n     $('#mydiv').css('color', 'blue');\r\n     $('#mydiv').addClass('myclass');\r\n     $('#mydiv').fadeIn('fast');\r\n}\r\n<\/pre>\n<p>By using chaining we can write the above code as follows:<\/p>\n<pre class=\"brush:js\">$(document).ready(function()\r\n{\r\n     $('#mydiv').css('color', 'blue').addClass('myclass').fadeIn('fast');\r\n});\r\n<\/pre>\n<h4><strong>69. Which selectors are faster? ID or Class? <\/strong><\/h4>\n<p>ID is absolutely the fastest. ID selectors are known to be faster than Class and Element selectors. Part of the reason is that ID is supposed to be unique, so the API stops searching after the ID is found in the DOM.<\/p>\n<h4><strong>70. Is jQuery a W3C standard? Is it possible that jQuery HTML work for both HTML and XML?<\/strong><\/h4>\n<p>No, jQuery is not a W3C standard. And no again, jQuery HTML only works for HTML document. It doesn&#8217;t work for XML documents.<\/p>\n<h2><strong><a name=\"general\"><\/a>7. General Questions<\/strong><\/h2>\n<h4><strong>71. How do you check if an element exists or not in jQuery?<\/strong><\/h4>\n<p>Using jQuery length property, we can ensure whether element exists or not.<\/p>\n<pre class=\"brush:js\">$(document).ready(function(){\r\n    if ($('#element').length &gt; 0){\r\n       \/\/Element exists\r\n  }\r\n});\r\n<\/pre>\n<h4><strong>72. Are events also copied when you clone any element in jQuery?<\/strong><\/h4>\n<p>Using <code>clone()<\/code> method, we can create clone of any element but the default implementation of the <code>clone()<\/code> method doesn&#8217;t copy events unless you tell the <code>clone()<\/code> method to copy the events. The <code>clone()<\/code> method takes a parameter, if you pass true then it will copy the events as well.<\/p>\n<pre class=\"brush:js\">$(document).ready(function(){\r\n   $(\"#btnClone\").bind('click', function(){\r\n     $('#dvClickme').clone(true).appendTo('body');\r\n  });\r\n<\/pre>\n<h4><strong>73. What is each() function in jQuery? How do you use it?<\/strong><\/h4>\n<p>The <code>jQuery.each()<\/code> function is a general function that will loop through a collection (object type or array type). Array-like objects with a length property are iterated by their index position and value. Other objects are iterated on their key-value properties. The <code>jQuery.each()<\/code> function however works differently from the <code>$(selector).each()<\/code> function that works on the DOM element using the selector. But both iterate over a jQuery object.<\/p>\n<h4><strong>74. How can we disable Browser&#8217;s Back button through jQuery?<\/strong><\/h4>\n<p>We can do that like so:<\/p>\n<pre class=\"brush:js\">$(document).ready(function() {\r\n     window.history.forward(1);\r\n     \/\/OR\r\n     window.history.forward(-1);\r\n});\r\n<\/pre>\n<h4><strong>75. What is the difference between Map and Grep function in jQuery?<\/strong><\/h4>\n<p>In <code>$.map()<\/code> you need to loop over each element in an array and modify its value whilst the <code>$.Grep()<\/code> method returns the filtered array using some filter condition from an existing array. The basic structure of Map() is: <code>$.map ( array, callback(elementOfArray, indexInArray))<\/code>.<\/p>\n<h4><strong>76. How to disable jQuery animation?<\/strong><\/h4>\n<p>Using jQuery property &#8220;<code>jQuery.fx.off<\/code>&#8220;, which when set to true, disables all the jQuery animation. When this is done, all animation methods will immediately set elements to their final state when called, rather than displaying an effect.<\/p>\n<h4><strong>77. What is difference between jQuery.get() and jQuery.ajax() method?<\/strong><\/h4>\n<p><code>ajax()<\/code> method is more powerful and configurable, allows you to specify how long to wait and how to handle error, <code>get()<\/code> is a specialization over ajax just to retrieve some data.<\/p>\n<h4><strong>78. How does jQuery store data related to an element?<\/strong><\/h4>\n<p>In plain java scripts the information about an element can be stored by adding a domain object model property to the element. This results in memory leak problems in certain browsers. In jquery the user does not has to worry about memory management issues.<\/p>\n<p>For ex : Storing and retrieving data related to an element:<\/p>\n<pre class=\"brush:js\">$('#myDiv').data('keyName', { foo : 'bar' });\r\n$('#myDiv').data('keyName'); \/\/ { foo : 'bar' }\r\n<\/pre>\n<p>Jquery allows the user to store any kind of information on an element. The $.fn.data is used the most to store data related to an element.<\/p>\n<p>For ex : Storing of relationship between elements with the use of $.fn.data:<\/p>\n<pre class=\"brush:js\">$('#myList li').each(function() \r\n{\r\n     var $li = $(this), $div = $li.find('div.content');\r\n     $li.data('contentDiv', $div);\r\n});\r\n\/\/ later, the user is not required to look for the div again;\r\n\/\/ the data can simply be read from the list items data;\r\nvar $firstLi = $('#myList li:first');\r\n$firstLi.data('contentDiv').html('new content');\r\n<\/pre>\n<h4><strong>79. How we can use jQuery in ASP.NET?<\/strong><\/h4>\n<p>Make a folder with the name Scripts inside your application. Right click on <strong>Scripts<\/strong> folder &gt; <strong>Add Existing Item<\/strong> &gt; Browse to the path where you downloaded the jQuery library (jquery-1.3.2.js) and the intellisense documentation (jquery-1.3.2-vsdoc2.js). Select the files and click <strong>Add<\/strong>. The structure will look similar to the following image:<\/p>\n<figure id=\"attachment_10558\" aria-describedby=\"caption-attachment-10558\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-6.jpg\" rel=\"attachment wp-att-10558\"><img decoding=\"async\" class=\"wp-image-10558 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-6.jpg\" alt=\"jquery-qa-6\" width=\"820\" height=\"476\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-6.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-6-300x174.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/01\/jquery-qa-6-768x446.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-10558\" class=\"wp-caption-text\">Folder and file organisation inside an .ASP project!<\/figcaption><\/figure>\n<h4><strong>80. What is the proper way in jQuery to remove an element from the DOM before its Promise is resolved?<\/strong><\/h4>\n<p>A returned Promise in jQuery is linked to a <strong>Deferred<\/strong> object stored on the <code>.data()<\/code> for an element. Since the <code>.remove()<\/code> method removes the element\u2019s data as well as the element itself, it will prevent any of the element\u2019s unresolved <strong>Promises<\/strong> from resolving.<\/p>\n<p>Therefore, if it is necessary to remove an element from the DOM before its <strong>Promise<\/strong> is resolved, use <code>.detach()<\/code> instead and follow with <code>.removeData()<\/code> after resolution.<\/p>\n<h4><strong>81. What are the guidelines for an application to follow the principles of progressive enhancement?<\/strong><\/h4>\n<p>This is a quite general question, but it will probably be part of any interview you experience:<br \/>\nProgressive enhancement is web development technique that would allow the application to be accessible to any computer with any Internet connection. For an application to work on the principles of progressive enhancement the following rules \/ guidelines must be met:<\/p>\n<p>1. The basic content must be available to all browsers with any type of Internet connections.<br \/>\n2. The basic functionalities of an application must be working in all browsers.<br \/>\n3. The application will not override any of the user specified browser settings.<br \/>\n4. The css files are linked externally to control the look and feel of the page.<br \/>\n5. The javascripts should also be externally linked as it can enhance the user experience<\/p>\n<h2><strong><a name=\"conclusion\"><\/a>8. To conclude<\/strong><\/h2>\n<p>If you are going for an interview, where role demands multiple skills e.g. Java, jQuery, it&#8217;s not expected from you to know every minor detail or comprehensive knowledge of jQuery, but if you are going for a purely client side development role, you might get tricky and advanced jQuery questions. Nevertheless, you can use these questions to quickly revise some of the most frequently asked jQuery questions on interviews and have a clearer idea on what&#8217;s coming.<\/p>\n<p><em>Still with us? Wow, that was a huge article about different types of questions that can be used in a jQuery interview. If you enjoyed this, then <a href=\"http:\/\/www.webcodegeeks.com\/wcg-ebooks\/\"><strong>subscribe to our newsletter<\/strong><\/a> to enjoy weekly updates and complimentary whitepapers!<\/em><\/p>\n<p><em>So, what other jQuery interview questions are there? Let us know in the comments and we will include them in the article! Happy coding!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Without a doubt, jQuery has given a much needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery came into the picture, we used to write lengthy JavaScript code not just for bigger but even for smaller functionality. That code was at times both difficult to read and maintain. Having &hellip;<\/p>\n","protected":false},"author":75,"featured_media":919,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[303],"class_list":["post-10375","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery","tag-interview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Without a doubt, jQuery has given a much needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery came into the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Without a doubt, jQuery has given a much needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery came into the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/fabiocimo\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-02T13:23:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-21T13:35:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Fabio Cimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fabiocimo\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fabio Cimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"38 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/\"},\"author\":{\"name\":\"Fabio Cimo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22\"},\"headline\":\"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List\",\"datePublished\":\"2016-02-02T13:23:31+00:00\",\"dateModified\":\"2017-12-21T13:35:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/\"},\"wordCount\":6575,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"keywords\":[\"Interview\"],\"articleSection\":[\"jQuery\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/\",\"name\":\"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"datePublished\":\"2016-02-02T13:23:31+00:00\",\"dateModified\":\"2017-12-21T13:35:06+00:00\",\"description\":\"Without a doubt, jQuery has given a much needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery came into the\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"jQuery\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/jquery\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22\",\"name\":\"Fabio Cimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g\",\"caption\":\"Fabio Cimo\"},\"description\":\"Fabio is a passionate student in web tehnologies including front-end (HTML\/CSS) and web design. He likes exploring as much as possible about the world wide web and how it can be more productive for us all. Currently he studies Computer Engineering, at the same time he works as a freelancer on both web programming and graphic design.\",\"sameAs\":[\"https:\/\/www.facebook.com\/fabiocimo\",\"https:\/\/al.linkedin.com\/in\/fabiocimo\",\"https:\/\/x.com\/fabiocimo\",\"https:\/\/www.youtube.com\/fabiocimo1\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/fabio-cimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List - Web Code Geeks - 2026","description":"Without a doubt, jQuery has given a much needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery came into the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/","og_locale":"en_US","og_type":"article","og_title":"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List - Web Code Geeks - 2026","og_description":"Without a doubt, jQuery has given a much needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery came into the","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/fabiocimo","article_published_time":"2016-02-02T13:23:31+00:00","article_modified_time":"2017-12-21T13:35:06+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","type":"image\/jpeg"}],"author":"Fabio Cimo","twitter_card":"summary_large_image","twitter_creator":"@fabiocimo","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Fabio Cimo","Est. reading time":"38 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/"},"author":{"name":"Fabio Cimo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22"},"headline":"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List","datePublished":"2016-02-02T13:23:31+00:00","dateModified":"2017-12-21T13:35:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/"},"wordCount":6575,"commentCount":4,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","keywords":["Interview"],"articleSection":["jQuery"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/","name":"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","datePublished":"2016-02-02T13:23:31+00:00","dateModified":"2017-12-21T13:35:06+00:00","description":"Without a doubt, jQuery has given a much needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery came into the","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-interview-questions-answers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"jQuery","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/jquery\/"},{"@type":"ListItem","position":4,"name":"81 jQuery Interview Questions and Answers \u2013 The ULTIMATE List"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22","name":"Fabio Cimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g","caption":"Fabio Cimo"},"description":"Fabio is a passionate student in web tehnologies including front-end (HTML\/CSS) and web design. He likes exploring as much as possible about the world wide web and how it can be more productive for us all. Currently he studies Computer Engineering, at the same time he works as a freelancer on both web programming and graphic design.","sameAs":["https:\/\/www.facebook.com\/fabiocimo","https:\/\/al.linkedin.com\/in\/fabiocimo","https:\/\/x.com\/fabiocimo","https:\/\/www.youtube.com\/fabiocimo1"],"url":"https:\/\/www.webcodegeeks.com\/author\/fabio-cimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/10375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=10375"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/10375\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/919"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=10375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=10375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=10375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}