2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Licensed under the MIT License:
6 * http://www.opensource.org/licenses/mit-license.php
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
19 function jQuery(a,c) {
21 // Initalize the extra macro functions
22 if ( !jQuery.initDone ) jQuery.init();
24 // Shortcut for document ready (because $(document).each() is silly)
25 if ( a && a.constructor == Function && jQuery.fn.ready )
26 return jQuery(document).ready(a);
28 // Make sure t hat a selection was provided
29 a = a || jQuery.context || document;
32 * Handle support for overriding other $() functions. Way too many libraries
33 * provide this function to simply ignore it and overwrite it.
36 // Check to see if this is a possible collision case
37 if ( jQuery._$ && !c && a.constructor == String &&
39 // Make sure that the expression is a colliding one
40 !/[^a-zA-Z0-9_-]/.test(a) &&
42 // and that there are no elements that match it
43 // (this is the one truly ambiguous case)
44 !document.getElementsByTagName(a).length )
46 // Use the default method, in case it works some voodoo
47 return jQuery._$( a );
50 // Watch for when a jQuery object is passed as the selector
54 // Watch for when a jQuery object is passed at the context
56 return jQuery(c.get()).find(a);
58 // If the context is global, return a new object
60 return new jQuery(a,c);
62 // Handle HTML strings
63 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
64 if ( m ) a = jQuery.clean( [ m[1] ] );
66 // Watch for when an array is passed in
67 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
68 // Assume that it is an array of DOM Elements
69 jQuery.merge( a, [] ) :
71 // Find the matching elements and save them for later
72 jQuery.find( a, c ) );
74 var fn = arguments[ arguments.length - 1 ];
75 if ( fn && fn.constructor == Function )
79 // Map over the $ in case of overwrite
83 // Map the jQuery namespace to the '$' one
86 jQuery.fn = jQuery.prototype = {
88 * The current SVN version of jQuery.
99 * The number of elements currently matched.
101 * @example $("img").length;
102 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
112 * The number of elements currently matched.
114 * @example $("img").size();
115 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
127 * Access all matched elements. This serves as a backwards-compatible
128 * way of accessing all matched elements (other than the jQuery object
129 * itself, which is, in fact, an array of elements).
131 * @example $("img").get();
132 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
133 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
136 * @type Array<Element>
141 * Access a single matched element. num is used to access the
142 * Nth element matched.
144 * @example $("img").get(1);
145 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
146 * @result [ <img src="test1.jpg"/> ]
150 * @param Number num Access the element in the Nth position.
155 * Set the jQuery object to an array of elements.
157 * @example $("img").get([ document.body ]);
158 * @result $("img").get() == [ document.body ]
163 * @param Elements elems An array of elements
166 get: function( num ) {
167 // Watch for when an array (of elements) is passed in
168 if ( num && num.constructor == Array ) {
170 // Use a tricky hack to make the jQuery object
171 // look and feel like an array
173 [].push.apply( this, num );
177 return num == undefined ?
179 // Return a 'clean' array
180 jQuery.map( this, function(a){ return a } ) :
182 // Return just the object
187 * Execute a function within the context of every matched element.
188 * This means that every time the passed-in function is executed
189 * (which is once for every element matched) the 'this' keyword
190 * points to the specific element.
192 * Additionally, the function, when executed, is passed a single
193 * argument representing the position of the element in the matched
196 * @example $("img").each(function(){ this.src = "test.jpg"; });
197 * @before <img/> <img/>
198 * @result <img src="test.jpg"/> <img src="test.jpg"/>
202 * @param Function fn A function to execute
205 each: function( fn, args ) {
206 return jQuery.each( this, fn, args );
210 * Access a property on the first matched element.
211 * This method makes it easy to retreive a property value
212 * from the first matched element.
214 * @example $("img").attr("src");
215 * @before <img src="test.jpg"/>
220 * @param String name The name of the property to access.
225 * Set a hash of key/value object properties to all matched elements.
226 * This serves as the best way to set a large number of properties
227 * on all matched elements.
229 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
231 * @result <img src="test.jpg" alt="Test Image"/>
235 * @param Hash prop A set of key/value pairs to set as object properties.
240 * Set a single property to a value, on all matched elements.
242 * @example $("img").attr("src","test.jpg");
244 * @result <img src="test.jpg"/>
248 * @param String key The name of the property to set.
249 * @param Object value The value to set the property to.
252 attr: function( key, value, type ) {
253 // Check to see if we're setting style values
254 return key.constructor != String || value != undefined ?
255 this.each(function(){
256 // See if we're setting a hash of styles
257 if ( value == undefined )
258 // Set all the styles
259 for ( var prop in key )
261 type ? this.style : this,
265 // See if we're setting a single key/value style
268 type ? this.style : this,
273 // Look for the case where we're accessing a style value
274 jQuery[ type || "attr" ]( this[0], key );
278 * Access a style property on the first matched element.
279 * This method makes it easy to retreive a style property value
280 * from the first matched element.
282 * @example $("p").css("red");
283 * @before <p style="color:red;">Test Paragraph.</p>
288 * @param String name The name of the property to access.
293 * Set a hash of key/value style properties to all matched elements.
294 * This serves as the best way to set a large number of style properties
295 * on all matched elements.
297 * @example $("p").css({ color: "red", background: "blue" });
298 * @before <p>Test Paragraph.</p>
299 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
303 * @param Hash prop A set of key/value pairs to set as style properties.
308 * Set a single style property to a value, on all matched elements.
310 * @example $("p").css("color","red");
311 * @before <p>Test Paragraph.</p>
312 * @result <p style="color:red;">Test Paragraph.</p>
316 * @param String key The name of the property to set.
317 * @param Object value The value to set the property to.
320 css: function( key, value ) {
321 return this.attr( key, value, "curCSS" );
325 * Retreive the text contents of all matched elements. The result is
326 * a string that contains the combined text contents of all matched
327 * elements. This method works on both HTML and XML documents.
329 * @example $("p").text();
330 * @before <p>Test Paragraph.</p>
331 * @result Test Paragraph.
340 for ( var j = 0; j < e.length; j++ ) {
341 var r = e[j].childNodes;
342 for ( var i = 0; i < r.length; i++ )
343 t += r[i].nodeType != 1 ?
344 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
350 * Wrap all matched elements with a structure of other elements.
351 * This wrapping process is most useful for injecting additional
352 * stucture into a document, without ruining the original semantic
353 * qualities of a document.
355 * The way that is works is that it goes through the first element argument
356 * provided and finds the deepest element within the structure - it is that
357 * element that will en-wrap everything else.
359 * @example $("p").wrap("<div class='wrap'></div>");
360 * @before <p>Test Paragraph.</p>
361 * @result <div class='wrap'><p>Test Paragraph.</p></div>
365 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
366 * @any Element elem A DOM element that will be wrapped.
367 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
368 * @any Object obj Any object, converted to a string, then a text node.
369 * @cat DOM/Manipulation
372 // The elements to wrap the target around
373 var a = jQuery.clean(arguments);
375 // Wrap each of the matched elements individually
376 return this.each(function(){
377 // Clone the structure that we're using to wrap
378 var b = a[0].cloneNode(true);
380 // Insert it before the element to be wrapped
381 this.parentNode.insertBefore( b, this );
383 // Find he deepest point in the wrap structure
384 while ( b.firstChild )
387 // Move the matched element to within the wrap structure
388 b.appendChild( this );
393 * Append any number of elements to the inside of all matched elements.
394 * This operation is similar to doing an appendChild to all the
395 * specified elements, adding them into the document.
397 * @example $("p").append("<b>Hello</b>");
398 * @before <p>I would like to say: </p>
399 * @result <p>I would like to say: <b>Hello</b></p>
403 * @any String html A string of HTML, that will be created on the fly and appended to the target.
404 * @any Element elem A DOM element that will be appended.
405 * @any Array<Element> elems An array of elements, all of which will be appended.
406 * @any Object obj Any object, converted to a string, then a text node.
407 * @cat DOM/Manipulation
410 return this.domManip(arguments, true, 1, function(a){
411 this.appendChild( a );
416 * Prepend any number of elements to the inside of all matched elements.
417 * This operation is the best way to insert a set of elements inside, at the
418 * beginning, of all the matched element.
420 * @example $("p").prepend("<b>Hello</b>");
421 * @before <p>, how are you?</p>
422 * @result <p><b>Hello</b>, how are you?</p>
426 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
427 * @any Element elem A DOM element that will be prepended.
428 * @any Array<Element> elems An array of elements, all of which will be prepended.
429 * @any Object obj Any object, converted to a string, then a text node.
430 * @cat DOM/Manipulation
432 prepend: function() {
433 return this.domManip(arguments, true, -1, function(a){
434 this.insertBefore( a, this.firstChild );
439 * Insert any number of elements before each of the matched elements.
441 * @example $("p").before("<b>Hello</b>");
442 * @before <p>how are you?</p>
443 * @result <b>Hello</b><p>how are you?</p>
447 * @any String html A string of HTML, that will be created on the fly and inserted.
448 * @any Element elem A DOM element that will beinserted.
449 * @any Array<Element> elems An array of elements, all of which will be inserted.
450 * @any Object obj Any object, converted to a string, then a text node.
451 * @cat DOM/Manipulation
454 return this.domManip(arguments, false, 1, function(a){
455 this.parentNode.insertBefore( a, this );
460 * Insert any number of elements after each of the matched elements.
462 * @example $("p").after("<p>I'm doing fine.</p>");
463 * @before <p>How are you?</p>
464 * @result <p>How are you?</p><p>I'm doing fine.</p>
468 * @any String html A string of HTML, that will be created on the fly and inserted.
469 * @any Element elem A DOM element that will beinserted.
470 * @any Array<Element> elems An array of elements, all of which will be inserted.
471 * @any Object obj Any object, converted to a string, then a text node.
472 * @cat DOM/Manipulation
475 return this.domManip(arguments, false, -1, function(a){
476 this.parentNode.insertBefore( a, this.nextSibling );
481 * End the most recent 'destructive' operation, reverting the list of matched elements
482 * back to its previous state. After an end operation, the list of matched elements will
483 * revert to the last state of matched elements.
485 * @example $("p").find("span").end();
486 * @before <p><span>Hello</span>, how are you?</p>
487 * @result $("p").find("span").end() == [ <p>...</p> ]
491 * @cat DOM/Traversing
494 return this.get( this.stack.pop() );
498 * Searches for all elements that match the specified expression.
499 * This method is the optimal way of finding additional descendant
500 * elements with which to process.
502 * All searching is done using a jQuery expression. The expression can be
503 * written using CSS 1-3 Selector syntax, or basic XPath.
505 * @example $("p").find("span");
506 * @before <p><span>Hello</span>, how are you?</p>
507 * @result $("p").find("span") == [ <span>Hello</span> ]
511 * @param String expr An expression to search with.
512 * @cat DOM/Traversing
515 return this.pushStack( jQuery.map( this, function(a){
516 return jQuery.find(t,a);
521 * Removes all elements from the set of matched elements that do not
522 * match the specified expression. This method is used to narrow down
523 * the results of a search.
525 * All searching is done using a jQuery expression. The expression
526 * can be written using CSS 1-3 Selector syntax, or basic XPath.
528 * @example $("p").filter(".selected")
529 * @before <p class="selected">Hello</p><p>How are you?</p>
530 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
534 * @param String expr An expression to search with.
535 * @cat DOM/Traversing
539 * Removes all elements from the set of matched elements that do not
540 * match at least one of the expressions passed to the function. This
541 * method is used when you want to filter the set of matched elements
542 * through more than one expression.
544 * Elements will be retained in the jQuery object if they match at
545 * least one of the expressions passed.
547 * @example $("p").filter([".selected", ":first"])
548 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
549 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
553 * @param Array<String> exprs A set of expressions to evaluate against
554 * @cat DOM/Traversing
556 filter: function(t) {
557 return this.pushStack(
558 t.constructor == Array &&
559 jQuery.map(this,function(a){
560 for ( var i = 0; i < t.length; i++ )
561 if ( jQuery.filter(t[i],[a]).r.length )
565 t.constructor == Boolean &&
566 ( t ? this.get() : [] ) ||
568 t.constructor == Function &&
569 jQuery.grep( this, t ) ||
571 jQuery.filter(t,this).r, arguments );
575 * Removes the specified Element from the set of matched elements. This
576 * method is used to remove a single Element from a jQuery object.
578 * @example $("p").not( document.getElementById("selected") )
579 * @before <p>Hello</p><p id="selected">Hello Again</p>
580 * @result [ <p>Hello</p> ]
584 * @param Element el An element to remove from the set
585 * @cat DOM/Traversing
589 * Removes elements matching the specified expression from the set
590 * of matched elements. This method is used to remove one or more
591 * elements from a jQuery object.
593 * @example $("p").not("#selected")
594 * @before <p>Hello</p><p id="selected">Hello Again</p>
595 * @result [ <p>Hello</p> ]
599 * @param String expr An expression with which to remove matching elements
600 * @cat DOM/Traversing
603 return this.pushStack( t.constructor == String ?
604 jQuery.filter(t,this,false).r :
605 jQuery.grep(this,function(a){ return a != t; }), arguments );
609 * Adds the elements matched by the expression to the jQuery object. This
610 * can be used to concatenate the result sets of two expressions.
612 * @example $("p").add("span")
613 * @before <p>Hello</p><p><span>Hello Again</span></p>
614 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
618 * @param String expr An expression whose matched elements are added
619 * @cat DOM/Traversing
623 * Adds each of the Elements in the array to the set of matched elements.
624 * This is used to add a set of Elements to a jQuery object.
626 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
627 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
628 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
632 * @param Array<Element> els An array of Elements to add
637 * Adds a single Element to the set of matched elements. This is used to
638 * add a single Element to a jQuery object.
640 * @example $("p").add( document.getElementById("a") )
641 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
642 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
646 * @param Element el An Element to add
650 return this.pushStack( jQuery.merge( this, t.constructor == String ?
651 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
655 * A wrapper function for each() to be used by append and prepend.
656 * Handles cases where you're trying to modify the inner contents of
657 * a table, when you actually need to work with the tbody.
660 * @param {String} expr The expression with which to filter
665 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
674 * @param Boolean table
676 * @param Function fn The function doing the DOM manipulation.
679 domManip: function(args, table, dir, fn){
680 var clone = this.size() > 1;
681 var a = jQuery.clean(args);
683 return this.each(function(){
686 if ( table && this.nodeName == "TABLE" ) {
687 var tbody = this.getElementsByTagName("tbody");
689 if ( !tbody.length ) {
690 obj = document.createElement("tbody");
691 this.appendChild( obj );
696 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
697 i != ( dir < 0 ? dir : a.length ); i += dir ) {
698 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
712 pushStack: function(a,args) {
713 var fn = args && args[args.length-1];
715 if ( !fn || fn.constructor != Function ) {
716 if ( !this.stack ) this.stack = [];
717 this.stack.push( this.get() );
720 var old = this.get();
722 if ( fn.constructor == Function )
723 return this.each( fn );
742 * Extend one object with another, returning the original,
743 * modified, object. This is a great utility for simple inheritance.
746 * @param Object obj The object to extend
747 * @param Object prop The object that will be merged into the first.
751 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
752 if ( !prop ) { prop = obj; obj = this; }
753 for ( var i in prop ) obj[i] = prop[i];
766 jQuery.initDone = true;
768 jQuery.each( jQuery.macros.axis, function(i,n){
769 jQuery.fn[ i ] = function(a) {
770 var ret = jQuery.map(this,n);
771 if ( a && a.constructor == String )
772 ret = jQuery.filter(a,ret).r;
773 return this.pushStack( ret, arguments );
777 jQuery.each( jQuery.macros.to, function(i,n){
778 jQuery.fn[ i ] = function(){
780 return this.each(function(){
781 for ( var j = 0; j < a.length; j++ )
787 jQuery.each( jQuery.macros.each, function(i,n){
788 jQuery.fn[ i ] = function() {
789 return this.each( n, arguments );
793 jQuery.each( jQuery.macros.filter, function(i,n){
794 jQuery.fn[ n ] = function(num,fn) {
795 return this.filter( ":" + n + "(" + num + ")", fn );
799 jQuery.each( jQuery.macros.attr, function(i,n){
801 jQuery.fn[ i ] = function(h) {
802 return h == undefined ?
803 this.length ? this[0][n] : null :
808 jQuery.each( jQuery.macros.css, function(i,n){
809 jQuery.fn[ i ] = function(h) {
810 return h == undefined ?
811 ( this.length ? jQuery.css( this[0], n ) : null ) :
819 * A generic iterator function, which can be used to seemlessly
820 * iterate over both objects and arrays.
823 * @param Object obj The object, or array, to iterate over.
824 * @param Object fn The function that will be executed on every object.
828 each: function( obj, fn, args ) {
829 if ( obj.length == undefined )
831 fn.apply( obj[i], args || [i, obj[i]] );
833 for ( var i = 0; i < obj.length; i++ )
834 fn.apply( obj[i], args || [i, obj[i]] );
840 if (jQuery.className.has(o,c)) return;
841 o.className += ( o.className ? " " : "" ) + c;
843 remove: function(o,c){
844 o.className = !c ? "" :
846 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
851 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
856 * Swap in/out style options.
859 swap: function(e,o,f) {
861 e.style["old"+i] = e.style[i];
866 e.style[i] = e.style["old"+i];
870 if ( p == "height" || p == "width" ) {
871 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
874 old["padding" + d[i]] = 0;
875 old["border" + d[i] + "Width"] = 0;
878 jQuery.swap( e, old, function() {
879 if (jQuery.css(e,"display") != "none") {
880 oHeight = e.offsetHeight;
881 oWidth = e.offsetWidth;
883 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
885 oHeight = e.clientHeight;
886 oWidth = e.clientWidth;
890 return p == "height" ? oHeight : oWidth;
891 } else if ( p == "opacity" && jQuery.browser.msie )
892 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
894 return jQuery.curCSS( e, p );
897 curCSS: function(e,p,force) {
900 if (!force && e.style[p])
902 else if (e.currentStyle) {
903 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
904 r = e.currentStyle[p];
905 } else if (document.defaultView && document.defaultView.getComputedStyle) {
906 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
907 var s = document.defaultView.getComputedStyle(e,"");
908 r = s ? s.getPropertyValue(p) : null;
916 for ( var i = 0; i < a.length; i++ ) {
917 if ( a[i].constructor == String ) {
919 if ( !a[i].indexOf("<tr") ) {
921 a[i] = "<table>" + a[i] + "</table>";
922 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
924 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
927 var div = document.createElement("div");
928 div.innerHTML = a[i];
931 div = div.firstChild.firstChild;
932 if ( td ) div = div.firstChild;
935 for ( var j = 0; j < div.childNodes.length; j++ )
936 r.push( div.childNodes[j] );
937 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
938 for ( var k = 0; k < a[i].length; k++ )
940 else if ( a[i] !== null )
941 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
947 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
948 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
956 last: "i==r.length-1",
961 "first-child": "jQuery.sibling(a,0).cur",
962 "last-child": "jQuery.sibling(a,0).last",
963 "only-child": "jQuery.sibling(a).length==1",
966 parent: "a.childNodes.length",
967 empty: "!a.childNodes.length",
970 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
973 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
974 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
977 enabled: "!a.disabled",
978 disabled: "a.disabled",
981 ".": "jQuery.className.has(a,m[2])",
985 "^=": "!z.indexOf(m[4])",
986 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
987 "*=": "z.indexOf(m[4])>=0",
990 "[": "jQuery.find(m[2],a).length"
994 "\\.\\.|/\\.\\.", "a.parentNode",
995 ">|/", "jQuery.sibling(a.firstChild)",
996 "\\+", "jQuery.sibling(a).next",
999 var s = jQuery.sibling(a);
1001 for ( var i = s.n; i < s.length; i++ )
1007 find: function( t, context ) {
1008 // Make sure that the context is a DOM Element
1009 if ( context && context.nodeType == undefined )
1012 // Set the correct context (if none is provided)
1013 context = context || jQuery.context || document;
1015 if ( t.constructor != String ) return [t];
1017 if ( !t.indexOf("//") ) {
1018 context = context.documentElement;
1019 t = t.substr(2,t.length);
1020 } else if ( !t.indexOf("/") ) {
1021 context = context.documentElement;
1022 t = t.substr(1,t.length);
1023 // FIX Assume the root element is right :(
1024 if ( t.indexOf("/") >= 1 )
1025 t = t.substr(t.indexOf("/"),t.length);
1028 var ret = [context];
1032 while ( t.length > 0 && last != t ) {
1036 t = jQuery.trim(t).replace( /^\/\//i, "" );
1038 var foundToken = false;
1040 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1041 var re = new RegExp("^(" + jQuery.token[i] + ")");
1045 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1046 t = jQuery.trim( t.replace( re, "" ) );
1051 if ( !foundToken ) {
1052 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1053 if ( ret[0] == context ) ret.shift();
1054 done = jQuery.merge( done, ret );
1055 r = ret = [context];
1056 t = " " + t.substr(1,t.length);
1058 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1059 var m = re2.exec(t);
1061 if ( m[1] == "#" ) {
1062 // Ummm, should make this work in all XML docs
1063 var oid = document.getElementById(m[2]);
1064 r = ret = oid ? [oid] : [];
1065 t = t.replace( re2, "" );
1067 if ( !m[2] || m[1] == "." ) m[2] = "*";
1069 for ( var i = 0; i < ret.length; i++ )
1070 r = jQuery.merge( r,
1072 jQuery.getAll(ret[i]) :
1073 ret[i].getElementsByTagName(m[2])
1080 var val = jQuery.filter(t,r);
1082 t = jQuery.trim(val.t);
1086 if ( ret && ret[0] == context ) ret.shift();
1087 done = jQuery.merge( done, ret );
1092 getAll: function(o,r) {
1094 var s = o.childNodes;
1095 for ( var i = 0; i < s.length; i++ )
1096 if ( s[i].nodeType == 1 ) {
1098 jQuery.getAll( s[i], r );
1103 attr: function(o,a,v){
1104 if ( a && a.constructor == String ) {
1107 "class": "className",
1111 a = (fix[a] && fix[a].replace && fix[a] || a)
1112 .replace(/-([a-z])/ig,function(z,b){
1113 return b.toUpperCase();
1116 if ( v != undefined ) {
1118 if ( o.setAttribute && a != "disabled" )
1119 o.setAttribute(a,v);
1122 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1127 // The regular expressions that power the parsing engine
1129 // Match: [@value='test'], [@foo]
1130 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1132 // Match: [div], [div p]
1135 // Match: :contains('foo')
1136 [ "(:)S\\(Q\\)", 0 ],
1138 // Match: :even, :last-chlid
1142 filter: function(t,r,not) {
1143 // Figure out if we're doing regular, or inverse, filtering
1144 var g = not !== false ? jQuery.grep :
1145 function(a,f) {return jQuery.grep(a,f,true);};
1147 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1149 var p = jQuery.parse;
1151 for ( var i = 0; i < p.length; i++ ) {
1152 var re = new RegExp( "^" + p[i][0]
1154 // Look for a string-like sequence
1155 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1157 // Look for something (optionally) enclosed with quotes
1158 .replace( 'Q', " *'?\"?([^'\"]*)'?\"? *" ), "i" );
1160 var m = re.exec( t );
1163 // Re-organize the match
1165 m = ["", m[1], m[3], m[2], m[4]];
1167 // Remove what we just matched
1168 t = t.replace( re, "" );
1174 // :not() is a special case that can be optomized by
1175 // keeping it out of the expression list
1176 if ( m[1] == ":" && m[2] == "not" )
1177 r = jQuery.filter(m[3],r,false).r;
1179 // Otherwise, find the expression to execute
1181 var f = jQuery.expr[m[1]];
1182 if ( f.constructor != String )
1183 f = jQuery.expr[m[1]][m[2]];
1185 // Build a custom macro to enclose it
1186 eval("f = function(a,i){" +
1187 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1188 "return " + f + "}");
1190 // Execute it against the current filter
1195 // Return an array of filtered elements (r)
1196 // and the modified expression string (t)
1197 return { r: r, t: t };
1201 * Remove the whitespace from the beginning and end of a string.
1206 * @param String str The string to trim.
1209 return t.replace(/^\s+|\s+$/g, "");
1213 * All ancestors of a given element.
1217 * @type Array<Element>
1218 * @param Element elem The element to find the ancestors of.
1220 parents: function(a){
1222 var c = a.parentNode;
1223 while ( c && c != document ) {
1231 * All elements on a specified axis.
1236 * @param Element elem The element to find all the siblings of (including itself).
1238 sibling: function(a,n) {
1240 var tmp = a.parentNode.childNodes;
1241 for ( var i = 0; i < tmp.length; i++ ) {
1242 if ( tmp[i].nodeType == 1 )
1243 type.push( tmp[i] );
1245 type.n = type.length - 1;
1247 type.last = type.n == type.length - 1;
1249 n == "even" && type.n % 2 == 0 ||
1250 n == "odd" && type.n % 2 ||
1252 type.prev = type[type.n - 1];
1253 type.next = type[type.n + 1];
1258 * Merge two arrays together, removing all duplicates.
1263 * @param Array a The first array to merge.
1264 * @param Array b The second array to merge.
1266 merge: function(a,b) {
1269 // Move b over to the new array (this helps to avoid
1270 // StaticNodeList instances)
1271 for ( var k = 0; k < b.length; k++ )
1274 // Now check for duplicates between a and b and only
1275 // add the unique items
1276 for ( var i = 0; i < a.length; i++ ) {
1279 // The collision-checking process
1280 for ( var j = 0; j < b.length; j++ )
1284 // If the item is unique, add it
1293 * Remove items that aren't matched in an array. The function passed
1294 * in to this method will be passed two arguments: 'a' (which is the
1295 * array item) and 'i' (which is the index of the item in the array).
1300 * @param Array array The Array to find items in.
1301 * @param Function fn The function to process each item against.
1302 * @param Boolean inv Invert the selection - select the opposite of the function.
1304 grep: function(a,f,s) {
1305 // If a string is passed in for the function, make a function
1306 // for it (a handy shortcut)
1307 if ( f.constructor == String )
1308 f = new Function("a","i","return " + f);
1312 // Go through the array, only saving the items
1313 // that pass the validator function
1314 for ( var i = 0; i < a.length; i++ )
1315 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1322 * Translate all items in array to another array of items. The translation function
1323 * that is provided to this method is passed one argument: 'a' (the item to be
1324 * translated). If an array is returned, that array is mapped out and merged into
1325 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1326 * from the array. Both of these changes imply that the size of the array may not
1327 * be the same size upon completion, as it was when it started.
1332 * @param Array array The Array to translate.
1333 * @param Function fn The function to process each item against.
1335 map: function(a,f) {
1336 // If a string is passed in for the function, make a function
1337 // for it (a handy shortcut)
1338 if ( f.constructor == String )
1339 f = new Function("a","return " + f);
1343 // Go through the array, translating each of the items to their
1344 // new value (or values).
1345 for ( var i = 0; i < a.length; i++ ) {
1347 if ( t !== null && t != undefined ) {
1348 if ( t.constructor != Array ) t = [t];
1349 r = jQuery.merge( t, r );
1356 * A number of helper functions used for managing events.
1357 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1361 // Bind an event to an element
1362 // Original by Dean Edwards
1363 add: function(element, type, handler) {
1364 // For whatever reason, IE has trouble passing the window object
1365 // around, causing it to be cloned in the process
1366 if ( jQuery.browser.msie && element.setInterval != undefined )
1369 // Make sure that the function being executed has a unique ID
1370 if ( !handler.guid )
1371 handler.guid = this.guid++;
1373 // Init the element's event structure
1374 if (!element.events)
1375 element.events = {};
1377 // Get the current list of functions bound to this event
1378 var handlers = element.events[type];
1380 // If it hasn't been initialized yet
1382 // Init the event handler queue
1383 handlers = element.events[type] = {};
1385 // Remember an existing handler, if it's already there
1386 if (element["on" + type])
1387 handlers[0] = element["on" + type];
1390 // Add the function to the element's handler list
1391 handlers[handler.guid] = handler;
1393 // And bind the global event handler to the element
1394 element["on" + type] = this.handle;
1396 // Remember the function in a global list (for triggering)
1397 if (!this.global[type])
1398 this.global[type] = [];
1399 this.global[type].push( element );
1405 // Detach an event or set of events from an element
1406 remove: function(element, type, handler) {
1408 if (type && element.events[type])
1410 delete element.events[type][handler.guid];
1412 for ( var i in element.events[type] )
1413 delete element.events[type][i];
1415 for ( var j in element.events )
1416 this.remove( element, j );
1419 trigger: function(type,data,element) {
1420 // Touch up the incoming data
1423 // Handle a global trigger
1425 var g = this.global[type];
1427 for ( var i = 0; i < g.length; i++ )
1428 this.trigger( type, data, g[i] );
1430 // Handle triggering a single element
1431 } else if ( element["on" + type] ) {
1432 // Pass along a fake event
1433 data.unshift( this.fix({ type: type, target: element }) );
1435 // Trigger the event
1436 element["on" + type].apply( element, data );
1440 handle: function(event) {
1441 if ( typeof jQuery == "undefined" ) return;
1443 event = event || jQuery.event.fix( window.event );
1445 // If no correct event was found, fail
1446 if ( !event ) return;
1448 var returnValue = true;
1450 var c = this.events[event.type];
1452 for ( var j in c ) {
1453 if ( c[j].apply( this, [event] ) === false ) {
1454 event.preventDefault();
1455 event.stopPropagation();
1456 returnValue = false;
1463 fix: function(event) {
1465 event.preventDefault = function() {
1466 this.returnValue = false;
1469 event.stopPropagation = function() {
1470 this.cancelBubble = true;
1481 var b = navigator.userAgent.toLowerCase();
1483 // Figure out what browser is being used
1485 safari: /webkit/.test(b),
1486 opera: /opera/.test(b),
1487 msie: /msie/.test(b) && !/opera/.test(b),
1488 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1491 // Check to see if the W3C box model is being used
1492 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1498 * Append all of the matched elements to another, specified, set of elements.
1499 * This operation is, essentially, the reverse of doing a regular
1500 * $(A).append(B), in that instead of appending B to A, you're appending
1503 * @example $("p").appendTo("#foo");
1504 * @before <p>I would like to say: </p><div id="foo"></div>
1505 * @result <div id="foo"><p>I would like to say: </p></div>
1509 * @param String expr A jQuery expression of elements to match.
1510 * @cat DOM/Manipulation
1515 * Prepend all of the matched elements to another, specified, set of elements.
1516 * This operation is, essentially, the reverse of doing a regular
1517 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1520 * @example $("p").prependTo("#foo");
1521 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1522 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1526 * @param String expr A jQuery expression of elements to match.
1527 * @cat DOM/Manipulation
1529 prependTo: "prepend",
1532 * Insert all of the matched elements before another, specified, set of elements.
1533 * This operation is, essentially, the reverse of doing a regular
1534 * $(A).before(B), in that instead of inserting B before A, you're inserting
1537 * @example $("p").insertBefore("#foo");
1538 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1539 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1541 * @name insertBefore
1543 * @param String expr A jQuery expression of elements to match.
1544 * @cat DOM/Manipulation
1546 insertBefore: "before",
1549 * Insert all of the matched elements after another, specified, set of elements.
1550 * This operation is, essentially, the reverse of doing a regular
1551 * $(A).after(B), in that instead of inserting B after A, you're inserting
1554 * @example $("p").insertAfter("#foo");
1555 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1556 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1560 * @param String expr A jQuery expression of elements to match.
1561 * @cat DOM/Manipulation
1563 insertAfter: "after"
1567 * Get the current CSS width of the first matched element.
1569 * @example $("p").width();
1570 * @before <p>This is just a test.</p>
1579 * Set the CSS width of every matched element. Be sure to include
1580 * the "px" (or other unit of measurement) after the number that you
1581 * specify, otherwise you might get strange results.
1583 * @example $("p").width("20px");
1584 * @before <p>This is just a test.</p>
1585 * @result <p style="width:20px;">This is just a test.</p>
1589 * @param String val Set the CSS property to the specified value.
1594 * Get the current CSS height of the first matched element.
1596 * @example $("p").height();
1597 * @before <p>This is just a test.</p>
1606 * Set the CSS height of every matched element. Be sure to include
1607 * the "px" (or other unit of measurement) after the number that you
1608 * specify, otherwise you might get strange results.
1610 * @example $("p").height("20px");
1611 * @before <p>This is just a test.</p>
1612 * @result <p style="height:20px;">This is just a test.</p>
1616 * @param String val Set the CSS property to the specified value.
1621 * Get the current CSS top of the first matched element.
1623 * @example $("p").top();
1624 * @before <p>This is just a test.</p>
1633 * Set the CSS top of every matched element. Be sure to include
1634 * the "px" (or other unit of measurement) after the number that you
1635 * specify, otherwise you might get strange results.
1637 * @example $("p").top("20px");
1638 * @before <p>This is just a test.</p>
1639 * @result <p style="top:20px;">This is just a test.</p>
1643 * @param String val Set the CSS property to the specified value.
1648 * Get the current CSS left of the first matched element.
1650 * @example $("p").left();
1651 * @before <p>This is just a test.</p>
1660 * Set the CSS left of every matched element. Be sure to include
1661 * the "px" (or other unit of measurement) after the number that you
1662 * specify, otherwise you might get strange results.
1664 * @example $("p").left("20px");
1665 * @before <p>This is just a test.</p>
1666 * @result <p style="left:20px;">This is just a test.</p>
1670 * @param String val Set the CSS property to the specified value.
1675 * Get the current CSS position of the first matched element.
1677 * @example $("p").position();
1678 * @before <p>This is just a test.</p>
1687 * Set the CSS position of every matched element.
1689 * @example $("p").position("relative");
1690 * @before <p>This is just a test.</p>
1691 * @result <p style="position:relative;">This is just a test.</p>
1695 * @param String val Set the CSS property to the specified value.
1700 * Get the current CSS float of the first matched element.
1702 * @example $("p").float();
1703 * @before <p>This is just a test.</p>
1712 * Set the CSS float of every matched element.
1714 * @example $("p").float("left");
1715 * @before <p>This is just a test.</p>
1716 * @result <p style="float:left;">This is just a test.</p>
1720 * @param String val Set the CSS property to the specified value.
1725 * Get the current CSS overflow of the first matched element.
1727 * @example $("p").overflow();
1728 * @before <p>This is just a test.</p>
1737 * Set the CSS overflow of every matched element.
1739 * @example $("p").overflow("auto");
1740 * @before <p>This is just a test.</p>
1741 * @result <p style="overflow:auto;">This is just a test.</p>
1745 * @param String val Set the CSS property to the specified value.
1750 * Get the current CSS color of the first matched element.
1752 * @example $("p").color();
1753 * @before <p>This is just a test.</p>
1762 * Set the CSS color of every matched element.
1764 * @example $("p").color("blue");
1765 * @before <p>This is just a test.</p>
1766 * @result <p style="color:blue;">This is just a test.</p>
1770 * @param String val Set the CSS property to the specified value.
1775 * Get the current CSS background of the first matched element.
1777 * @example $("p").background();
1778 * @before <p>This is just a test.</p>
1787 * Set the CSS background of every matched element.
1789 * @example $("p").background("blue");
1790 * @before <p>This is just a test.</p>
1791 * @result <p style="background:blue;">This is just a test.</p>
1795 * @param String val Set the CSS property to the specified value.
1799 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1801 filter: [ "eq", "lt", "gt", "contains" ],
1805 * Get the current value of the first matched element.
1807 * @example $("input").val();
1808 * @before <input type="text" value="some text"/>
1809 * @result "some text"
1813 * @cat DOM/Attributes
1817 * Set the value of every matched element.
1819 * @example $("input").value("test");
1820 * @before <input type="text" value="some text"/>
1821 * @result <input type="text" value="test"/>
1825 * @param String val Set the property to the specified value.
1826 * @cat DOM/Attributes
1831 * Get the html contents of the first matched element.
1833 * @example $("div").html();
1834 * @before <div><input/></div>
1839 * @cat DOM/Attributes
1843 * Set the html contents of every matched element.
1845 * @example $("div").html("<b>new stuff</b>");
1846 * @before <div><input/></div>
1847 * @result <div><b>new stuff</b></div>
1851 * @param String val Set the html contents to the specified value.
1852 * @cat DOM/Attributes
1857 * Get the current id of the first matched element.
1859 * @example $("input").id();
1860 * @before <input type="text" id="test" value="some text"/>
1865 * @cat DOM/Attributes
1869 * Set the id of every matched element.
1871 * @example $("input").id("newid");
1872 * @before <input type="text" id="test" value="some text"/>
1873 * @result <input type="text" id="newid" value="some text"/>
1877 * @param String val Set the property to the specified value.
1878 * @cat DOM/Attributes
1883 * Get the current title of the first matched element.
1885 * @example $("img").title();
1886 * @before <img src="test.jpg" title="my image"/>
1887 * @result "my image"
1891 * @cat DOM/Attributes
1895 * Set the title of every matched element.
1897 * @example $("img").title("new title");
1898 * @before <img src="test.jpg" title="my image"/>
1899 * @result <img src="test.jpg" title="new image"/>
1903 * @param String val Set the property to the specified value.
1904 * @cat DOM/Attributes
1909 * Get the current name of the first matched element.
1911 * @example $("input").name();
1912 * @before <input type="text" name="username"/>
1913 * @result "username"
1917 * @cat DOM/Attributes
1921 * Set the name of every matched element.
1923 * @example $("input").name("user");
1924 * @before <input type="text" name="username"/>
1925 * @result <input type="text" name="user"/>
1929 * @param String val Set the property to the specified value.
1930 * @cat DOM/Attributes
1935 * Get the current href of the first matched element.
1937 * @example $("a").href();
1938 * @before <a href="test.html">my link</a>
1939 * @result "test.html"
1943 * @cat DOM/Attributes
1947 * Set the href of every matched element.
1949 * @example $("a").href("test2.html");
1950 * @before <a href="test.html">my link</a>
1951 * @result <a href="test2.html">my link</a>
1955 * @param String val Set the property to the specified value.
1956 * @cat DOM/Attributes
1961 * Get the current src of the first matched element.
1963 * @example $("img").src();
1964 * @before <img src="test.jpg" title="my image"/>
1965 * @result "test.jpg"
1969 * @cat DOM/Attributes
1973 * Set the src of every matched element.
1975 * @example $("img").src("test2.jpg");
1976 * @before <img src="test.jpg" title="my image"/>
1977 * @result <img src="test2.jpg" title="my image"/>
1981 * @param String val Set the property to the specified value.
1982 * @cat DOM/Attributes
1987 * Get the current rel of the first matched element.
1989 * @example $("a").rel();
1990 * @before <a href="test.html" rel="nofollow">my link</a>
1991 * @result "nofollow"
1995 * @cat DOM/Attributes
1999 * Set the rel of every matched element.
2001 * @example $("a").rel("nofollow");
2002 * @before <a href="test.html">my link</a>
2003 * @result <a href="test.html" rel="nofollow">my link</a>
2007 * @param String val Set the property to the specified value.
2008 * @cat DOM/Attributes
2015 * Get a set of elements containing the unique parents of the matched
2018 * @example $("p").parent()
2019 * @before <div><p>Hello</p><p>Hello</p></div>
2020 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2024 * @cat DOM/Traversing
2028 * Get a set of elements containing the unique parents of the matched
2029 * set of elements, and filtered by an expression.
2031 * @example $("p").parent(".selected")
2032 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2033 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2037 * @param String expr An expression to filter the parents with
2038 * @cat DOM/Traversing
2040 parent: "a.parentNode",
2043 * Get a set of elements containing the unique ancestors of the matched
2046 * @example $("span").ancestors()
2047 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2048 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2052 * @cat DOM/Traversing
2056 * Get a set of elements containing the unique ancestors of the matched
2057 * set of elements, and filtered by an expression.
2059 * @example $("span").ancestors("p")
2060 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2061 * @result [ <p><span>Hello</span></p> ]
2065 * @param String expr An expression to filter the ancestors with
2066 * @cat DOM/Traversing
2068 ancestors: jQuery.parents,
2071 * Get a set of elements containing the unique ancestors of the matched
2074 * @example $("span").ancestors()
2075 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2076 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2080 * @cat DOM/Traversing
2084 * Get a set of elements containing the unique ancestors of the matched
2085 * set of elements, and filtered by an expression.
2087 * @example $("span").ancestors("p")
2088 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2089 * @result [ <p><span>Hello</span></p> ]
2093 * @param String expr An expression to filter the ancestors with
2094 * @cat DOM/Traversing
2096 parents: jQuery.parents,
2099 * Get a set of elements containing the unique next siblings of each of the
2100 * matched set of elements.
2102 * It only returns the very next sibling, not all next siblings.
2104 * @example $("p").next()
2105 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2106 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2110 * @cat DOM/Traversing
2114 * Get a set of elements containing the unique next siblings of each of the
2115 * matched set of elements, and filtered by an expression.
2117 * It only returns the very next sibling, not all next siblings.
2119 * @example $("p").next(".selected")
2120 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2121 * @result [ <p class="selected">Hello Again</p> ]
2125 * @param String expr An expression to filter the next Elements with
2126 * @cat DOM/Traversing
2128 next: "jQuery.sibling(a).next",
2131 * Get a set of elements containing the unique previous siblings of each of the
2132 * matched set of elements.
2134 * It only returns the immediately previous sibling, not all previous siblings.
2136 * @example $("p").previous()
2137 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2138 * @result [ <div><span>Hello Again</span></div> ]
2142 * @cat DOM/Traversing
2146 * Get a set of elements containing the unique previous siblings of each of the
2147 * matched set of elements, and filtered by an expression.
2149 * It only returns the immediately previous sibling, not all previous siblings.
2151 * @example $("p").previous(".selected")
2152 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2153 * @result [ <div><span>Hello</span></div> ]
2157 * @param String expr An expression to filter the previous Elements with
2158 * @cat DOM/Traversing
2160 prev: "jQuery.sibling(a).prev",
2163 * Get a set of elements containing all of the unique siblings of each of the
2164 * matched set of elements.
2166 * @example $("div").siblings()
2167 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2168 * @result [ <p>Hello</p>, <p>And Again</p> ]
2172 * @cat DOM/Traversing
2176 * Get a set of elements containing all of the unique siblings of each of the
2177 * matched set of elements, and filtered by an expression.
2179 * @example $("div").siblings(".selected")
2180 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2181 * @result [ <p class="selected">Hello Again</p> ]
2185 * @param String expr An expression to filter the sibling Elements with
2186 * @cat DOM/Traversing
2188 siblings: jQuery.sibling,
2192 * Get a set of elements containing all of the unique children of each of the
2193 * matched set of elements.
2195 * @example $("div").children()
2196 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2197 * @result [ <span>Hello Again</span> ]
2201 * @cat DOM/Traversing
2205 * Get a set of elements containing all of the unique children of each of the
2206 * matched set of elements, and filtered by an expression.
2208 * @example $("div").children(".selected")
2209 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2210 * @result [ <p class="selected">Hello Again</p> ]
2214 * @param String expr An expression to filter the child Elements with
2215 * @cat DOM/Traversing
2217 children: "a.childNodes"
2222 * Displays each of the set of matched elements if they are hidden.
2224 * @example $("p").show()
2225 * @before <p style="display: none">Hello</p>
2226 * @result [ <p style="display: block">Hello</p> ]
2233 this.style.display = this.oldblock ? this.oldblock : "";
2234 if ( jQuery.css(this,"display") == "none" )
2235 this.style.display = "block";
2239 * Hides each of the set of matched elements if they are shown.
2241 * @example $("p").hide()
2242 * @before <p>Hello</p>
2243 * @result [ <p style="display: none">Hello</p> ]
2250 this.oldblock = this.oldblock || jQuery.css(this,"display");
2251 if ( this.oldblock == "none" )
2252 this.oldblock = "block";
2253 this.style.display = "none";
2257 * Toggles each of the set of matched elements. If they are shown,
2258 * toggle makes them hidden. If they are hidden, toggle
2261 * @example $("p").toggle()
2262 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2263 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2269 _toggle: function(){
2270 var d = jQuery.css(this,"display");
2271 $(this)[ !d || d == "none" ? "show" : "hide" ]();
2275 * Adds the specified class to each of the set of matched elements.
2277 * @example $("p").addClass("selected")
2278 * @before <p>Hello</p>
2279 * @result [ <p class="selected">Hello</p> ]
2283 * @param String class A CSS class to add to the elements
2286 addClass: function(c){
2287 jQuery.className.add(this,c);
2291 * Removes the specified class from the set of matched elements.
2293 * @example $("p").removeClass("selected")
2294 * @before <p class="selected">Hello</p>
2295 * @result [ <p>Hello</p> ]
2299 * @param String class A CSS class to remove from the elements
2302 removeClass: function(c){
2303 jQuery.className.remove(this,c);
2307 * Adds the specified class if it is present, removes it if it is
2310 * @example $("p").toggleClass("selected")
2311 * @before <p>Hello</p><p class="selected">Hello Again</p>
2312 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2316 * @param String class A CSS class with which to toggle the elements
2319 toggleClass: function( c ){
2320 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2324 * Removes all matched elements from the DOM. This does NOT remove them from the
2325 * jQuery object, allowing you to use the matched elements further.
2327 * @example $("p").remove();
2328 * @before <p>Hello</p> how are <p>you?</p>
2333 * @cat DOM/Manipulation
2337 * Removes only elements (out of the list of matched elements) that match
2338 * the specified jQuery expression. This does NOT remove them from the
2339 * jQuery object, allowing you to use the matched elements further.
2341 * @example $("p").remove(".hello");
2342 * @before <p class="hello">Hello</p> how are <p>you?</p>
2343 * @result how are <p>you?</p>
2347 * @param String expr A jQuery expression to filter elements by.
2348 * @cat DOM/Manipulation
2350 remove: function(a){
2351 if ( !a || jQuery.filter( [this], a ).r )
2352 this.parentNode.removeChild( this );
2356 * Removes all child nodes from the set of matched elements.
2358 * @example $("p").empty()
2359 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2360 * @result [ <p></p> ]
2364 * @cat DOM/Manipulation
2367 while ( this.firstChild )
2368 this.removeChild( this.firstChild );
2372 * Binds a particular event (like click) to a each of a set of match elements.
2374 * @example $("p").bind( "click", function() { alert("Hello"); } )
2375 * @before <p>Hello</p>
2376 * @result [ <p>Hello</p> ]
2378 * Cancel a default action and prevent it from bubbling by returning false
2379 * from your function.
2381 * @example $("form").bind( "submit", function() { return false; } )
2383 * Cancel a default action by using the preventDefault method.
2385 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2387 * Stop an event from bubbling by using the stopPropogation method.
2389 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2393 * @param String type An event type
2394 * @param Function fn A function to bind to the event on each of the set of matched elements
2397 bind: function( type, fn ) {
2398 if ( fn.constructor == String )
2399 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2400 jQuery.event.add( this, type, fn );
2404 * The opposite of bind, removes a bound event from each of the matched
2405 * elements. You must pass the identical function that was used in the original
2408 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2409 * @before <p onclick="alert('Hello');">Hello</p>
2410 * @result [ <p>Hello</p> ]
2414 * @param String type An event type
2415 * @param Function fn A function to unbind from the event on each of the set of matched elements
2420 * Removes all bound events of a particular type from each of the matched
2423 * @example $("p").unbind( "click" )
2424 * @before <p onclick="alert('Hello');">Hello</p>
2425 * @result [ <p>Hello</p> ]
2429 * @param String type An event type
2434 * Removes all bound events from each of the matched elements.
2436 * @example $("p").unbind()
2437 * @before <p onclick="alert('Hello');">Hello</p>
2438 * @result [ <p>Hello</p> ]
2444 unbind: function( type, fn ) {
2445 jQuery.event.remove( this, type, fn );
2449 * Trigger a type of event on every matched element.
2451 * @example $("p").trigger("click")
2452 * @before <p click="alert('hello')">Hello</p>
2453 * @result alert('hello')
2457 * @param String type An event type to trigger.
2460 trigger: function( type, data ) {
2461 jQuery.event.trigger( type, data, this );