JQuery Interview Questions

JQuery Interview Questions

Q: What is jQuery?
A: 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. It is one of the most popular client side library and as per a survey it runs on every second website.
 
Q: Why do we use jQuery?
A: Due to following advantages.
                •               Easy to use and learn.
                •               Easily expandable.
                •               Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
                •               Easy to use for DOM manipulation and traversal.
                •               Large pool of built in methods.
                •               AJAX Capabilities.
                •               Methods for changing or applying CSS, creating animations.
                •               Event detection and handling.
                •               Tons of plug-ins for all kind of needs.
 
Q: How JavaScript and jQuery are different?
A: JavaScript is a language While jQuery is a library built in the JavaScript language that helps to use the JavaScript language.
 
Q: Is jQuery replacement of Java Script?
A: No. jQuery is not a replacement of JavaScript. jQuery is a different library which is written on top of JavaScript. jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML.
 
Q: Is jQuery a library for client scripting or server scripting?
A: Client side scripting.
 
Q: Is jQuery a W3C standard?
A: No. jQuery is not a W3C standard.
 
Q: What is the basic need to start with jQuery?
A: To start with jQuery, one need to make reference of it's library. The latest version of jQuery can be downloaded from jQuery.com.
 
Q: Which is the starting point of code execution in jQuery?
A: The starting point of jQuery code execution is $(document).ready() function which is executed when DOM is loaded.
 
Q: What does dollar sign ($) means in jQuery?
A: Dollar Sign is nothing but it's an alias for JQuery. Take a look at below jQuery code.

$(document).ready(function(){
});
Over here $ sign can be replaced with "jQuery" keyword.

jQuery(document).ready(function(){
});

Q: Can we have multiple document.ready() function on the same page?
A: YES. We can have any number of document.ready() function on the same page.
 
Q: Can we use our own specific character in the place of $ sign in jQuery?
A: Yes. It is possible using jQuery.noConflict().
 
Q: Is it possible to use other client side libraries like MooTools, Prototype along with jQuery?
A: Yes.
 
Q: What is jQuery.noConflict?
A: As other client side libraries like MooTools, Prototype can be used with jQuery and they also use $() as their global function and to define variables. This situation creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introduced jQuery.noConflict().

jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
   jQuery("div").hide();
}); 
You can also use your own specific character in the place of $ sign in jQuery.

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

Q: Is there any difference between body onload() and document.ready() function?
A: document.ready() function is different from body onload() function for 2 reasons.
1.             We can have more than one document.ready() function in a page where we can have only one body onload function.
2.             document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.
 
Q: What is the difference between .js and .min.js?
A: jQuery library comes in 2 different versions Development and Production/Deployment. The deployment version is also known as minified version. So .min.js is basically the minified version of jQuery library file. Both the files are same as far as functionality is concerned. but .min.js is quite small in size so it loads quickly and saves bandwidth.
 
Q: Why there are two different version of jQuery library?
A: jQuery library comes in 2 different versions.
1.             Development
2.             Production/Deployment
The development version is quite useful at development time as jQuery is open source and if you want to change something then you can make those changes in development version. But the deployment version is minified version or compressed version so it is impossible to make changes in it. Because it is compressed, so its size is very less than the production version which affects the page load time.
 
Q: What is a CDN?
A: A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance.
 
Q: Which are the popular jQuery CDN? and what is the advantage of using CDN?
A: There are 3 popular jQuery CDNs.
1. Google.
2. Microsoft
3. jQuery.

Advantage of using CDN.
•               It reduces the load from your server.
•               It saves bandwidth. jQuery framework will load faster from these CDN.
•               The most important benefit is it will be cached, if the user has visited any site which is using jQuery framework from any of these CDN
 
Q: How to load jQuery from CDN?
A: Below is the code to load jQuery from all 3 CDNs.
Code to load jQuery Framework from Google CDN

<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
Code to load jQuery Framework from Microsoft CDN

<script type="text/javascript"
    src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js">
</script>
Code to load jQuery Framework from jQuery Site(EdgeCast CDN)

<script type="text/javascript"
    src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>

Q: How to load jQuery locally when CDN fails?
A: It is a good approach to always use CDN but sometimes what if the CDN is down (rare possibility though) but you never know in this world as anything can happen.
Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
                if (typeof jQuery == 'undefined') {
                  document.write(unescape("%3Cscript src='Scripts/jquery.1.9.1.min.js' type='text/javascript'%3E%3C/script%3E"));
                }
</script>
It first loads the jQuery from Google CDN and then check the jQuery object. If jQuery is not loaded successfully then it will references the jQuery.js file from hard drive location. In this example, the jQuery.js is loaded from Scripts folder.
 
Q: What are selectors in jQuery and how many types of selectors are there?
A: To work with an element on the web page, first we need to find them. To find the html element in jQuery we use selectors. There are many types of selectors but basic selectors are: 
                •               Name: Selects all elements which match with the given element Name.
                •               #ID: Selects a single element which matches with the given ID
                •               .Class: Selects all elements which match with the given Class.
                •               Universal (*): Selects all elements available in a DOM.
                •               Multiple Elements E, F, G: Selects the combined results of all the specified selectors E, F or G.
                •               Attribute Selector: Select elements based on its attribute value.
 
Q: How do you select element by ID in jQuery?
A: To select element use ID selector. We need to prefix the id with "#" (hash symbol). For example, to select element with ID "txtName", then syntax would be,
$('#txtName')

Q: What does $("div") will select?
A: This will select all the div elements on page.
 
Q: How to select element having a particular class (".selected")?
A: $('.selected'). This selector is known as class selector. We need to prefix the class name with "." (dot).
 
Q: What does $("div.parent") will select?
A: All the div element with parent class.
 
