Wednesday, October 17, 2012

Jquery $() factory function



Jquery is a powerful JavaScript library which simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery can quickly find the matching elements in DOM using selectors.

Jquery can be downloaded from:
http://jquery.com/

A lot of jQuery beginners may not get used to $() function in jQuery.

$() factory function ( the same as jQuery(), used in case of conflicting with other JavaScript functions) is used as a jQuery selector to  find out matching elements from a DOM based on a given variable, which can be:

1) tag name, for example  $("p") to get the object between <p> </p>
2) tag ID, for example $('#myid')  to select the element with ID myid, such as <p id="myid"> </p>
3) class, for example $('.myclass')  to select the element with class myclass, such as <p class="myclass"> </p>
4) Universal *, for example $(*) selects all elements in the document.
5) Combination, for example $(p > *)  selects all elements that are children of <p>; $("li > ul") selects all elements matched by <ul> that are children of  <li>.


No comments:

Post a Comment