Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere
Search *: Please select technology.



Q.1-What is the use of dollor sing in JQuery?
Dollor sign ($) is just an aliase of Jquery.Rather then writting jQuery we use dollor($).

same lines of code can be written as


Q.2-What is the difference btween body onload function and document.ready?
1-We can have more then one doucument.ready function in a page but we can have only one body onload function.
2-ducument.ready is called as soon as the DOM is loaded but body onload function is called when everything gets loaded on the page.

Q.3-What are the advantage of JQuery?
The advantages of using jQuery are:
1-Eliminates cross- browser incompatibilities:The JavaScript engines of different browsers differ slightly so JavaScript code that works for one browser may not work for another. jQuery handles all these cross-browser inconsistencies and provides a consistent interface that works across different browsers.
2-Extensible:jQuery makes extending the framework.New events, elements, and methods can be easily added and then reused as a plugin.
3-Ease of use: This is pretty much the main advantage of using JQuery, it is a lot more easy to use compared to standard javascript and other javascript libraries. Apart from simple syntax, it also requires much less lines of code to achieve the same feature in comparison.
4-Ajax support: JQuery lets you develop Ajax templates with ease.
Click here to read JQuery in details

Q.4-What is CDN?
If you want to use Jquery,there are different ways of using jQuery on your web site.
1-Download the jQuery library from jQuery.com or
2-Include jQuery from a CDN, like Google,microsoft etc.

If you do not want to download jquery then use can use it from CDN(Content Delivery Network)
CDN host jquery files, and allow you to use those.

Q.5-How do you select all div of a page using jQuery?
you can use Element selector to select all div elements.
Ex- $("div")
will return all div Element reference .
Click here to read jQuery Selector in details




Q.6-What is the difference between ID selector and class selector in jQuery?
1-Id Selector- The jQuery #id selector uses the id attribute of an HTML element to find the specific element. Id of elemets is always unique in a page,so use #id selector when you want to find a single, unique element.
To use id selector,write a hash character and then write the id of the HTML element which you want to select.
Syntex-$("#txtFirst")

will select element which has id="txtFirst"

2-Class Selector- The jQuery class selector finds elements which has specific class used in elements. use class selector when you want to select group of elements. To use class selector, write a period character and then name of the class.
Syntex-$(".required")

will select all element those has required class.
Click here to read jQuery Selector in details

Q.7- What is the use of each() function in jQuery? JQuery each() function is an iterator,it allows you to iterate over a set of elements. You can also pass a function to each() method, which will be executed for each element from the jQuery object, on which it has been called.
Ex- $("#pnlTraverse").children().each(function(){alert($(this).text())});
Above code will first select all the child element of pnlTraverse panel and then display each child elements text as an alert
Click here to read jQuery Traversing in details

Q.8-How do you add and remove CSS classes to an element using jQuery?
JQuery has provided addClass() method to add a css class to an element and removeClass() jQuery methods to remove a class from an element.
1-addClass() -
Adds one or more classes to the selected elements
Example: $("div").addClass(" blue ");
Above code will add blue class to div element.

2-removeClass() - Removes one or more classes from the selected elements
Example : $(“div").removeClass(" blue ");
Above code will remove blue class from div element
Click here to read Working with CSS in JQuery details

Q.9-What is difference between jQuery.get() and jQuery.ajax() method? ajax() method is more powerful and configurable, it allows you to specify datatypes,and how to handle error.
get() is a specialization to over ajax just to retrieve some data.
Click here to read Ajax in details

Q.10-Is JQuery W3C Standard? No.


Q.11- What is siblings() method in jQuery?
Returns all sibling elements of the selected element.
Example-

Now we want to find the siblings of "liSecond" element and want to change the text color to say red.
Then we will write below code-
$('.liSecond').siblings().css('color','red');
If we want pick specific sibling elements reference then we can write
$('.liSecond').siblings('.liFourth').css('color','red');

Q.12-Explain bind(),delegate() and live() method siblings()? 1-Bind Method- The .bind() method registers the type of event and an event handler directly to the DOM element.
Ex- $( "#bthSubmit" ).bind( "click", function() { alert( "Page has been submitted by the user." ); });
The .bind() method will attach the event handler to all of the element that are matched!. It's not good, if we consider page performance.
Not only is that expensive to implicitly iterate over all of those items to attach an event handler, but it is also wasteful since it is the same event handler over and over again.
Pros-
1-This methods works across various browser implementations.
2-It is pretty easy and quick to wire-up event handlers.

Cons:
1-The method attaches the same event handler to every matched element in the selection.
2-It doesn't work for elements added dynamically that matches the same selector.

2-Live()- live method attaches the event handler to the root level document along with the associated selector and event information.
Once an event is raised, jQuery looks at the selector/event metadata to determine which handler it should invoke, if any. This extra work has some impact on performance at the point of user interaction, but the initial register process is fairly speedy. The good thing about this code as compared to the .bind() example above is that it is only attaching the event handler once to the document instead of multiple times. This not only is faster, but less wasteful.
Ex-$( "#btnSubmit" ).live( "click", function( e ) {} );

Pros:
1-There is only one event handler registered instead of the numerous event handlers that could have been registered with the .bind() method.
2-Elements dynamically added to the DOM that match the selector magically work because the real information was registered on the document.
Cons:
1-This method is deprecated as of jQuery 1.7 and you should start phasing out its use in your code.
2-Chaining is not properly supported using this method and using event.stopPropagation() is no longer helpful.
3-matchesSelector method to determine which event handler to invoke, if any.
Your events always delegate all the way up to the document. This can affect performance if your DOM is deep.

3-Delegate Method: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 should be attached.
The selector and event information Just like the .live() method, this technique uses event delegation to work correctly.

Example-$( "#menu" ).delegate( "li a", "click", function( e ) {//write your logic here} );
The above code will attach the event handler to the unordered list ("#members") along with the selector/event information. This is much more efficient than the .live() method that always attaches the information to the document.

Pros:
1-You have the option of choosing where to attach the selector/event information. Events here are generally registered at the root element.
JQuery still needs to iterate over the selector/event data to determine a match,but since you can choose where the root is the amount of data to sort through can be much smaller.
2-Chaining is supported correctly.
3-Since this technique uses event delegation, it can work with dynamically added elements to the DOM where the selectors match.
Click here to read Events in details


Q.13- What is Chaining in jQuery? Jquery Chaining allows us to run multiple jQuery methods, one after the other, (on the same element) within a single statement.
This way, browsers do not have to find the same element(s) more than once.(this way it chaining increases performance)
To chain an action, you simply append the action to the previous action.

The following example chains together the css(), slideUp(), and slideDown() methods.
The "p1" element first changes to red, then it slides up, and then it slides down:
Example $("#p1").css("color", "red").slideUp(2000).slideDown(2000);
Click here to read JQuery Chaining in details

Q.14-Which is the fastest, document.getElementByID('id') or $('#id')? For id selectors, jQuery uses the JavaScript function document.getElementById(), which is extremely efficient. The jQuery method to select $('#id') internally make a call to document.getElementByID('id'). Hence, document.getElementByID('id') is faster then $('#id').

Q.15- Is jQuery replacement of Java Script?
No.jQuery is not the replacement of JavaScript. jQuery is a different library which is written on the top of JavaScript.It internally uses java script functions. but it has provided the simple syntex which helps the developer to write less lines of code to achieve the same feature in comparison..