Q: What are the fastest selectors in jQuery?
A: ID and element selectors are the fastest selectors in jQuery.
 
Q: What are the slow selectors in jQuery?
A: class selectors are the slow compare to ID and element.
 
Q: How jQuery selectors are executed?
A: Your last selectors is always executed first. For example, in below jQuery code, jQuery will first find all the elements with class ".myCssClass" and after that it will reject all the other elements which are not in "p#elmID".
$("p#elmID .myCssClass");

Q: Which is fast document.getElementByID('txtName') or $('#txtName').?
A: Native JavaScipt is always fast. jQuery method to select txtName "$('#txtName')" will internally makes a call to document.getElementByID('txtName'). As jQuery is written on top of JavaScript and it internally uses JavaScript only So JavaScript is always fast.
 
Q: Difference between $(this) and 'this' in jQuery?
A: this and $(this) refers to the same element. The only difference is the way they are used. 'this' is used in traditional sense, when 'this' is wrapped in $() then it becomes a jQuery object and you are able to use the power of jQuery.

$(document).ready(function(){
    $('#spnValue').mouseover(function(){
       alert($(this).text());
  });
});
In below example, this is an object but since it is not wrapped in $(), we can't use jQuery method and use the native JavaScript to get the value of span element.

$(document).ready(function(){
    $('#spnValue').mouseover(function(){
       alert(this.innerText);
  });
});

Q: How do you check if an element is empty?
A: There are Q: Ways to check if element is empty or not. We can check using ":empty" selector.
$(document).ready(function(){
    if ($('#element').is(':empty')){
       //Element is empty
  }
}); 
And the second way is using the "$.trim()" method.

$(document).ready(function(){
    if($.trim($('#element').html())=='') {
       //Element is empty
  }
}); 

Q: How do you check if an element exists or not in jQuery?
A: Using jQuery length property, we can ensure whether element exists or not.

$(document).ready(function(){
    if ($('#element').length > 0){
       //Element exists
  }
});

Q: What is the use of jquery .each() function?
A: 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.
 
Q: What is the difference between jquery.size() and jquery.length?
A: 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.
 
