Tuesday, September 13, 2011

What is $.disconnect significance and how it is different from $.disconnectAll


In jQuery to disconnect one function from another function then $.disconnect is used. Once this statement gets executed, function gets disconnected from reference function and the connected function will not be executed after the code.
Syntax is same as connect function. To disconnect c2.fun1 use the following code

$.disconnect(a,'fun1',b,fun2);

Where fun1 is the reference function and fun2 is connected function. Here a, b are objects.
$.disconnectAll function is used to disconnect all connected functions.

$.disconnectAll(a,'fun1');

In what scenarios jQuery can be used?


  1. To apply CSS static or dynamic
  2. To call functions on events
  3. Crisscross the documents
  4. Manipulation purpose
  5. To add animation effects
In all the cases where we use JavaScript can be replaced with jQuery in the projects. This can reduce maintenance.

Do you prefer jQuery or JavaScript? Explain Why?


jQuery solves major JavaScript problems.


jQuery is preferred over JavaScript due to following reasons.

jQuery is light weight library for developing client side applications including ajax.
jQuery assists to keep code simple and concise and reusable. Huge line of code developed using JavaScript can be eliminated with just few lines of jQuery.
jQuery library simplifies the process of traversal of HTML DOM tree.
jQuery can also handle events, perform animation, and add Ajax support in web applications.


Creating animation and effects using JavaScript is not an easy task and requires deep understanding and imagination. This is quite difficult to do using JavaScript.

When a client wants  to zoom entire screen, or to show a slideshow of photographs, this can be achieved using jQuery.  With a few script includes and smart work , its  possible and extremely effective.  Using  variety of jquery Plugging that are available customization is easy for developers , web developers have control over the effects without even touching a single line of raw Javascript.  Thats the power of query.
If you know the JavaScript well, it helps you to make better use of jQuery.
To distinguish jQuery from JavaScript Here is an example for basic animation using javascript .


What are the advantages of jQuery?


  1. Easy and Self Explanatory
  2. JavaScript enhancement without headache of learning new syntax.
  3. The code is simple, clear, readable, reusable and also easy to maintainable.
  4. Elimination of writing repeated, complex loops and DOM scripting library calls.

Explain how jQuery works?


The $() function is an alias for the jQuery() function . This returns a special Java-Script object. This JavaScript Object contains an array of  DOM elements that matches the selector. Selector is key thing in jQuery development.It is away to select node from DOM. This Java-Script object possesses a large number of useful predefined methods that can action group of elements.This type of construct is termed a wrapper because it wraps the matching element(s) with extended functionality.
  • Here $(object) is called jQuery wrapper around the object.
  • jQuery has a ready element that checks the document and waits until document is ready to be manipulated.
  • It searches for the reference files for framework, once it finds it then control goes to the function specified.
  • What ever code mentioned in the function that gets executed. Event handling also can be implemented here.

Does document.ready() function similar to onload()? (or) Explain the importance of document.ready()? (or) Why jQuery script is faster?


Document.ready() function is completely different from body onload() function .

Explanation
JavaScript Operations on the page elements are performed outside of the DOcument Markup (DOM) that creates them. This is because of waiting until  DOM elements of the page are fully loaded before those operations execute. The onload handler for the window object is used for this purpose, executing statements after the entire page is fully loaded.

Browser delays calling onload till DOM tree is created and then all images/other external resources are fully loaded.

jQuery waits until DOM tree is ready before executing scripts. It uses this approach using Document.Ready . This makes running scripts fast and triggers execution of code once the DOM tree is loaded, but not external image resources has loaded.  Hence script execution need not wait till the page is loaded. The code execution happens before page is loaded hence jQuery code is faster. We can use this technique multiple times within the same HTML document.

To summarize the differences
  • First of all Document.ready() function is called as soon as DOM is loaded but body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.
  • We can have as many document.ready() functions in a page but onload function is limited on one time.

Monday, September 12, 2011

What do Dollar ($) sign significance in jQuery?


Dollar Sign is nonetheless an alias for JQuery. You can write jQuery syntax using $ sign or jQuery.
This can also be called Selector($).


This can be called as an expression for identifying target elements on a page that allows  to easily identify and also  grab elements required.


The below 2 syntaxes are the same to create a function using jQuery.
To collect a group of elements, we use the simple syntax $(selector) or jQuery(selector).