Q: What is the difference between $('div') and $('<div/>') in jQuery?
A: $('<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.
 
Q: What is the difference between parent() and parents() methods in jQuery?
A: The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree.
 
Q: What is the difference between eq() and get() methods in jQuery?
A: eq() 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.
get() return a DOM element. The method retrieve the DOM elements matched by the jQuery object. But as it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can't be used. Find out more here.
 
Q: How do you implement animation functionality?
A: The .animate() 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:
(selector).animate({styles},speed,easing,callback)
•               styles: Specifies one or more CSS properties/values to animate.
•               duration: Optional. Specifies the speed of the animation.
•               easing: Optional. Specifies the speed of the element in different points of the animation. Default value is "swing".
•               callback: Optional. A function to be executed after the animation completes.
Simple use of animate function is,

$("btnClick").click(function(){
  $("#dvBox").animate({height:"100px"});
});

Q: How to disable jQuery animation?
A: Using jQuery property "jQuery.fx.off", 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.
 
Q: How do you stop the currently-running animation?
A: Using jQuery ".stop()" method.
 
Q: What is the difference between .empty(), .remove() and .detach() methods in jQuery?
A: All these methods .empty(), .remove() and .detach() are used for removing elements from DOM but they all are different.
.empty(): This method removes all the child element of the matched element where remove() method removes set of matched elements from DOM.
.remove(): Use .remove() when you 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.
.detach(): This method is the same as .remove(), except that .detach() 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.

Q: Explain .bind() vs .live() vs .delegate() vs .on()
A: All these 4 jQuery methods are used for attaching events to selectors or elements. But they all are different from each other.

.bind(): This is the easiest and quick method to bind events. But the issue with bind() is that it doesn'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.
.live(): 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.
.delegate(): 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.
.on(): Since live was deprecated with 1.7, so new method was introduced named ".on()". This method provides all the goodness of previous 3 methods and it brings uniformity for attaching event handlers. 

Q: What is wrong with this code line "$('#myid.3').text('blah blah!!!');"
A: The problem with above statement is that the selectors is having meta characters and to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").
So the correct syntax is,
$('#myid\\.3').text('blah blah!!!');
 
Q: How to create clone of any object using jQuery?
A: jQuery provides clone() 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.
$(document).ready(function(){
  $('#btnClone').click(function(){
     $('#dvText').clone().appendTo('body');
     return false;
  });
});

Q: Does events are also copied when you clone any element in jQuery?
A: As explained in previous question, using clone() method, we can create clone of any element but the default implementation of the clone() method doesn't copy events unless you tell the clone() method to copy the events. The clone() method takes a parameter, if you pass true then it will copy the events as well.
$(document).ready(function(){
   $("#btnClone").bind('click', function(){
     $('#dvClickme').clone(true).appendTo('body');
  });

Q: What is difference between prop and attr?
A: attr(): Get the value of an attribute for the first element in the set of matched elements. Whereas,.prop(): (Introduced in jQuery 1.6) Get the value of a property for the first element in the set of matched elements.
Attributes carry additional information about an HTML element and come in name="value" 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.
attr() gives you the value of element as it was defines in the html on page load. It is always recommended to use prop() to get values of elements which is modified via javascript/jquery , as it gives you the original value of an element's current state.
 
Q: What is event.PreventDefault?
A: The event.preventDefault() method stops the default action of an element from happening. For example, Prevents a link from following the URL.
 
Q: What is the difference between event.PreventDefault and event.stopPropagation?
A: event.preventDefault(): Stops the default action of an element from happening.
event.stopPropagation(): 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.
 
Q: What is the difference between event.PreventDefault and "return false"?
A:e.preventDefault() will prevent the default event from occurring, e.stopPropagation() will prevent the event from bubbling up and return false will do both.
 
Q: What is the difference between event.stopPropagation and event.stopImmediatePropagation?
A:event.stopPropagation() allows other handlers on the same element to be executed, while event.stopImmediatePropagation() prevents every event from running. For example, see below jQuery code block.
$("p").click(function(event){
  event.stopImmediatePropagation();
});
$("p").click(function(event){
  // This function won't be executed
  $(this).css("background-color", "#f00");
});
If event.stopPropagation was used in previous example, then the next click event on p element which changes the css will fire, but in case event.stopImmediatePropagation(), the next p click event will not fire.
 
Q: How to check if number is numeric while using jQuery 1.7+?
A: Using "isNumeric()" function which was introduced with jQuery 1.7.
 
Q: How to check data type of any variable in jQuery?
A: Using $.type(Object) which returns the built-in JavaScript type for the object.
 
Q: How do you attach a event to element which should be executed only once?
A: Using jQuery one() 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.
$(document).ready(function() {
    $("#btnDummy").one("click", function() {
        alert("This will be displayed only once.");
    });
});

Q: Can you include multiple version of jQuery? If yes, then how they are executed?
A: Yes. Multiple versions of jQuery can be included in same page.
 
Q: In what situation you would use multiple version of jQuery and how would you include them?
A: Well, it is quite possible that the jQuery plugins which are used are dependent on older version but for your own jQuery code, you would like to use newer version. So because of this dependency, multiple version of jQuery may required sometimes on single page.

Below code shows how to include multiple version of jQuery.
<script type='text/javascript' src='js/jquery_1.9.1.min.js'></script>

<script type='text/javascript'>
                var $jq = jQuery.noConflict();
</script>

<script type='text/javascript' src='js/jquery_1.7.2.min.js'></script>
By this way, for your own jQuery code use "$jq", instead of "$" as "$jq" refers to jQuery 1.9.1, where "$" refers to 1.7.2.
 
Q: Is it possible to hold or delay document.ready execution for sometime?
A: Yes, its possible. With Release of jQuery 1.6, a new method "jQuery.holdReady(hold)" was introduced. This method allows to delay the execution of document.ready() event. document.ready() event is called as soon as your DOM is ready but sometimes there is a situation when you want to load additional JavaScript or some plugins which you have referenced.
$.holdReady(true);
$.getScript("myplugin.js", function() {
     $.holdReady(false);
});

Q: What is chaining in jQuery?
A: Chaining is one of the most powerful feature of jQuery. In jQuery, Chaining means to connect multiple functions, events on selectors. It makes your code short and easy to manage and it gives better performance. The chain starts from left to right. So left most will be called first and so on.
$(document).ready(function(){
    $('#dvContent').addClass('dummy');
    $('#dvContent').css('color', 'red');
    $('#dvContent').fadeIn('slow');
});
The above jQuery code sample can be re-written using chaining. See below.
$(document).ready(function(){
    $('#dvContent').addClass('dummy')
          .css('color', 'red')
          .fadeIn('slow');    
});
Not only functions or methods, chaining also works with events in jQuery.
 
Q: How does caching helps and how to use caching in jQuery?
A: Caching is an area which can give you awesome performance, if used properly and at the right place. While using jQuery, you should also think about caching. For example, if you are using any element in jQuery more than one time, then you must cache it. See below code.
$("#myID").css("color", "red");
//Doing some other stuff......
$("#myID").text("Error occurred!");

Now in above jQuery code, the element with #myID is used twice but without caching. So both the times jQuery had to traverse through DOM and get the element. But if you have saved this in a variable then you just need to reference the variable. So the better way would be,
var $myElement = $("#myID").css("color", "red");
//Doing some other stuff......
$myElement.text("Error occurred!");

So now in this case, jQuery won't need to traverse through the whole DOM tree when it is used second time. So in jQuery, Caching is like saving the jQuery selector in a variable. And using the variable reference when required instead of searching through DOM again.
 
Q: You get "jquery is not defined" or "$ is not defined" error. What could be the reason?
A: There could be many reasons for this.
•               You have forgot to include the reference of jQuery library and trying to access jQuery.
•               You have include the reference of the jQuery file, but it is after your jQuery code.
•               The order of the scripts is not correct. For example, if you are using any jQuery plugin and you have placed the reference of the plugin js before the jQuery library then you will face this error.

Q: How to write browser specific code using jQuery?
A: Using jQuery.browser property, we can write browser specific code. This property contains flags for the useragent, read from navigator.userAgent. This property was removed in jQuery 1.9.
 
Q: Can we use jQuery to make ajax request?
A: Yes. jQuery can be used for making ajax request.

Q: What are various methods to make ajax request in jQuery?
A: Using below jQuery methods, you can make ajax calls.
•               load() : Load a piece of html into a container DOM
•               $.getJSON(): Load JSON with GET method.
•               $.getScript(): Load a JavaScript file.
•               $.get(): Use to make a GET call and play extensively with the response.
•               $.post(): Use to make a POST call and don't want to load the response to some container DOM.
•               $.ajax(): Use this to do something on XHR failures, or to specify ajax options (e.g. cache: true) on the fly.

Q: Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?
A: By using jQuery post()/ jQuery get(), you always trust the response from the server and you believe it is going to be successful all the time. Well, it is certainly not a good idea to trust the response. As there can be n number of reason which may lead to failure of response.
Where jQuery.ajax() is jQuery's low-level AJAX implementation. $.get and $.post are higher-level abstractions that are often easier to understand and use, but don't offer as much functionality (such as error callbacks). 

Q: What are deferred and promise object in jQuery?
A: Deferred and promise are part of jQuery since version 1.5 and they help in handling asynchronous functions like Ajax. 

Q: Can we execute/run multiple Ajax request simultaneously in jQuery? If yes, then how?
A: Yes, it is possible to execute multiple Ajax request simultaneously or in parallel. Instead of waiting for first ajax request to complete and then issue the second request is time consuming. The better approach to speed up things would be to execute multiple ajax request simultaneously.
Using jQuery .when() method which provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events. Find out more here.
 
Q: Can you call C# code-behind method using jQuery? If yes,then how?
A: Yes. We can call C# code-behind function via $.ajax. But for do that it is compulsory to mark the method as WebMethod.
 
Q: Which is the latest version of jQuery library?
A: The latest version (when this post is written) of jQuery is 1.10.2 or 2.0.3. jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.
 
Q: Does jQuery 2.0 supports IE?
A: No. jQuery 2.0 has no support for IE 6 IE 7 and IE 8.
 
Q: What are source maps in jQuery?
A: In case of jQuery, Source Map is nothing but mapping of minified version of jQuery against the un-minified version. Source map allows to debug minified version of jQuery library. Source map feature was release with jQuery 1.9

Q: How to use migrate jQuery plugin?
A: with release of 1.9 version of jQuery, many deprecated methods were discarded and they are no longer available. But there are many sites in production which are still using these deprecated features and it's not possible to replace them overnight. So jQuery team provided with jQuery Migrate plugin that makes code written prior to 1.Q: Work with it.
So to use old/deprecated features, all you need to do is to provide reference of jQuery Migrate Plugin. 

Q: Is it possible to get value of multiple CSS properties in single statement?
A: Well, before jQuery 1.9 release it was not possible but one of the new feature of jQuery 1.Q: Was .css() multi-property getter.
var propCollection = $("#dvBox").css([ "width", "height", "backgroundColor" ]);
In this case, the propCollection will be an array and it will look something like this.
{
  width: "100px",
  height: "200px",
  backgroundColor: "#FF00FF"
}

Q: How do you stop the currently-running animation, remove all queued animations, and complete all animations for the matched elements?
A: It can be done via calling .stop([clearQueue ] [, jumpToEnd ]) method and by passing both the parameters as true.
 
Q: What is finish method in jQuery?
A: The .finish() method stops all queued animations and places the element(s) in their final state. This method was introduced in jQuery 1.9.
 
Q: What is the difference between calling stop(true,true) and finish method?
A: The .finish() method is similar to .stop(true, true) in that it clears the queue and the current animation jumps to its end value. It differs, however, in that .finish() also causes the CSS property of all queued animations to jump to their end values, as well.
 
Q: Consider a scenario where things can be done easily with javascript, would you still prefer jQuery?
A: No. If things can be done easily via CSS or JavaScript then You should not think about jQuery. Remember, jQuery library always comes with xx kilobyte size and there is no point of wasting bandwidth.
 
Q: Can we use protocol less URL while referencing jQuery from CDNs?
A: Yes. Below code is completely valid.
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Q: What is the advantage of using protocol less URL while referencing jQuery from CDNs?
A: It is quite useful when you are moving from HTTP to HTTPS url. You need to make sure that correct protocol is used for referencing jQuery library as pages served via SSL should contain no references to content served through unencrypted connections.

"protocol-less" URL is the best way to reference third party content that’s available via both HTTP and HTTPS. When a URL’s protocol is omitted, the browser uses the underlying document’s protocol instead.

Q: What is jQuery plugin and what is the advantage of using plugin?
A: 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.
 
Q: What is jQuery UI?
A: jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library that can be used to build interactive web applications.
 
Q: What is the difference between jQuery and jQuery UI?
A: jQuery is the core library. jQueryUI is built on top of it. If you use jQueryUI, you must also include jQuery.

Q: What is jQuery?
A: jQuery is not a programming language but a well written JavaScript code. It is a JavaScript code, which do document traversing, event handling, Ajax interactions and Animations.

Q: Why jQuery is needed?
A: jQuery is needed for the following list:
•               Used to develop browser compatible web applications
•               Improve the performance of an application
•               Very fast and extensible
•               UI related functions are written in minimal lines of codes

Q: Whether jQuery HTML work for both HTML and XML documents?
A: No, jQuery HTML only works for HTML documents not for XML Documents.

Q: What are the methods used to provide effects?
A: Some of the effects methods are:
•               Show()
•               Hide()
•               Toggle()
•               FadeIn() and
•               FadeOut()

Q: What is the advantage of using minimized version of jQuery?
A: Efficiency of web page increases when minimized version of jQuery is used.min.js file will be more than 50% less than the normal js file. Reduction in the file size makes the web page faster.

Q: Is jQuery is a JavaScript or JSON library file?
A: jQuery is a library of JavaScript file and it consists of DOM, event effects and the Ajax functions. jQuery is said to be a single JavaScript file.

Q: Which operating system is more compatible with jQuery?
A: Mac, Windows and Linux are more compatible with the jQuery.

Q: How can we include jQuery library in ASP.Net project?
A: Download the jQuery library from jQuery.com and include that reference in the asp.net page.

Q: Which command will give a version of jQuery?
A: The command $.ui.version returns jQuery UI version.

Q: In what scenarios jQuery can be used?
A: jQuery can be used in following scenarios:
•               Apply CSS static or dynamic
•               Calling functions on events
•               Manipulation purpose
•               Mainly for Animation effects

Q: What is the difference between find and children methods?
A: Find method is used to find all levels down the DOM tree but children find single level down the DOM tree.

Q: What is jQuery connect?
A: A ‘ jQuery connect’  is a plugin used to connect or bind a function with another  function. Connect is used to execute function from any other function or plugin is executed.

Q: How to use connect?
A: Connect can be used by downloading jQuery connect file from jQuery.com and then include that file in the HTML file. Use $.connect function to connect a function to another function.

Q: What are the features of jQuery, has been used in web applications?
A: jQuery uses features like Sliding, File uploading and accordian in web applications.

Q: What are the browser related issues for jQuery?
A: Browser compatibility of jQuery plugin is an issue and needs lot of time to fix it.

Q: Whether we need to add jQuery file in both Master and Content page?
A: jQuery file should be added to the Master page and can use access from the content page directly without having any reference to it.

Q: What are the basic selectors in jQuery?
A: Following are the basic selectors in jQuery:
•               Element ID
•               CSS Name
•               Tag Name
•               DOM hierarchy

Q: Can we call C# code behind using jQuery?
A: Yes, we can call C# code from jQuery as it supports .net application.

Q: What is the use jQuery.data method?
A: jQuery.data methods is used to associate the data with the DOM nodes and the objects. This data method makes the jQuery code clear and concise.

Q: What is the use of each function in jQuery?
A: Each function is used to iterate each and every element of an object. It is used to loop DOM elements, arrays and the object properties.

Q: What is the difference between size and length of jQuery?
A: Size and length both returns the number of element in an object. But length is faster than the size because length is a property and size is a method.

Q: Can we add more than one ‘document.ready’ function in a page?
A: Yes, we can add more than one document.ready function in a page. But, body.onload can be added once in a page.

Q: What is the use of jQuery load method?
A: jQuery load method is a powerful AJAX method which is used to load the data from a server and assign the data into the element without loading the page.

Q: Whether our own specific characters are used in place of $ in jQuery?
A: Yes, We can use our own variable in place of $ by suing the method called no Conflict () method.
var sample = $.noConflict()

Q: What are the four parameters used for jQuery Ajax method?
A: The four parameters are
•               URL – Need to specify the URL to send the request
•               type – Specifies type of request(Get or Post)
•               data – Specifies data to be sent to server
•               Cache – Whether the browser should cache the requested page

Q: What is the use of jQuery filter?
A: The jQuery filter is used to filter the certain values from the object list based on the criteria. Example is to filter certain products from the master list of products in a cart website.

Q: Which program is useful for testing jQuery?
A: QUnit is used to test jQuery and it is very easy and efficient.

Q: What is CDN?
A: CDN is abbreviated as Content Distribution network and it is said to be a group of companies in different location with network containing copies of data files to maximize bandwidth in accessing the data.

Q: What are the two types of CDNs?
A: There are two types of CDNs:
•               Microsoft – Load jQuery from Ajax CDN
•               Google – Load jQuery from Google libraries API

Q: Which sign is used as a shortcut for jQuery?
A: Dollar ($) sign is used as a shortcut for jQuery.

Q: Is jQuery is a client or server scripting?
A: jQuery is a client scripting.

Q: What is the script build up by jQuery?
A: jQuery is a Javascript file and it is single javascript file that contains common DOM, event effects and Ajax functions.

Q: How can we debug jQuery?
A: There are two ways to debug jQuery:
Debugger keyword
•               Add the debugger to the line from where we have to start debugging and then run Visual Studio in Debug mode with F5 function key.
•               Insert a break point after attaching the process

Q: What are all the ways to include jQuery in a page?
A: Following are the ways to include jQuery in a page:
•               Local copy inside script tag
•               Remote copy of jQuery.com
•               Remote copy of Ajax API
•               Local copy of script manager control
•               Embedded script using client script object

Q: What is the use of jQuery.ajax method ()?
A: jQuery.ajax method is used for asynchronous HTTP requests.

Q: Where can we download JQuery?
A: jQuery javascript can be downloaded from jQuery official website – www.jquery.com

Q: Is jQuery is a replacement of JavaScript?
A: No, jQuery is not a replacement of JavaScript.

Q: What is called chaining?
A: Chaining is used to connect multiple events and functions in a selector.

Q: What are the advantages of jQuery?
A: Following are the advantages of jQuery:
•               Just a JavaScript enhancement
•               Coding is simple, clear, reusable
•               Removal of writing more complex conditions and loops

Q: Whether C# code behind can be called from jQuery?
A: Yes, we can call C# code behind from jQuery.

Q: What is the use of jQuery.data() method?
A: jQuery data method is used to associate data with DOM nodes and JavaScript objects. This method will make a code very concise and neat.

Q: What is the difference between onload() and document.ready()?
A: In a page, we can have only one onload function but we can have more than one document.ready function. Document.ready function is called when DOM is loaded but onload function is called when DOM and images are loaded on the page.

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

Q: How method can be called inside code behind using jQuery?
A: $.ajax can be called and by declaring WebMethod inside code behind using jQuery.

Q: Which is the fastest selector in jQuery?
A: ID and Element are the fastest selectors in jQuery.

Q: What is the slowest selector in jQuery?
A: Class selectors are the slowest selectors in jQuery.

Q: Where jQuery code is getting executed?
A: jQuery code is getting executed on a client browser.

Q: What is the method used to define the specific character in place of $ sign?
A: ‘NoConflict’ method is used to reference a jQuery and save it in a variable. That variable can be used instead of Sign.

Q: Why jQuery is better than JavaScript?
A: jQuery is a library used for developing Ajax application and it helps to write the code clean and concise. It also handles events, animation and Ajax support applications.

Q: What are the types of selectors in jQuery?
A: There are three types of selectors in jQuery:
•               CSS Selector
•               XPath Selector
•               Custom Selector

Q: What is jQuery Selectors? Give some examples.
A: •          jQuery Selectors are used to select one or a group of HTML elements from your web page.
•               jQuery support all the CSS selectors as well as many additional custom selectors.
•               jQuery selectors always start with dollar sign and parentheses: $()
•               There are three building blocks to select the elements in a web document.
1) Select elements by tag name
Example: $(div)
It will select all the div elements in the document.

Q: Select elements by ID
A: Example: $(#xyzid”)
It will select single element that has an ID of xyzid

Q: Select elements by class
A: Example: $(“.xyzclass”)
It will select all the elements having class xyzclass

Q: How can we give face effect in jQuery?
A: •          In jQuery we have three methods to give the fade effect to elements: fadeIn, fadeOut and fadeTo
•               This methods change the opacity of element with animation.
Syntax:
$(selector).fadeIn(speed,callback)
$(selector).fadeOut(speed,callback)
$(selector).fadeTo(speed,opacity,callback)
•               “speed” can be one of following values : “slow”, “fast”, “normal” or milliseconds
•               “opacity” specify the value that allows the fading to given opacity.
•               “callback” is the function which we want to run once the fading effect is complete.
For example
$("clickme").click(function(){
$("mydiv").fadeTo("slow",0.50);
});

$("clickme").click(function(){
$("mydiv").fadeOut(3000);
});.

Q: Explain the animate function.
A: -The animate function is used to apply the custom animation effect to elements.
-Syntax:
$(selector).animate({params}, [duration], [easing], [callback])
•               “param” defines the CSS properties on which you want to apply the animation.
•               “duration” specify how long the animation will run. It can be one of following values : “slow”, “fast”, “normal” or milliseconds
•               “easing” is the string which specify the function for the transition.
•               “callback” is the function which we want to run once the animation effect is complete.
For example
Click Me
Following is the jQuery to animate opacity, left offset, and height of the mydiv element

$('# clickToAnimate’).click(function() {
$('#book').animate({
opacity: 0.30,
left: '+=20',
height: 'toggle'
}, 3000, function() {
// run after the animation complete.
});
});

Q: What is .siblings() method in jQuery?
A: •          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.
•               Syntax : .siblings( [selector])
•               “selector” is the selector expression which specify the matched elements.
For example
·         item 1
·         item 2
·         item 3
·         item 4
Now we want to find the siblings of the element of id “second_item” and change the text color to Blue :
$(‘li.second_item’).siblings().css(‘color’,’blue’);
If we want specific sibling elements for example the elements having class “myitem” then we can pass a optional selector:
$(‘li.second_item’).siblings(‘.myitem’).css(‘color’,’blue’);

Q: Explain width() vs css(‘width’).
A: •          In jQuery, there are two way to change the width of an element.
•               One way is using .css(‘width’) and other way is using .width().
For example
$(‘#mydiv’).css(‘width’,’300px’);
$(‘#mydiv’).width(100);
•               The difference in .css(‘width’) and .width() is the data type of value we specify or return from the both functions.
•               In .css(‘width’) we have to add “px” in the width value while in .width() we don’t have to add.
•               When you want to get the width of “mydiv” element then .css(‘width’) will return ‘300px’ while .width() will return only integer value 300.

Q: What is the use of jQuery.data()?
A: •          jQuery.data() is used to set/return arbitrary data to/from an element.
•               Syntax: jQuery.data(element, key, value)
•               “element” is the DOM element to which the data is associated.
•               “key” is an arbitrary name of the piece of data.
•               “value” is value of the specified key.
•               Suppose we want to set the data for a span element:
jQuery.data(span, “item”, { val1: 10, val2: "myitem" });
If we want to retrieve the data related to div element and set it to label’s data:
$("label:val1").text(jQuery.data(div, "item").val1);
$("label:val2").text(jQuery.data(div, "item").val2);

Q: Explain bind() vs live() vs delegate() methods.
A: -The bind() method will not attach events to those elements which are added after DOM is loaded while live() and delegate() methods attach events to the future elements also.
-The difference between live() and delegate() methods is live() function will not work in chaining. It will work only on an selector or an element while delegate() method can work in chaining.
For example
$(document).ready(function(){
                $("#myTable").find("tr").live("click",function(){
                                alert($(this).text());
                });
});

Above code will not work using live() method. But using delegate() method we can accomplish this.
$(document).ready(function(){
$("#dvContainer")children("table").delegate("tr","click",function(){
alert($(this).text());
});
});

Q: Explain the each() function.
A: -The each() function specify the function to be called for every matched element.
Syntax:
$(selector).each(function (index, element))
•               “index” is the index position of the selector.
•               “selector” specifies the current selector where we can use “this” selector also.
•               In the case when we need to stop the each loop early then we can use “return false;”
For example
$("#clickme").click(function(){
                $("li").each(function(){
                                document.write($(this).text())
                });
});
This will write the text for each “li” element.

Q: Explain slideToggle() effect.
A: -slideToggle() effect is used to give animated sliding effect to an element.

Syntax:
slideToggle([ duration] [, easing] [, callback])
•               “duration” is the number specifying how long the animation will run.
•               “easing” is the string which specify the function for the transition.
•               “callback” is the function which we want to run once the animation is complete.
•               If the element is visible then this effect will slide the element up side and make it completely hidden. If the element is hidden then slideToggle() effect will slide it down side and make it visible.
•               We can specify the toggle speed with this effect.
For example
$("#clickme").click(function(){
                $("#mydiv").slideToggle(“slow”, function(){
                                //run after the animation is complete.
                });
});

Q: What is difference between $(this) and ‘this’ in jQuery?
A: Refer the following example
$(document).ready(function(){
                $(‘#clickme’).click(function(){
                                alert($(this).text());
                                alert(this.innerText);
                });
});
-this and $(this) references the same element but the difference is that “this” is used in traditional way but when “this” is used with $() then it becomes a jQuery object on which we can use the functions of jQuery.
-In the example given, when only “this” keyword is used then we can use the jQuery text() function to get the text of the element, because it is not jQuery object. Once the “this” keyword is wrapped in $() then we can use the jQuery function text() to get the text of the element.

Q: What is the use of param() method.
A: •          The param() method is used to represent an array or an object in serialize manner.
•               While making an ajax request we can use these serialize values in the query strings of URL.
•               Syntax: $.param(object | array, boolValue)
•               “object | array” specifies an array or an object to be serialized.
•               “boolValue” specifies whether to use the traditional style of param serialization or not.
For example:
personObj=new Object();
empObject.name="Arpit";
empObject.age="24";
empObject.dept=”IT”;

$("#clickme").click(function(){
                $("span").text($.param(empObject));
});
It will set the text of span to “name=Arpit&age=24&dep=IT”

Q: What is jQuery.holdReady() function?
A: -By using jQuery.holdReady() function we can hold or release the execution of jQuery’s ready event.
-This method should be call before we run ready event.
-To delay the ready event, we have to call
jQuery.holdReady(true);
-When we want to release the ready event then we have to call
jQuery.holdReady(false);
-This function is helpful when we want to load any jQuery plugins before the execution of ready event.
For example
$.holdReady(true);
$.getScript("xyzplugin.js", function() {
                $.holdReady(false);
});

Q: Explain .empty() vs .remove() vs .detach().
A: -.empty() method is used to remove all the child elements from matched elements.
-.remove() method is used to remove all the matched element. This method will remove all the jQuery data associated with the matched element.
-.detach() method is same as .remove() method except that the .detach() method doesn’t remove jQuery data associated with the matched elements.
-.remove() is faster than .empty() or .detach() method.
Syntax:
$(selector).empty();
$(selector).remove();
$(selector).detach();

Q: How to read, write and delete cookies in jQuery?
A: -To deal with cookies in jQuery we have to use the Dough cookie plugin.
-Dough is easy to use and having powerful features.
-Create cookie
$.dough("cookie_name", "cookie_value");
Read Cookie
$.dough("cookie_name");
Delete cookie
$.dough("cookie_name", "remove");

Q: Is window.onload is different from document.ready()?
A: - The window.onload() is Java script function and document.ready() is jQuery event which are called when page is loaded.
- The difference is that document.ready() is called after the DOM is loaded without waiting for all the contents to get loaded. While window.onload() function waits until the contents of page is loaded.
- Suppose there is very large image on a page, at that time window.onload() will wait until that image is loaded totally.
- So while using the window.onlaod() function the execution will be slow, but the document.ready() will not wait until the image is loaded.

Q: What is Chaining in jQuery?
A: - Chaining is very powerful feature of jQuery.
- Chaining means specifying multiple function and/or selectors to an element.
- Examine the below example
$(document).ready(function(){
$('#mydiv').css('color', 'blue');
$('#mydiv').addClass('myclass');
$('#mydiv').fadeIn('fast');
}
By using chaining we can write above code as follows
$(document).ready(function(){
$('#mydiv').css('color', 'blue').addClass('myclass').fadeIn('fast');
});
-Advantage of chaining is that it makes your code simple and simple to manage.
-The execution becomes faster because the code search for the element only once.

Q: What is difference between sorting string array and sorting numerical array in jQuery?
A: The sort method is used to sort any array elements. It sorts the string elements alphabetically.
For example
$(document).ready(function(){
                var mylist = [ “Apple”,”Orange”,”Banana”];
                mylist = mylist.sort();
                $(“#mydiv”).html(list.join(“”));
});
It will give following output
Apple
Banana
Orange

Now we declare a numerical array and use sort() method to sort its elements.
$(document).ready(function(){
                var mylist = [ “20”,”3””100”,”50”];
                mylist = mylist.sort();
                $(“#mydiv”).html(list.join(“”));
});
It will give following output
100
20
3
50

Q: What is difference between prop and attr?
A: •          In jQuery both prop() and attr() function is used to set/get the value of specified property of an element.
•               The difference in both the function is that attr() returns the default value of the property while the prop() returns the current value of the property.
For example
<input value="My Value" type="text"/>

$('input').prop('value', 'Changed Value');

-.attr('value') will return 'My Value'
-.prop('value') will return 'Changed Value'

Q: How to always reference latest version of jQuery?
A: When you reference the jQuery on your web page, you have to specify the version number also.
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”>
</script>

Above code will always load the 1.5.1 version of jQuery. If you reference the latest jQuery then you don’t need to change the code every time the new version of jQuery is released.
To achieve this you have to use following code
<script type=”text/javascript” src=”http://code.jquery.com/jquery-latest.min.js”></script>
This code will always reference the latest version of jQuery in your page.

Q: What is resize() function in jQuery?
A: The resize() function is called whenever the browser size is changed. This event can be only used with $(window).
Syntax:
.resize([event_data], handler(event_object))
-The “event_data” is the data to be sent to the handler.
-The “handler(event_object)” is a function to be called each time when the window is resized.
For example
$(window).resize(function() {
$('#message).text('window is resized to ' + $(window).width() + ‘x’ + $(window).height());
});

Q: What is method chaining in jQuery? Provide an example. What advantages does it offer?
A: Method chaining is a feature of jQuery that allows several methods to be executed on a jQuery selection in sequence in a single code statement. For example, the following snippets of code are equivalent:

Without chaining:
$( "button#play-movie" ).on( "click", playMovie );
$( "button#play-movie" ).css( "background-color", "orange" );
$( "button#play-movie" ).show();

With chaining:
$( "button#play-movie" ).on( "click", playMovie )
                        .css( "background-color", "orange" )
                        .show();

Notice that with chaining, the button only needs to be selected one time, whereas without chaining, jQuery must search the whole DOM and find the button before each method is applied. Thus, in addition to yielding more concise code, method chaining in jQuery offers a potentially powerful performance advantage.

Q: What is the difference between jQuery.get() and jQuery.ajax()?
A: jQuery.ajax() is the all-encompassing Ajax request method provided by jQuery. It allows for the creation of highly-customized Ajax requests, with options for how long to wait for a response, how to handle a failure, whether the request is blocking (synchronous) or non-blocking (asynchronous), what format to request for the response, and many more options.

jQuery.get() is a shortcut method that uses jQuery.ajax() under the hood, to create an Ajax request that is typical for simple retrieval of information. Other pre-built Ajax requests are provided by jQuery, such as jQuery.post(), jQuery.getScript(), and jQuery.getJSON().

Q: 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.
A: Let’s say you want to retrieve all elements whose IDs end with “txtTitle”. This could be done using the following selector:

$("[id$='txtTitle']")

To retrieve only <div> elements whose IDs end with “txtTitle”, the selector would be:

$("div[id$='txtTitle']")

Q: Which of the two lines of code below is more efficient? Explain your answer.
document.getElementById( "logo" );
or
$( "#logo" );
A: 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.
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.

Q: Explain what the following code will do:
$( "div#first, div.first, ol#items > [name$='first']" )
A: This code performs a query to retrieve any <div> element with the id first, plus all <div> elements with the class first, plus all elements which are children of the <ol id="items"> element and whose name attribute ends with the string "first". This is an example of using multiple selectors at once. The function will return a jQuery object containing the results of the query.

Q: Explain what the following code does:
$( "div" ).css( "width", "300px" ).add( "p" ).css( "background-color", "blue" );
A: This code uses method chaining to accomplish a couple of things. First, it selects all the <div> elements and changes their CSS width to 300px. Then, it adds all the <p> elements to the current selection, so it can finally change the CSS background color for both the <div> and <p> elements to blue.

Q: The code below is for an application that requires defining a click handler for all buttons on the page, inlcuding 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?
// define the click handler for all buttons
$( "button" ).bind( "click", function() {
    alert( "Button Clicked!" )
});

/* ... some time later ... */
// dynamically add another button to the page
$( "html" ).append( "<button>Click Alert!</button>" );
A: The button that is added dynamically after the call to bind() will not have the click handler attached. This is because the bind() method only attaches handlers to elements that exist at the time the call to bind() is made.

This problem is solved with functions that use “event bubbling” to match events on both current and future elements. In the past, this was done by replacing bind() with live(). live() was deprecated in jQuery 1.7 though. delegate() works similarly to live() but also provides control over how far an event must bubble up the DOM.

However, the recommended method is to use on(), which can behave like bind(), live(), or delegate() depending on syntax. The following code attaches the handler to all current and future buttons:

// define the click handler for all buttons
$( document ).on( "click", "button", function() {
    alert( "Button Clicked!" )
});

/* ... some time later ... */

// dynamically add another button to the page
$( "html" ).append( "<button>Click Alert!</button>" );

Q: What’s the deal with the $ in jQuery? What is it and what does it mean?
Also, how can jQuery be used in conjunction with another JavaScript library that also uses $ for naming? Bonus credit if you can provide two answers.
A: Since $ has no special meaning in JavaScript, it is free to be used in object naming. In jQuery, it is simply used as an alias for the jQuery object and jQuery() function.

However, jQuery has no monopoly on use of $, so you may encounter situations where you want to use it in conjunction with another JS library that also uses $, which would therefore result in a naming conflict. jQuery provides the jQuery.noConflict() method for just this reason. Calling this method makes it necessary to use the underlying name jQuery instead in subequent references to jQuery and its functions.
Here’s an example from the jQuery documentation:

<script src="other_lib.js"></script>
<script src="jquery.js"></script>
<script>
$.noConflict();
// Code that uses other library's $ can follow here.
</script>

Alternatively, you can also use a closure instead of the $.noConflict() method; e.g.:
(function ($) {
  // Code in which we now exactly what the meaning of $ is
} (jQuery));

Q: Explain and contrast the usage of event.preventDefault() and event.stopPropagation(). Provide an example.
A: event.stopPropagation() stops an event from bubbling up the event chain, whereas event.preventDefault() only precludes the browser’s default action on that event from occurring, but the event still propogates up the event chain.

For example, consider the following code snippet:

// in this example, 'foo' is a div containing button 'bar'
$("#foo").click(function() {
   // mouse click on div 'foo'
});

$("#bar").click(function(e) {
   // mouse click on button 'bar'
   e.stopPropagation();
});

Due to the call to stopPropagation() in the button’s click handler, the event never propogates to the div so its click handler never fires. It effectively stops parent elements from knowing about an event on their children.
In contrast, if you replaced the above call to stopPropagation() with a call to preventDefault(), only the browser’s default action would be precluded, but the div’s click handler would still fire.
(Note: Although the stopPropagation() and preventDefault() methods are mostly used in jQuery event handling implementations, they apply to plain JavaScript as well.)

Q: What is accomplished by returning false from (a) a jQuery event handler, (b) a regular JavaScript onclick event handler for an anchor tag, and (c) a regular JavaScript onclick event handler for a non-anchor tag (e.g., a div, button, etc.)?
A: (a) Returning false from a jQuery event handler is effectively the same as calling both preventDefault() and stopPropagation() on the passed jQuery event object.

(b) Returning false from a regular JavaScript onclick event handler for an anchor tag prevents the browser from navigating to the link address and stops the event from propagating through the DOM.

(c) Returning false from a a regular JavaScript onclick event handler for a non-anchor tag (e.g., a div, button, etc.) has absolutely no effect.


2 comments:

  1. Thanks to Admin for Sharing such useful Information. I really like your Blog. Addition to your Story here I am Contributing 1 more Similar Story UI Developer Interview Questions for Experienced Professionals.

    ReplyDelete