Backported wiki changes from http://docs.jquery.com/API/1.1.1/Core
[jquery.git] / src / jquery / jquery.js
1 /*
2  * jQuery @VERSION - New Wave Javascript
3  *
4  * Copyright (c) 2007 John Resig (jquery.com)
5  * Dual licensed under the MIT (MIT-LICENSE.txt)
6  * and GPL (GPL-LICENSE.txt) licenses.
7  *
8  * $Date$
9  * $Rev$
10  */
11
12 // Global undefined variable
13 window.undefined = window.undefined;
14
15 /**
16  * Create a new jQuery Object
17  *
18  * @constructor
19  * @private
20  * @name jQuery
21  * @param String|Function|Element|Array<Element>|jQuery a selector
22  * @param jQuery|Element|Array<Element> c context
23  * @cat Core
24  */
25 var jQuery = function(a,c) {
26         // If the context is global, return a new object
27         if ( window == this )
28                 return new jQuery(a,c);
29
30         // Make sure that a selection was provided
31         a = a || document;
32         
33         // HANDLE: $(function)
34         // Shortcut for document ready
35         if ( jQuery.isFunction(a) )
36                 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
37         
38         // Handle HTML strings
39         if ( typeof a  == "string" ) {
40                 // HANDLE: $(html) -> $(array)
41                 var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a);
42                 if ( m )
43                         a = jQuery.clean( [ m[1] ] );
44                 
45                 // HANDLE: $(expr)
46                 else
47                         return new jQuery( c ).find( a );
48         }
49         
50         return this.setArray(
51                 // HANDLE: $(array)
52                 a.constructor == Array && a ||
53
54                 // HANDLE: $(arraylike)
55                 // Watch for when an array-like object is passed as the selector
56                 (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
57
58                 // HANDLE: $(*)
59                 [ a ] );
60 };
61
62 // Map over the $ in case of overwrite
63 if ( typeof $ != "undefined" )
64         jQuery._$ = $;
65         
66 // Map the jQuery namespace to the '$' one
67 var $ = jQuery;
68
69 /**
70  * This function accepts a string containing a CSS or
71  * basic XPath selector which is then used to match a set of elements.
72  *
73  * The core functionality of jQuery centers around this function.
74  * Everything in jQuery is based upon this, or uses this in some way.
75  * The most basic use of this function is to pass in an expression
76  * (usually consisting of CSS or XPath), which then finds all matching
77  * elements.
78  *
79  * By default, if no context is specified, $() looks for DOM elements within the context of the
80  * current HTML document. If you do specify a context, such as a DOM
81  * element or jQuery object, the expression will be matched against
82  * the contents of that context.
83  *
84  * See [[DOM/Traversing/Selectors]] for the allowed CSS/XPath syntax for expressions.
85  *
86  * @example $("div > p")
87  * @desc Finds all p elements that are children of a div element.
88  * @before <p>one</p> <div><p>two</p></div> <p>three</p>
89  * @result [ <p>two</p> ]
90  *
91  * @example $("input:radio", document.forms[0])
92  * @desc Searches for all inputs of type radio within the first form in the document
93  *
94  * @example $("div", xml.responseXML)
95  * @desc This finds all div elements within the specified XML document.
96  *
97  * @name $
98  * @param String expr An expression to search with
99  * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
100  * @cat Core
101  * @type jQuery
102  * @see $(Element)
103  * @see $(Element<Array>)
104  */
105  
106 /**
107  * Create DOM elements on-the-fly from the provided String of raw HTML.
108  *
109  * @example $("<div><p>Hello</p></div>").appendTo("body")
110  * @desc Creates a div element (and all of its contents) dynamically, 
111  * and appends it to the body element. Internally, an
112  * element is created and its innerHTML property set to the given markup.
113  * It is therefore both quite flexible and limited. 
114  *
115  * @name $
116  * @param String html A string of HTML to create on the fly.
117  * @cat Core
118  * @type jQuery
119  * @see appendTo(String)
120  */
121
122 /**
123  * Wrap jQuery functionality around a single or multiple DOM Element(s).
124  *
125  * This function also accepts XML Documents and Window objects
126  * as valid arguments (even though they are not DOM Elements).
127  *
128  * @example $(document.body).css( "background", "black" );
129  * @desc Sets the background color of the page to black.
130  *
131  * @example $( myForm.elements ).hide()
132  * @desc Hides all the input elements within a form
133  *
134  * @name $
135  * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
136  * @cat Core
137  * @type jQuery
138  */
139
140 /**
141  * A shorthand for $(document).ready(), allowing you to bind a function
142  * to be executed when the DOM document has finished loading. This function
143  * behaves just like $(document).ready(), in that it should be used to wrap
144  * other $() operations on your page that depend on the DOM being ready to be
145  * operated on. While this function is, technically, chainable - there really
146  * isn't much use for chaining against it.
147  *
148  * You can have as many $(document).ready events on your page as you like.
149  *
150  * See ready(Function) for details about the ready event. 
151  * 
152  * @example $(function(){
153  *   // Document is ready
154  * });
155  * @desc Executes the function when the DOM is ready to be used.
156  *
157  * @example jQuery(function($) {
158  *   // Your code using failsafe $ alias here...
159  * });
160  * @desc Uses both the shortcut for $(document).ready() and the argument
161  * to write failsafe jQuery code using the $ alias, without relying on the
162  * global alias.
163  *
164  * @name $
165  * @param Function fn The function to execute when the DOM is ready.
166  * @cat Core
167  * @type jQuery
168  * @see ready(Function)
169  */
170
171 jQuery.fn = jQuery.prototype = {
172         /**
173          * The current version of jQuery.
174          *
175          * @private
176          * @property
177          * @name jquery
178          * @type String
179          * @cat Core
180          */
181         jquery: "@VERSION",
182
183         /**
184          * The number of elements currently matched. The size function will return the same value.
185          *
186          * @example $("img").length;
187          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
188          * @result 2
189          *
190          * @property
191          * @name length
192          * @type Number
193          * @cat Core
194          */
195
196         /**
197          * Get the number of elements currently matched. This returns the same
198          * number as the 'length' property of the jQuery object.
199          *
200          * @example $("img").size();
201          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
202          * @result 2
203          *
204          * @name size
205          * @type Number
206          * @cat Core
207          */
208         size: function() {
209                 return this.length;
210         },
211         
212         length: 0,
213
214         /**
215          * Access all matched DOM elements. This serves as a backwards-compatible
216          * way of accessing all matched elements (other than the jQuery object
217          * itself, which is, in fact, an array of elements).
218          *
219          * It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions.
220          *
221          * @example $("img").get();
222          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
223          * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
224          * @desc Selects all images in the document and returns the DOM Elements as an Array
225          *
226          * @name get
227          * @type Array<Element>
228          * @cat Core
229          */
230
231         /**
232          * Access a single matched DOM element at a specified index in the matched set.
233          * This allows you to extract the actual DOM element and operate on it
234          * directly without necessarily using jQuery functionality on it.
235          *
236          * @example $("img").get(0);
237          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
238          * @result <img src="test1.jpg"/>
239          * @desc Selects all images in the document and returns the first one
240          *
241          * @name get
242          * @type Element
243          * @param Number num Access the element in the Nth position.
244          * @cat Core
245          */
246         get: function( num ) {
247                 return num == undefined ?
248
249                         // Return a 'clean' array
250                         jQuery.makeArray( this ) :
251
252                         // Return just the object
253                         this[num];
254         },
255         
256         /**
257          * Set the jQuery object to an array of elements, while maintaining
258          * the stack.
259          *
260          * @example $("img").pushStack([ document.body ]);
261          * @result $("img").pushStack() == [ document.body ]
262          *
263          * @private
264          * @name pushStack
265          * @type jQuery
266          * @param Elements elems An array of elements
267          * @cat Core
268          */
269         pushStack: function( a ) {
270                 var ret = jQuery(a);
271                 ret.prevObject = this;
272                 return ret;
273         },
274         
275         /**
276          * Set the jQuery object to an array of elements. This operation is
277          * completely destructive - be sure to use .pushStack() if you wish to maintain
278          * the jQuery stack.
279          *
280          * @example $("img").setArray([ document.body ]);
281          * @result $("img").setArray() == [ document.body ]
282          *
283          * @private
284          * @name setArray
285          * @type jQuery
286          * @param Elements elems An array of elements
287          * @cat Core
288          */
289         setArray: function( a ) {
290                 this.length = 0;
291                 [].push.apply( this, a );
292                 return this;
293         },
294
295         /**
296          * Execute a function within the context of every matched element.
297          * This means that every time the passed-in function is executed
298          * (which is once for every element matched) the 'this' keyword
299          * points to the specific DOM element.
300          *
301          * Additionally, the function, when executed, is passed a single
302          * argument representing the position of the element in the matched
303          * set (integer, zero-index).
304          *
305          * @example $("img").each(function(i){
306          *   this.src = "test" + i + ".jpg";
307          * });
308          * @before <img/><img/>
309          * @result <img src="test0.jpg"/><img src="test1.jpg"/>
310          * @desc Iterates over two images and sets their src property
311          *
312          * @name each
313          * @type jQuery
314          * @param Function fn A function to execute
315          * @cat Core
316          */
317         each: function( fn, args ) {
318                 return jQuery.each( this, fn, args );
319         },
320
321         /**
322          * Searches every matched element for the object and returns
323          * the index of the element, if found, starting with zero. 
324          * Returns -1 if the object wasn't found.
325          *
326          * @example $("*").index( $('#foobar')[0] ) 
327          * @before <div id="foobar"><b></b><span id="foo"></span></div>
328          * @result 0
329          * @desc Returns the index for the element with ID foobar
330          *
331          * @example $("*").index( $('#foo')[0] ) 
332          * @before <div id="foobar"><b></b><span id="foo"></span></div>
333          * @result 2
334          * @desc Returns the index for the element with ID foo within another element
335          *
336          * @example $("*").index( $('#bar')[0] ) 
337          * @before <div id="foobar"><b></b><span id="foo"></span></div>
338          * @result -1
339          * @desc Returns -1, as there is no element with ID bar
340          *
341          * @name index
342          * @type Number
343          * @param Element subject Object to search for
344          * @cat Core
345          */
346         index: function( obj ) {
347                 var pos = -1;
348                 this.each(function(i){
349                         if ( this == obj ) pos = i;
350                 });
351                 return pos;
352         },
353
354         /**
355          * Access a property on the first matched element.
356          * This method makes it easy to retrieve a property value
357          * from the first matched element.
358          *
359          * @example $("img").attr("src");
360          * @before <img src="test.jpg"/>
361          * @result test.jpg
362          * @desc Returns the src attribute from the first image in the document.
363          *
364          * @name attr
365          * @type Object
366          * @param String name The name of the property to access.
367          * @cat DOM/Attributes
368          */
369
370         /**
371          * Set a key/value object as properties to all matched elements.
372          *
373          * This serves as the best way to set a large number of properties
374          * on all matched elements.
375          *
376          * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
377          * @before <img/>
378          * @result <img src="test.jpg" alt="Test Image"/>
379          * @desc Sets src and alt attributes to all images.
380          *
381          * @name attr
382          * @type jQuery
383          * @param Map properties Key/value pairs to set as object properties.
384          * @cat DOM/Attributes
385          */
386
387         /**
388          * Set a single property to a value, on all matched elements.
389          *
390          * Can compute values provided as ${formula}, see second example.
391          *
392          * Note that you can't set the name property of input elements in IE.
393          * Use $(html) or .append(html) or .html(html) to create elements
394          * on the fly including the name property.
395          *
396          * @example $("img").attr("src","test.jpg");
397          * @before <img/>
398          * @result <img src="test.jpg"/>
399          * @desc Sets src attribute to all images.
400          *
401          * @example $("img").attr("title", "${this.src}");
402          * @before <img src="test.jpg" />
403          * @result <img src="test.jpg" title="test.jpg" />
404          * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
405          *
406          * @name attr
407          * @type jQuery
408          * @param String key The name of the property to set.
409          * @param Object value The value to set the property to.
410          * @cat DOM/Attributes
411          */
412          
413         /**
414          * Set a single property to a computed value, on all matched elements.
415          *
416          * Instead of a value, a function is provided, that computes the value.
417          *
418          * @example $("img").attr("title", function() { return this.src });
419          * @before <img src="test.jpg" />
420          * @result <img src="test.jpg" title="test.jpg" />
421          * @desc Sets title attribute from src attribute.
422          *
423          * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
424          * @before <img title="pic" /><img title="pic" /><img title="pic" />
425          * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
426          * @desc Enumerate title attribute.
427          *
428          * @name attr
429          * @type jQuery
430          * @param String key The name of the property to set.
431          * @param Function value A function returning the value to set.
432          *                Scope: Current element, argument: Index of current element
433          * @cat DOM/Attributes
434          */
435         attr: function( key, value, type ) {
436                 var obj = key;
437                 
438                 // Look for the case where we're accessing a style value
439                 if ( key.constructor == String )
440                         if ( value == undefined )
441                                 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
442                         else {
443                                 obj = {};
444                                 obj[ key ] = value;
445                         }
446                 
447                 // Check to see if we're setting style values
448                 return this.each(function(index){
449                         // Set all the styles
450                         for ( var prop in obj )
451                                 jQuery.attr(
452                                         type ? this.style : this,
453                                         prop, jQuery.prop(this, obj[prop], type, index, prop)
454                                 );
455                 });
456         },
457
458         /**
459          * Access a style property on the first matched element.
460          * This method makes it easy to retrieve a style property value
461          * from the first matched element.
462          *
463          * @example $("p").css("color");
464          * @before <p style="color:red;">Test Paragraph.</p>
465          * @result "red"
466          * @desc Retrieves the color style of the first paragraph
467          *
468          * @example $("p").css("font-weight");
469          * @before <p style="font-weight: bold;">Test Paragraph.</p>
470          * @result "bold"
471          * @desc Retrieves the font-weight style of the first paragraph.
472          *
473          * @name css
474          * @type String
475          * @param String name The name of the property to access.
476          * @cat CSS
477          */
478
479         /**
480          * Set a key/value object as style properties to all matched elements.
481          *
482          * This serves as the best way to set a large number of style properties
483          * on all matched elements.
484          *
485          * @example $("p").css({ color: "red", background: "blue" });
486          * @before <p>Test Paragraph.</p>
487          * @result <p style="color:red; background:blue;">Test Paragraph.</p>
488          * @desc Sets color and background styles to all p elements.
489          *
490          * @name css
491          * @type jQuery
492          * @param Map properties Key/value pairs to set as style properties.
493          * @cat CSS
494          */
495
496         /**
497          * Set a single style property to a value, on all matched elements.
498          * If a number is provided, it is automatically converted into a pixel value.
499          *
500          * @example $("p").css("color","red");
501          * @before <p>Test Paragraph.</p>
502          * @result <p style="color:red;">Test Paragraph.</p>
503          * @desc Changes the color of all paragraphs to red
504          *
505          * @example $("p").css("left",30);
506          * @before <p>Test Paragraph.</p>
507          * @result <p style="left:30px;">Test Paragraph.</p>
508          * @desc Changes the left of all paragraphs to "30px"
509          *
510          * @name css
511          * @type jQuery
512          * @param String key The name of the property to set.
513          * @param String|Number value The value to set the property to.
514          * @cat CSS
515          */
516         css: function( key, value ) {
517                 return this.attr( key, value, "curCSS" );
518         },
519
520         /**
521          * Get the text contents of all matched elements. The result is
522          * a string that contains the combined text contents of all matched
523          * elements. This method works on both HTML and XML documents.
524          *
525          * @example $("p").text();
526          * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
527          * @result Test Paragraph.Paraparagraph
528          * @desc Gets the concatenated text of all paragraphs
529          *
530          * @name text
531          * @type String
532          * @cat DOM/Attributes
533          */
534
535         /**
536          * Set the text contents of all matched elements.
537          *
538          * Similar to html(), but escapes HTML (replace "<" and ">" with their
539          * HTML entities).
540          *
541          * @example $("p").text("<b>Some</b> new text.");
542          * @before <p>Test Paragraph.</p>
543          * @result <p>&lt;b&gt;Some&lt;/b&gt; new text.</p>
544          * @desc Sets the text of all paragraphs.
545          *
546          * @example $("p").text("<b>Some</b> new text.", true);
547          * @before <p>Test Paragraph.</p>
548          * @result <p>Some new text.</p>
549          * @desc Sets the text of all paragraphs.
550          *
551          * @name text
552          * @type String
553          * @param String val The text value to set the contents of the element to.
554          * @cat DOM/Attributes
555          */
556         text: function(e) {
557                 if ( typeof e == "string" )
558                         return this.empty().append( document.createTextNode( e ) );
559
560                 var t = "";
561                 jQuery.each( e || this, function(){
562                         jQuery.each( this.childNodes, function(){
563                                 if ( this.nodeType != 8 )
564                                         t += this.nodeType != 1 ?
565                                                 this.nodeValue : jQuery.fn.text([ this ]);
566                         });
567                 });
568                 return t;
569         },
570
571         /**
572          * Wrap all matched elements with a structure of other elements.
573          * This wrapping process is most useful for injecting additional
574          * stucture into a document, without ruining the original semantic
575          * qualities of a document.
576          *
577          * This works by going through the first element
578          * provided (which is generated, on the fly, from the provided HTML)
579          * and finds the deepest ancestor element within its
580          * structure - it is that element that will en-wrap everything else.
581          *
582          * This does not work with elements that contain text. Any necessary text
583          * must be added after the wrapping is done.
584          *
585          * @example $("p").wrap("<div class='wrap'></div>");
586          * @before <p>Test Paragraph.</p>
587          * @result <div class='wrap'><p>Test Paragraph.</p></div>
588          * 
589          * @name wrap
590          * @type jQuery
591          * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
592          * @cat DOM/Manipulation
593          */
594
595         /**
596          * Wrap all matched elements with a structure of other elements.
597          * This wrapping process is most useful for injecting additional
598          * stucture into a document, without ruining the original semantic
599          * qualities of a document.
600          *
601          * This works by going through the first element
602          * provided and finding the deepest ancestor element within its
603          * structure - it is that element that will en-wrap everything else.
604          *
605          * This does not work with elements that contain text. Any necessary text
606          * must be added after the wrapping is done.
607          *
608          * @example $("p").wrap( document.getElementById('content') );
609          * @before <p>Test Paragraph.</p><div id="content"></div>
610          * @result <div id="content"><p>Test Paragraph.</p></div>
611          *
612          * @name wrap
613          * @type jQuery
614          * @param Element elem A DOM element that will be wrapped around the target.
615          * @cat DOM/Manipulation
616          */
617         wrap: function() {
618                 // The elements to wrap the target around
619                 var a = jQuery.clean(arguments);
620
621                 // Wrap each of the matched elements individually
622                 return this.each(function(){
623                         // Clone the structure that we're using to wrap
624                         var b = a[0].cloneNode(true);
625
626                         // Insert it before the element to be wrapped
627                         this.parentNode.insertBefore( b, this );
628
629                         // Find the deepest point in the wrap structure
630                         while ( b.firstChild )
631                                 b = b.firstChild;
632
633                         // Move the matched element to within the wrap structure
634                         b.appendChild( this );
635                 });
636         },
637
638         /**
639          * Append content to the inside of every matched element.
640          *
641          * This operation is similar to doing an appendChild to all the
642          * specified elements, adding them into the document.
643          *
644          * @example $("p").append("<b>Hello</b>");
645          * @before <p>I would like to say: </p>
646          * @result <p>I would like to say: <b>Hello</b></p>
647          * @desc Appends some HTML to all paragraphs.
648          *
649          * @example $("p").append( $("#foo")[0] );
650          * @before <p>I would like to say: </p><b id="foo">Hello</b>
651          * @result <p>I would like to say: <b id="foo">Hello</b></p>
652          * @desc Appends an Element to all paragraphs.
653          *
654          * @example $("p").append( $("b") );
655          * @before <p>I would like to say: </p><b>Hello</b>
656          * @result <p>I would like to say: <b>Hello</b></p>
657          * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
658          *
659          * @name append
660          * @type jQuery
661          * @param <Content> content Content to append to the target
662          * @cat DOM/Manipulation
663          * @see prepend(<Content>)
664          * @see before(<Content>)
665          * @see after(<Content>)
666          */
667         append: function() {
668                 return this.domManip(arguments, true, 1, function(a){
669                         this.appendChild( a );
670                 });
671         },
672
673         /**
674          * Prepend content to the inside of every matched element.
675          *
676          * This operation is the best way to insert elements
677          * inside, at the beginning, of all matched elements.
678          *
679          * @example $("p").prepend("<b>Hello</b>");
680          * @before <p>I would like to say: </p>
681          * @result <p><b>Hello</b>I would like to say: </p>
682          * @desc Prepends some HTML to all paragraphs.
683          *
684          * @example $("p").prepend( $("#foo")[0] );
685          * @before <p>I would like to say: </p><b id="foo">Hello</b>
686          * @result <p><b id="foo">Hello</b>I would like to say: </p>
687          * @desc Prepends an Element to all paragraphs.
688          *      
689          * @example $("p").prepend( $("b") );
690          * @before <p>I would like to say: </p><b>Hello</b>
691          * @result <p><b>Hello</b>I would like to say: </p>
692          * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
693          *
694          * @name prepend
695          * @type jQuery
696          * @param <Content> content Content to prepend to the target.
697          * @cat DOM/Manipulation
698          * @see append(<Content>)
699          * @see before(<Content>)
700          * @see after(<Content>)
701          */
702         prepend: function() {
703                 return this.domManip(arguments, true, -1, function(a){
704                         this.insertBefore( a, this.firstChild );
705                 });
706         },
707         
708         /**
709          * Insert content before each of the matched elements.
710          *
711          * @example $("p").before("<b>Hello</b>");
712          * @before <p>I would like to say: </p>
713          * @result <b>Hello</b><p>I would like to say: </p>
714          * @desc Inserts some HTML before all paragraphs.
715          *
716          * @example $("p").before( $("#foo")[0] );
717          * @before <p>I would like to say: </p><b id="foo">Hello</b>
718          * @result <b id="foo">Hello</b><p>I would like to say: </p>
719          * @desc Inserts an Element before all paragraphs.
720          *
721          * @example $("p").before( $("b") );
722          * @before <p>I would like to say: </p><b>Hello</b>
723          * @result <b>Hello</b><p>I would like to say: </p>
724          * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
725          *
726          * @name before
727          * @type jQuery
728          * @param <Content> content Content to insert before each target.
729          * @cat DOM/Manipulation
730          * @see append(<Content>)
731          * @see prepend(<Content>)
732          * @see after(<Content>)
733          */
734         before: function() {
735                 return this.domManip(arguments, false, 1, function(a){
736                         this.parentNode.insertBefore( a, this );
737                 });
738         },
739
740         /**
741          * Insert content after each of the matched elements.
742          *
743          * @example $("p").after("<b>Hello</b>");
744          * @before <p>I would like to say: </p>
745          * @result <p>I would like to say: </p><b>Hello</b>
746          * @desc Inserts some HTML after all paragraphs.
747          *
748          * @example $("p").after( $("#foo")[0] );
749          * @before <b id="foo">Hello</b><p>I would like to say: </p>
750          * @result <p>I would like to say: </p><b id="foo">Hello</b>
751          * @desc Inserts an Element after all paragraphs.
752          *
753          * @example $("p").after( $("b") );
754          * @before <b>Hello</b><p>I would like to say: </p>
755          * @result <p>I would like to say: </p><b>Hello</b>
756          * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
757          *
758          * @name after
759          * @type jQuery
760          * @param <Content> content Content to insert after each target.
761          * @cat DOM/Manipulation
762          * @see append(<Content>)
763          * @see prepend(<Content>)
764          * @see before(<Content>)
765          */
766         after: function() {
767                 return this.domManip(arguments, false, -1, function(a){
768                         this.parentNode.insertBefore( a, this.nextSibling );
769                 });
770         },
771
772         /**
773          * End the most recent 'destructive' operation, reverting the list of matched elements
774          * back to its previous state. After an end operation, the list of matched elements will
775          * revert to the last state of matched elements.
776          *
777          * If there was no destructive operation before, an empty set is returned.
778          *
779          * @example $("p").find("span").end();
780          * @before <p><span>Hello</span>, how are you?</p>
781          * @result [ <p>...</p> ]
782          * @desc Selects all paragraphs, finds span elements inside these, and reverts the
783          * selection back to the paragraphs.
784          *
785          * @name end
786          * @type jQuery
787          * @cat DOM/Traversing
788          */
789         end: function() {
790                 return this.prevObject || jQuery([]);
791         },
792
793         /**
794          * Searches for all elements that match the specified expression.
795          
796          * This method is a good way to find additional descendant
797          * elements with which to process.
798          *
799          * All searching is done using a jQuery expression. The expression can be
800          * written using CSS 1-3 Selector syntax, or basic XPath.
801          *
802          * @example $("p").find("span");
803          * @before <p><span>Hello</span>, how are you?</p>
804          * @result [ <span>Hello</span> ]
805          * @desc Starts with all paragraphs and searches for descendant span
806          * elements, same as $("p span")
807          *
808          * @name find
809          * @type jQuery
810          * @param String expr An expression to search with.
811          * @cat DOM/Traversing
812          */
813         find: function(t) {
814                 return this.pushStack( jQuery.map( this, function(a){
815                         return jQuery.find(t,a);
816                 }), t );
817         },
818
819         /**
820          * Clone matched DOM Elements and select the clones. 
821          *
822          * This is useful for moving copies of the elements to another
823          * location in the DOM.
824          *
825          * @example $("b").clone().prependTo("p");
826          * @before <b>Hello</b><p>, how are you?</p>
827          * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
828          * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
829          *
830          * @name clone
831          * @type jQuery
832          * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
833          * @cat DOM/Manipulation
834          */
835         clone: function(deep) {
836                 return this.pushStack( jQuery.map( this, function(a){
837                         var a = a.cloneNode( deep != undefined ? deep : true );
838                         a.$events = null; // drop $events expando to avoid firing incorrect events
839                         return a;
840                 }) );
841         },
842
843         /**
844          * Removes all elements from the set of matched elements that do not
845          * match the specified expression(s). This method is used to narrow down
846          * the results of a search.
847          *
848          * Provide a comma-separated list of expressions to apply multiple filters at once.
849          *
850          * @example $("p").filter(".selected")
851          * @before <p class="selected">Hello</p><p>How are you?</p>
852          * @result [ <p class="selected">Hello</p> ]
853          * @desc Selects all paragraphs and removes those without a class "selected".
854          *
855          * @example $("p").filter(".selected, :first")
856          * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
857          * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
858          * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
859          *
860          * @name filter
861          * @type jQuery
862          * @param String expression Expression(s) to search with.
863          * @cat DOM/Traversing
864          */
865          
866         /**
867          * Removes all elements from the set of matched elements that do not
868          * pass the specified filter. This method is used to narrow down
869          * the results of a search.
870          *
871          * @example $("p").filter(function(index) {
872          *   return $("ol", this).length == 0;
873          * })
874          * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
875          * @result [ <p>How are you?</p> ]
876          * @desc Remove all elements that have a child ol element
877          *
878          * @name filter
879          * @type jQuery
880          * @param Function filter A function to use for filtering
881          * @cat DOM/Traversing
882          */
883         filter: function(t) {
884                 return this.pushStack(
885                         jQuery.isFunction( t ) &&
886                         jQuery.grep(this, function(el, index){
887                                 return t.apply(el, [index])
888                         }) ||
889
890                         jQuery.multiFilter(t,this) );
891         },
892
893         /**
894          * Removes the specified Element from the set of matched elements. This
895          * method is used to remove a single Element from a jQuery object.
896          *
897          * @example $("p").not( $("#selected")[0] )
898          * @before <p>Hello</p><p id="selected">Hello Again</p>
899          * @result [ <p>Hello</p> ]
900          * @desc Removes the element with the ID "selected" from the set of all paragraphs.
901          *
902          * @name not
903          * @type jQuery
904          * @param Element el An element to remove from the set
905          * @cat DOM/Traversing
906          */
907
908         /**
909          * Removes elements matching the specified expression from the set
910          * of matched elements. This method is used to remove one or more
911          * elements from a jQuery object.
912          *
913          * @example $("p").not("#selected")
914          * @before <p>Hello</p><p id="selected">Hello Again</p>
915          * @result [ <p>Hello</p> ]
916          * @desc Removes the element with the ID "selected" from the set of all paragraphs.
917          *
918          * @name not
919          * @type jQuery
920          * @param String expr An expression with which to remove matching elements
921          * @cat DOM/Traversing
922          */
923
924         /**
925          * Removes any elements inside the array of elements from the set
926          * of matched elements. This method is used to remove one or more
927          * elements from a jQuery object.
928          *
929          * @example $("p").not( $("div p.selected") )
930          * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
931          * @result [ <p>Hello</p> ]
932          * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
933          *
934          * @name not
935          * @type jQuery
936          * @param jQuery elems A set of elements to remove from the jQuery set of matched elements.
937          * @cat DOM/Traversing
938          */
939         not: function(t) {
940                 return this.pushStack(
941                         t.constructor == String &&
942                         jQuery.multiFilter(t, this, true) ||
943
944                         jQuery.grep(this, function(a) {
945                                 return ( t.constructor == Array || t.jquery )
946                                         ? jQuery.inArray( a, t ) < 0
947                                         : a != t;
948                         })
949                 );
950         },
951
952         /**
953          * Adds more elements, matched by the given expression,
954          * to the set of matched elements.
955          *
956          * @example $("p").add("span")
957          * @before <p>Hello</p><span>Hello Again</span>
958          * @result [ <p>Hello</p>, <span>Hello Again</span> ]
959          *
960          * @name add
961          * @type jQuery
962          * @param String expr An expression whose matched elements are added
963          * @cat DOM/Traversing
964          */
965          
966         /**
967          * Adds more elements, created on the fly, to the set of
968          * matched elements.
969          *
970          * @example $("p").add("<span>Again</span>")
971          * @before <p>Hello</p>
972          * @result [ <p>Hello</p>, <span>Again</span> ]
973          *
974          * @name add
975          * @type jQuery
976          * @param String html A string of HTML to create on the fly.
977          * @cat DOM/Traversing
978          */
979
980         /**
981          * Adds one or more Elements to the set of matched elements.
982          *
983          * @example $("p").add( document.getElementById("a") )
984          * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
985          * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
986          *
987          * @example $("p").add( document.forms[0].elements )
988          * @before <p>Hello</p><p><form><input/><button/></form>
989          * @result [ <p>Hello</p>, <input/>, <button/> ]
990          *
991          * @name add
992          * @type jQuery
993          * @param Element|Array<Element> elements One or more Elements to add
994          * @cat DOM/Traversing
995          */
996         add: function(t) {
997                 return this.pushStack( jQuery.merge(
998                         this.get(),
999                         t.constructor == String ?
1000                                 jQuery(t).get() :
1001                                 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
1002                                         t : [t] )
1003                 );
1004         },
1005
1006         /**
1007          * Checks the current selection against an expression and returns true,
1008          * if at least one element of the selection fits the given expression.
1009          *
1010          * Does return false, if no element fits or the expression is not valid.
1011          *
1012          * filter(String) is used internally, therefore all rules that apply there
1013          * apply here, too.
1014          *
1015          * @example $("input[@type='checkbox']").parent().is("form")
1016          * @before <form><input type="checkbox" /></form>
1017          * @result true
1018          * @desc Returns true, because the parent of the input is a form element
1019          * 
1020          * @example $("input[@type='checkbox']").parent().is("form")
1021          * @before <form><p><input type="checkbox" /></p></form>
1022          * @result false
1023          * @desc Returns false, because the parent of the input is a p element
1024          *
1025          * @name is
1026          * @type Boolean
1027          * @param String expr The expression with which to filter
1028          * @cat DOM/Traversing
1029          */
1030         is: function(expr) {
1031                 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1032         },
1033         
1034         /**
1035          * Get the current value of the first matched element.
1036          *
1037          * @example $("input").val();
1038          * @before <input type="text" value="some text"/>
1039          * @result "some text"
1040          *
1041          * @name val
1042          * @type String
1043          * @cat DOM/Attributes
1044          */
1045         
1046         /**
1047          * Set the value of every matched element.
1048          *
1049          * @example $("input").val("test");
1050          * @before <input type="text" value="some text"/>
1051          * @result <input type="text" value="test"/>
1052          *
1053          * @name val
1054          * @type jQuery
1055          * @param String val Set the property to the specified value.
1056          * @cat DOM/Attributes
1057          */
1058         val: function( val ) {
1059                 return val == undefined ?
1060                         ( this.length ? this[0].value : null ) :
1061                         this.attr( "value", val );
1062         },
1063         
1064         /**
1065          * Get the html contents of the first matched element.
1066          * This property is not available on XML documents.
1067          *
1068          * @example $("div").html();
1069          * @before <div><input/></div>
1070          * @result <input/>
1071          *
1072          * @name html
1073          * @type String
1074          * @cat DOM/Attributes
1075          */
1076         
1077         /**
1078          * Set the html contents of every matched element.
1079          * This property is not available on XML documents.
1080          *
1081          * @example $("div").html("<b>new stuff</b>");
1082          * @before <div><input/></div>
1083          * @result <div><b>new stuff</b></div>
1084          *
1085          * @name html
1086          * @type jQuery
1087          * @param String val Set the html contents to the specified value.
1088          * @cat DOM/Attributes
1089          */
1090         html: function( val ) {
1091                 return val == undefined ?
1092                         ( this.length ? this[0].innerHTML : null ) :
1093                         this.empty().append( val );
1094         },
1095         
1096         /**
1097          * @private
1098          * @name domManip
1099          * @param Array args
1100          * @param Boolean table Insert TBODY in TABLEs if one is not found.
1101          * @param Number dir If dir<0, process args in reverse order.
1102          * @param Function fn The function doing the DOM manipulation.
1103          * @type jQuery
1104          * @cat Core
1105          */
1106         domManip: function(args, table, dir, fn){
1107                 var clone = this.length > 1; 
1108                 var a = jQuery.clean(args);
1109                 if ( dir < 0 )
1110                         a.reverse();
1111
1112                 return this.each(function(){
1113                         var obj = this;
1114
1115                         if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
1116                                 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1117
1118                         jQuery.each( a, function(){
1119                                 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
1120                         });
1121
1122                 });
1123         }
1124 };
1125
1126 /**
1127  * Extends the jQuery object itself. Can be used to add functions into
1128  * the jQuery namespace and to [[Plugins/Authoring|add plugin methods]] (plugins).
1129  * 
1130  * @example jQuery.fn.extend({
1131  *   check: function() {
1132  *     return this.each(function() { this.checked = true; });
1133  *   },
1134  *   uncheck: function() {
1135  *     return this.each(function() { this.checked = false; });
1136  *   }
1137  * });
1138  * $("input[@type=checkbox]").check();
1139  * $("input[@type=radio]").uncheck();
1140  * @desc Adds two plugin methods.
1141  *
1142  * @example jQuery.extend({
1143  *   min: function(a, b) { return a < b ? a : b; },
1144  *   max: function(a, b) { return a > b ? a : b; }
1145  * });
1146  * @desc Adds two functions into the jQuery namespace
1147  *
1148  * @name $.extend
1149  * @param Object prop The object that will be merged into the jQuery object
1150  * @type Object
1151  * @cat Core
1152  */
1153
1154 /**
1155  * Extend one object with one or more others, returning the original,
1156  * modified, object. This is a great utility for simple inheritance.
1157  * 
1158  * @example var settings = { validate: false, limit: 5, name: "foo" };
1159  * var options = { validate: true, name: "bar" };
1160  * jQuery.extend(settings, options);
1161  * @result settings == { validate: true, limit: 5, name: "bar" }
1162  * @desc Merge settings and options, modifying settings
1163  *
1164  * @example var defaults = { validate: false, limit: 5, name: "foo" };
1165  * var options = { validate: true, name: "bar" };
1166  * var settings = jQuery.extend({}, defaults, options);
1167  * @result settings == { validate: true, limit: 5, name: "bar" }
1168  * @desc Merge defaults and options, without modifying the defaults
1169  *
1170  * @name $.extend
1171  * @param Object target The object to extend
1172  * @param Object prop1 The object that will be merged into the first.
1173  * @param Object propN (optional) More objects to merge into the first
1174  * @type Object
1175  * @cat JavaScript
1176  */
1177 jQuery.extend = jQuery.fn.extend = function() {
1178         // copy reference to target object
1179         var target = arguments[0],
1180                 a = 1;
1181
1182         // extend jQuery itself if only one argument is passed
1183         if ( arguments.length == 1 ) {
1184                 target = this;
1185                 a = 0;
1186         }
1187         var prop;
1188         while (prop = arguments[a++])
1189                 // Extend the base object
1190                 for ( var i in prop ) target[i] = prop[i];
1191
1192         // Return the modified object
1193         return target;
1194 };
1195
1196 jQuery.extend({
1197         /**
1198          * Run this function to give control of the $ variable back
1199          * to whichever library first implemented it. This helps to make 
1200          * sure that jQuery doesn't conflict with the $ object
1201          * of other libraries.
1202          *
1203          * By using this function, you will only be able to access jQuery
1204          * using the 'jQuery' variable. For example, where you used to do
1205          * $("div p"), you now must do jQuery("div p").
1206          *
1207          * @example jQuery.noConflict();
1208          * // Do something with jQuery
1209          * jQuery("div p").hide();
1210          * // Do something with another library's $()
1211          * $("content").style.display = 'none';
1212          * @desc Maps the original object that was referenced by $ back to $
1213          *
1214          * @example jQuery.noConflict();
1215          * (function($) { 
1216          *   $(function() {
1217          *     // more code using $ as alias to jQuery
1218          *   });
1219          * })(jQuery);
1220          * // other code using $ as an alias to the other library
1221          * @desc Reverts the $ alias and then creates and executes a
1222          * function to provide the $ as a jQuery alias inside the functions
1223          * scope. Inside the function the original $ object is not available.
1224          * This works well for most plugins that don't rely on any other library.
1225          * 
1226          *
1227          * @name $.noConflict
1228          * @type undefined
1229          * @cat Core 
1230          */
1231         noConflict: function() {
1232                 if ( jQuery._$ )
1233                         $ = jQuery._$;
1234                 return jQuery;
1235         },
1236
1237         // This may seem like some crazy code, but trust me when I say that this
1238         // is the only cross-browser way to do this. --John
1239         isFunction: function( fn ) {
1240                 return !!fn && typeof fn != "string" && !fn.nodeName && 
1241                         typeof fn[0] == "undefined" && /function/i.test( fn + "" );
1242         },
1243         
1244         // check if an element is in a XML document
1245         isXMLDoc: function(elem) {
1246                 return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
1247         },
1248
1249         nodeName: function( elem, name ) {
1250                 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
1251         },
1252
1253         /**
1254          * A generic iterator function, which can be used to seemlessly
1255          * iterate over both objects and arrays. This function is not the same
1256          * as $().each() - which is used to iterate, exclusively, over a jQuery
1257          * object. This function can be used to iterate over anything.
1258          *
1259          * The callback has two arguments:the key (objects) or index (arrays) as first
1260          * the first, and the value as the second.
1261          *
1262          * @example $.each( [0,1,2], function(i, n){
1263          *   alert( "Item #" + i + ": " + n );
1264          * });
1265          * @desc This is an example of iterating over the items in an array,
1266          * accessing both the current item and its index.
1267          *
1268          * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1269          *   alert( "Name: " + i + ", Value: " + n );
1270          * });
1271          *
1272          * @desc This is an example of iterating over the properties in an
1273          * Object, accessing both the current item and its key.
1274          *
1275          * @name $.each
1276          * @param Object obj The object, or array, to iterate over.
1277          * @param Function fn The function that will be executed on every object.
1278          * @type Object
1279          * @cat JavaScript
1280          */
1281         // args is for internal usage only
1282         each: function( obj, fn, args ) {
1283                 if ( obj.length == undefined )
1284                         for ( var i in obj )
1285                                 fn.apply( obj[i], args || [i, obj[i]] );
1286                 else
1287                         for ( var i = 0, ol = obj.length; i < ol; i++ )
1288                                 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1289                 return obj;
1290         },
1291         
1292         prop: function(elem, value, type, index, prop){
1293                         // Handle executable functions
1294                         if ( jQuery.isFunction( value ) )
1295                                 value = value.call( elem, [index] );
1296                                 
1297                         // exclude the following css properties to add px
1298                         var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
1299
1300                         // Handle passing in a number to a CSS property
1301                         return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
1302                                 value + "px" :
1303                                 value;
1304         },
1305
1306         className: {
1307                 // internal only, use addClass("class")
1308                 add: function( elem, c ){
1309                         jQuery.each( c.split(/\s+/), function(i, cur){
1310                                 if ( !jQuery.className.has( elem.className, cur ) )
1311                                         elem.className += ( elem.className ? " " : "" ) + cur;
1312                         });
1313                 },
1314
1315                 // internal only, use removeClass("class")
1316                 remove: function( elem, c ){
1317                         elem.className = c ?
1318                                 jQuery.grep( elem.className.split(/\s+/), function(cur){
1319                                         return !jQuery.className.has( c, cur ); 
1320                                 }).join(" ") : "";
1321                 },
1322
1323                 // internal only, use is(".class")
1324                 has: function( t, c ) {
1325                         t = t.className || t;
1326                         // escape regex characters
1327                         c = c.replace(/([\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
1328                         return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
1329                 }
1330         },
1331
1332         /**
1333          * Swap in/out style options.
1334          * @private
1335          */
1336         swap: function(e,o,f) {
1337                 for ( var i in o ) {
1338                         e.style["old"+i] = e.style[i];
1339                         e.style[i] = o[i];
1340                 }
1341                 f.apply( e, [] );
1342                 for ( var i in o )
1343                         e.style[i] = e.style["old"+i];
1344         },
1345
1346         css: function(e,p) {
1347                 if ( p == "height" || p == "width" ) {
1348                         var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1349
1350                         jQuery.each( d, function(){
1351                                 old["padding" + this] = 0;
1352                                 old["border" + this + "Width"] = 0;
1353                         });
1354
1355                         jQuery.swap( e, old, function() {
1356                                 if (jQuery.css(e,"display") != "none") {
1357                                         oHeight = e.offsetHeight;
1358                                         oWidth = e.offsetWidth;
1359                                 } else {
1360                                         e = jQuery(e.cloneNode(true))
1361                                                 .find(":radio").removeAttr("checked").end()
1362                                                 .css({
1363                                                         visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1364                                                 }).appendTo(e.parentNode)[0];
1365
1366                                         var parPos = jQuery.css(e.parentNode,"position");
1367                                         if ( parPos == "" || parPos == "static" )
1368                                                 e.parentNode.style.position = "relative";
1369
1370                                         oHeight = e.clientHeight;
1371                                         oWidth = e.clientWidth;
1372
1373                                         if ( parPos == "" || parPos == "static" )
1374                                                 e.parentNode.style.position = "static";
1375
1376                                         e.parentNode.removeChild(e);
1377                                 }
1378                         });
1379
1380                         return p == "height" ? oHeight : oWidth;
1381                 }
1382
1383                 return jQuery.curCSS( e, p );
1384         },
1385
1386         curCSS: function(elem, prop, force) {
1387                 var ret;
1388                 
1389                 if (prop == "opacity" && jQuery.browser.msie)
1390                         return jQuery.attr(elem.style, "opacity");
1391                         
1392                 if (prop == "float" || prop == "cssFloat")
1393                     prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1394
1395                 if (!force && elem.style[prop])
1396                         ret = elem.style[prop];
1397
1398                 else if (document.defaultView && document.defaultView.getComputedStyle) {
1399
1400                         if (prop == "cssFloat" || prop == "styleFloat")
1401                                 prop = "float";
1402
1403                         prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1404                         var cur = document.defaultView.getComputedStyle(elem, null);
1405
1406                         if ( cur )
1407                                 ret = cur.getPropertyValue(prop);
1408                         else if ( prop == "display" )
1409                                 ret = "none";
1410                         else
1411                                 jQuery.swap(elem, { display: "block" }, function() {
1412                                     var c = document.defaultView.getComputedStyle(this, "");
1413                                     ret = c && c.getPropertyValue(prop) || "";
1414                                 });
1415
1416                 } else if (elem.currentStyle) {
1417
1418                         var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1419                         ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1420                         
1421                 }
1422
1423                 return ret;
1424         },
1425         
1426         clean: function(a) {
1427                 var r = [];
1428
1429                 jQuery.each( a, function(i,arg){
1430                         if ( !arg ) return;
1431
1432                         if ( arg.constructor == Number )
1433                                 arg = arg.toString();
1434                         
1435                          // Convert html string into DOM nodes
1436                         if ( typeof arg == "string" ) {
1437                                 // Trim whitespace, otherwise indexOf won't work as expected
1438                                 var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
1439
1440                                 var wrap =
1441                                          // option or optgroup
1442                                         !s.indexOf("<opt") &&
1443                                         [1, "<select>", "</select>"] ||
1444                                         
1445                                         (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
1446                                         [1, "<table>", "</table>"] ||
1447                                         
1448                                         !s.indexOf("<tr") &&
1449                                         [2, "<table><tbody>", "</tbody></table>"] ||
1450                                         
1451                                         // <thead> matched above
1452                                         (!s.indexOf("<td") || !s.indexOf("<th")) &&
1453                                         [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1454                                         
1455                                         [0,"",""];
1456
1457                                 // Go to html and back, then peel off extra wrappers
1458                                 div.innerHTML = wrap[1] + s + wrap[2];
1459                                 
1460                                 // Move to the right depth
1461                                 while ( wrap[0]-- )
1462                                         div = div.firstChild;
1463                                 
1464                                 // Remove IE's autoinserted <tbody> from table fragments
1465                                 if ( jQuery.browser.msie ) {
1466                                         
1467                                         // String was a <table>, *may* have spurious <tbody>
1468                                         if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 ) 
1469                                                 tb = div.firstChild && div.firstChild.childNodes;
1470                                                 
1471                                         // String was a bare <thead> or <tfoot>
1472                                         else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1473                                                 tb = div.childNodes;
1474
1475                                         for ( var n = tb.length-1; n >= 0 ; --n )
1476                                                 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
1477                                                         tb[n].parentNode.removeChild(tb[n]);
1478                                         
1479                                 }
1480                                 
1481                                 arg = div.childNodes;
1482                         }
1483
1484                         if ( arg.length === 0 && !jQuery.nodeName(arg, "form") )
1485                                 return;
1486                         
1487                         if ( arg[0] == undefined || jQuery.nodeName(arg, "form") )
1488                                 r.push( arg );
1489                         else
1490                                 r = jQuery.merge( r, arg );
1491
1492                 });
1493
1494                 return r;
1495         },
1496         
1497         attr: function(elem, name, value){
1498                 var fix = jQuery.isXMLDoc(elem) ? {} : {
1499                         "for": "htmlFor",
1500                         "class": "className",
1501                         "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1502                         cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1503                         innerHTML: "innerHTML",
1504                         className: "className",
1505                         value: "value",
1506                         disabled: "disabled",
1507                         checked: "checked",
1508                         readonly: "readOnly",
1509                         selected: "selected"
1510                 };
1511                 
1512                 // IE actually uses filters for opacity ... elem is actually elem.style
1513                 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1514                         // IE has trouble with opacity if it does not have layout
1515                         // Force it by setting the zoom level
1516                         elem.zoom = 1; 
1517
1518                         // Set the alpha filter to set the opacity
1519                         return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1520                                 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1521
1522                 } else if ( name == "opacity" && jQuery.browser.msie )
1523                         return elem.filter ? 
1524                                 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1525                 
1526                 // Mozilla doesn't play well with opacity 1
1527                 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1528                         value = 0.9999;
1529                         
1530
1531                 // Certain attributes only work when accessed via the old DOM 0 way
1532                 if ( fix[name] ) {
1533                         if ( value != undefined ) elem[fix[name]] = value;
1534                         return elem[fix[name]];
1535
1536                 } else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
1537                         return elem.getAttributeNode(name).nodeValue;
1538
1539                 // IE elem.getAttribute passes even for style
1540                 else if ( elem.tagName ) {
1541                         if ( value != undefined ) elem.setAttribute( name, value );
1542                         if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) ) 
1543                                 return elem.getAttribute( name, 2 );
1544                         return elem.getAttribute( name );
1545
1546                 // elem is actually elem.style ... set the style
1547                 } else {
1548                         name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1549                         if ( value != undefined ) elem[name] = value;
1550                         return elem[name];
1551                 }
1552         },
1553         
1554         /**
1555          * Remove the whitespace from the beginning and end of a string.
1556          *
1557          * @example $.trim("  hello, how are you?  ");
1558          * @result "hello, how are you?"
1559          *
1560          * @name $.trim
1561          * @type String
1562          * @param String str The string to trim.
1563          * @cat JavaScript
1564          */
1565         trim: function(t){
1566                 return t.replace(/^\s+|\s+$/g, "");
1567         },
1568
1569         makeArray: function( a ) {
1570                 var r = [];
1571
1572                 if ( a.constructor != Array )
1573                         for ( var i = 0, al = a.length; i < al; i++ )
1574                                 r.push( a[i] );
1575                 else
1576                         r = a.slice( 0 );
1577
1578                 return r;
1579         },
1580
1581         inArray: function( b, a ) {
1582                 for ( var i = 0, al = a.length; i < al; i++ )
1583                         if ( a[i] == b )
1584                                 return i;
1585                 return -1;
1586         },
1587
1588         /**
1589          * Merge two arrays together, removing all duplicates.
1590          *
1591          * The result is the altered first argument with
1592          * the unique elements from the second array added.
1593          *
1594          * @example $.merge( [0,1,2], [2,3,4] )
1595          * @result [0,1,2,3,4]
1596          * @desc Merges two arrays, removing the duplicate 2
1597          *
1598          * @example var array = [3,2,1];
1599          * $.merge( array, [4,3,2] )
1600          * @result array == [3,2,1,4]
1601          * @desc Merges two arrays, removing the duplicates 3 and 2
1602          *
1603          * @name $.merge
1604          * @type Array
1605          * @param Array first The first array to merge, the unique elements of second added.
1606          * @param Array second The second array to merge into the first, unaltered.
1607          * @cat JavaScript
1608          */
1609         merge: function(first, second) {
1610                 var r = [].slice.call( first, 0 );
1611
1612                 // Now check for duplicates between the two arrays
1613                 // and only add the unique items
1614                 for ( var i = 0, sl = second.length; i < sl; i++ )
1615                         // Check for duplicates
1616                         if ( jQuery.inArray( second[i], r ) == -1 )
1617                                 // The item is unique, add it
1618                                 first.push( second[i] );
1619
1620                 return first;
1621         },
1622
1623         /**
1624          * Filter items out of an array, by using a filter function.
1625          *
1626          * The specified function will be passed two arguments: The
1627          * current array item and the index of the item in the array. The
1628          * function must return 'true' to keep the item in the array, 
1629          * false to remove it.
1630          *
1631          * @example $.grep( [0,1,2], function(i){
1632          *   return i > 0;
1633          * });
1634          * @result [1, 2]
1635          *
1636          * @name $.grep
1637          * @type Array
1638          * @param Array array The Array to find items in.
1639          * @param Function fn The function to process each item against.
1640          * @param Boolean inv Invert the selection - select the opposite of the function.
1641          * @cat JavaScript
1642          */
1643         grep: function(elems, fn, inv) {
1644                 // If a string is passed in for the function, make a function
1645                 // for it (a handy shortcut)
1646                 if ( typeof fn == "string" )
1647                         fn = new Function("a","i","return " + fn);
1648
1649                 var result = [];
1650
1651                 // Go through the array, only saving the items
1652                 // that pass the validator function
1653                 for ( var i = 0, el = elems.length; i < el; i++ )
1654                         if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1655                                 result.push( elems[i] );
1656
1657                 return result;
1658         },
1659
1660         /**
1661          * Translate all items in an array to another array of items.
1662          *
1663          * The translation function that is provided to this method is 
1664          * called for each item in the array and is passed one argument: 
1665          * The item to be translated.
1666          *
1667          * The function can then return the translated value, 'null'
1668          * (to remove the item), or  an array of values - which will
1669          * be flattened into the full array.
1670          *
1671          * @example $.map( [0,1,2], function(i){
1672          *   return i + 4;
1673          * });
1674          * @result [4, 5, 6]
1675          * @desc Maps the original array to a new one and adds 4 to each value.
1676          *
1677          * @example $.map( [0,1,2], function(i){
1678          *   return i > 0 ? i + 1 : null;
1679          * });
1680          * @result [2, 3]
1681          * @desc Maps the original array to a new one and adds 1 to each
1682          * value if it is bigger then zero, otherwise it's removed-
1683          * 
1684          * @example $.map( [0,1,2], function(i){
1685          *   return [ i, i + 1 ];
1686          * });
1687          * @result [0, 1, 1, 2, 2, 3]
1688          * @desc Maps the original array to a new one, each element is added
1689          * with it's original value and the value plus one.
1690          *
1691          * @name $.map
1692          * @type Array
1693          * @param Array array The Array to translate.
1694          * @param Function fn The function to process each item against.
1695          * @cat JavaScript
1696          */
1697         map: function(elems, fn) {
1698                 // If a string is passed in for the function, make a function
1699                 // for it (a handy shortcut)
1700                 if ( typeof fn == "string" )
1701                         fn = new Function("a","return " + fn);
1702
1703                 var result = [], r = [];
1704
1705                 // Go through the array, translating each of the items to their
1706                 // new value (or values).
1707                 for ( var i = 0, el = elems.length; i < el; i++ ) {
1708                         var val = fn(elems[i],i);
1709
1710                         if ( val !== null && val != undefined ) {
1711                                 if ( val.constructor != Array ) val = [val];
1712                                 result = result.concat( val );
1713                         }
1714                 }
1715
1716                 var r = result.length ? [ result[0] ] : [];
1717
1718                 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1719                         for ( var j = 0; j < i; j++ )
1720                                 if ( result[i] == r[j] )
1721                                         continue check;
1722
1723                         r.push( result[i] );
1724                 }
1725
1726                 return r;
1727         }
1728 });
1729
1730 /**
1731  * Contains flags for the useragent, read from navigator.userAgent.
1732  * Available flags are: safari, opera, msie, mozilla
1733  *
1734  * This property is available before the DOM is ready, therefore you can
1735  * use it to add ready events only for certain browsers.
1736  *
1737  * There are situations where object detections is not reliable enough, in that
1738  * cases it makes sense to use browser detection. Simply try to avoid both!
1739  *
1740  * A combination of browser and object detection yields quite reliable results.
1741  *
1742  * @example $.browser.msie
1743  * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1744  *
1745  * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1746  * @desc Alerts "this is safari!" only for safari browsers
1747  *
1748  * @property
1749  * @name $.browser
1750  * @type Boolean
1751  * @cat JavaScript
1752  */
1753  
1754 /*
1755  * Whether the W3C compliant box model is being used.
1756  *
1757  * @property
1758  * @name $.boxModel
1759  * @type Boolean
1760  * @cat JavaScript
1761  */
1762 new function() {
1763         var b = navigator.userAgent.toLowerCase();
1764
1765         // Figure out what browser is being used
1766         jQuery.browser = {
1767                 safari: /webkit/.test(b),
1768                 opera: /opera/.test(b),
1769                 msie: /msie/.test(b) && !/opera/.test(b),
1770                 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1771         };
1772
1773         // Check to see if the W3C box model is being used
1774         jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1775 };
1776
1777 /**
1778  * Get a set of elements containing the unique parents of the matched
1779  * set of elements.
1780  *
1781  * Can be filtered with an optional expressions.
1782  *
1783  * @example $("p").parent()
1784  * @before <div><p>Hello</p><p>Hello</p></div>
1785  * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1786  * @desc Find the parent element of each paragraph.
1787  *
1788  * @example $("p").parent(".selected")
1789  * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1790  * @result [ <div class="selected"><p>Hello Again</p></div> ]
1791  * @desc Find the parent element of each paragraph with a class "selected".
1792  *
1793  * @name parent
1794  * @type jQuery
1795  * @param String expr (optional) An expression to filter the parents with
1796  * @cat DOM/Traversing
1797  */
1798
1799 /**
1800  * Get a set of elements containing the unique ancestors of the matched
1801  * set of elements (except for the root element).
1802  *
1803  * Can be filtered with an optional expressions.
1804  *
1805  * @example $("span").parents()
1806  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1807  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1808  * @desc Find all parent elements of each span.
1809  *
1810  * @example $("span").parents("p")
1811  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1812  * @result [ <p><span>Hello</span></p> ]
1813  * @desc Find all parent elements of each span that is a paragraph.
1814  *
1815  * @name parents
1816  * @type jQuery
1817  * @param String expr (optional) An expression to filter the ancestors with
1818  * @cat DOM/Traversing
1819  */
1820
1821 /**
1822  * Get a set of elements containing the unique next siblings of each of the
1823  * matched set of elements.
1824  *
1825  * It only returns the very next sibling, not all next siblings.
1826  *
1827  * Can be filtered with an optional expressions.
1828  *
1829  * @example $("p").next()
1830  * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1831  * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1832  * @desc Find the very next sibling of each paragraph.
1833  *
1834  * @example $("p").next(".selected")
1835  * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1836  * @result [ <p class="selected">Hello Again</p> ]
1837  * @desc Find the very next sibling of each paragraph that has a class "selected".
1838  *
1839  * @name next
1840  * @type jQuery
1841  * @param String expr (optional) An expression to filter the next Elements with
1842  * @cat DOM/Traversing
1843  */
1844
1845 /**
1846  * Get a set of elements containing the unique previous siblings of each of the
1847  * matched set of elements.
1848  *
1849  * Can be filtered with an optional expressions.
1850  *
1851  * It only returns the immediately previous sibling, not all previous siblings.
1852  *
1853  * @example $("p").prev()
1854  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1855  * @result [ <div><span>Hello Again</span></div> ]
1856  * @desc Find the very previous sibling of each paragraph.
1857  *
1858  * @example $("p").prev(".selected")
1859  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1860  * @result [ <div><span>Hello</span></div> ]
1861  * @desc Find the very previous sibling of each paragraph that has a class "selected".
1862  *
1863  * @name prev
1864  * @type jQuery
1865  * @param String expr (optional) An expression to filter the previous Elements with
1866  * @cat DOM/Traversing
1867  */
1868
1869 /**
1870  * Get a set of elements containing all of the unique siblings of each of the
1871  * matched set of elements.
1872  *
1873  * Can be filtered with an optional expressions.
1874  *
1875  * @example $("div").siblings()
1876  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1877  * @result [ <p>Hello</p>, <p>And Again</p> ]
1878  * @desc Find all siblings of each div.
1879  *
1880  * @example $("div").siblings(".selected")
1881  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1882  * @result [ <p class="selected">Hello Again</p> ]
1883  * @desc Find all siblings with a class "selected" of each div.
1884  *
1885  * @name siblings
1886  * @type jQuery
1887  * @param String expr (optional) An expression to filter the sibling Elements with
1888  * @cat DOM/Traversing
1889  */
1890
1891 /**
1892  * Get a set of elements containing all of the unique children of each of the
1893  * matched set of elements.
1894  *
1895  * Can be filtered with an optional expressions.
1896  *
1897  * @example $("div").children()
1898  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1899  * @result [ <span>Hello Again</span> ]
1900  * @desc Find all children of each div.
1901  *
1902  * @example $("div").children(".selected")
1903  * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1904  * @result [ <p class="selected">Hello Again</p> ]
1905  * @desc Find all children with a class "selected" of each div.
1906  *
1907  * @name children
1908  * @type jQuery
1909  * @param String expr (optional) An expression to filter the child Elements with
1910  * @cat DOM/Traversing
1911  */
1912 jQuery.each({
1913         parent: "a.parentNode",
1914         parents: "jQuery.parents(a)",
1915         next: "jQuery.nth(a,2,'nextSibling')",
1916         prev: "jQuery.nth(a,2,'previousSibling')",
1917         siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1918         children: "jQuery.sibling(a.firstChild)"
1919 }, function(i,n){
1920         jQuery.fn[ i ] = function(a) {
1921                 var ret = jQuery.map(this,n);
1922                 if ( a && typeof a == "string" )
1923                         ret = jQuery.multiFilter(a,ret);
1924                 return this.pushStack( ret );
1925         };
1926 });
1927
1928 /**
1929  * Append all of the matched elements to another, specified, set of elements.
1930  * This operation is, essentially, the reverse of doing a regular
1931  * $(A).append(B), in that instead of appending B to A, you're appending
1932  * A to B.
1933  *
1934  * @example $("p").appendTo("#foo");
1935  * @before <p>I would like to say: </p><div id="foo"></div>
1936  * @result <div id="foo"><p>I would like to say: </p></div>
1937  * @desc Appends all paragraphs to the element with the ID "foo"
1938  *
1939  * @name appendTo
1940  * @type jQuery
1941  * @param <Content> content Content to append to the selected element to.
1942  * @cat DOM/Manipulation
1943  * @see append(<Content>)
1944  */
1945
1946 /**
1947  * Prepend all of the matched elements to another, specified, set of elements.
1948  * This operation is, essentially, the reverse of doing a regular
1949  * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1950  * A to B.
1951  *
1952  * @example $("p").prependTo("#foo");
1953  * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1954  * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1955  * @desc Prepends all paragraphs to the element with the ID "foo"
1956  *
1957  * @name prependTo
1958  * @type jQuery
1959  * @param <Content> content Content to prepend to the selected element to.
1960  * @cat DOM/Manipulation
1961  * @see prepend(<Content>)
1962  */
1963
1964 /**
1965  * Insert all of the matched elements before another, specified, set of elements.
1966  * This operation is, essentially, the reverse of doing a regular
1967  * $(A).before(B), in that instead of inserting B before A, you're inserting
1968  * A before B.
1969  *
1970  * @example $("p").insertBefore("#foo");
1971  * @before <div id="foo">Hello</div><p>I would like to say: </p>
1972  * @result <p>I would like to say: </p><div id="foo">Hello</div>
1973  * @desc Same as $("#foo").before("p")
1974  *
1975  * @name insertBefore
1976  * @type jQuery
1977  * @param <Content> content Content to insert the selected element before.
1978  * @cat DOM/Manipulation
1979  * @see before(<Content>)
1980  */
1981
1982 /**
1983  * Insert all of the matched elements after another, specified, set of elements.
1984  * This operation is, essentially, the reverse of doing a regular
1985  * $(A).after(B), in that instead of inserting B after A, you're inserting
1986  * A after B.
1987  *
1988  * @example $("p").insertAfter("#foo");
1989  * @before <p>I would like to say: </p><div id="foo">Hello</div>
1990  * @result <div id="foo">Hello</div><p>I would like to say: </p>
1991  * @desc Same as $("#foo").after("p")
1992  *
1993  * @name insertAfter
1994  * @type jQuery
1995  * @param <Content> content Content to insert the selected element after.
1996  * @cat DOM/Manipulation
1997  * @see after(<Content>)
1998  */
1999
2000 jQuery.each({
2001         appendTo: "append",
2002         prependTo: "prepend",
2003         insertBefore: "before",
2004         insertAfter: "after"
2005 }, function(i,n){
2006         jQuery.fn[ i ] = function(){
2007                 var a = arguments;
2008                 return this.each(function(){
2009                         for ( var j = 0, al = a.length; j < al; j++ )
2010                                 jQuery(a[j])[n]( this );
2011                 });
2012         };
2013 });
2014
2015 /**
2016  * Remove an attribute from each of the matched elements.
2017  *
2018  * @example $("input").removeAttr("disabled")
2019  * @before <input disabled="disabled"/>
2020  * @result <input/>
2021  *
2022  * @name removeAttr
2023  * @type jQuery
2024  * @param String name The name of the attribute to remove.
2025  * @cat DOM/Attributes
2026  */
2027
2028 /**
2029  * Adds the specified class(es) to each of the set of matched elements.
2030  *
2031  * @example $("p").addClass("selected")
2032  * @before <p>Hello</p>
2033  * @result [ <p class="selected">Hello</p> ]
2034  *
2035  * @example $("p").addClass("selected highlight")
2036  * @before <p>Hello</p>
2037  * @result [ <p class="selected highlight">Hello</p> ]
2038  *
2039  * @name addClass
2040  * @type jQuery
2041  * @param String class One or more CSS classes to add to the elements
2042  * @cat DOM/Attributes
2043  * @see removeClass(String)
2044  */
2045
2046 /**
2047  * Removes all or the specified class(es) from the set of matched elements.
2048  *
2049  * @example $("p").removeClass()
2050  * @before <p class="selected">Hello</p>
2051  * @result [ <p>Hello</p> ]
2052  *
2053  * @example $("p").removeClass("selected")
2054  * @before <p class="selected first">Hello</p>
2055  * @result [ <p class="first">Hello</p> ]
2056  *
2057  * @example $("p").removeClass("selected highlight")
2058  * @before <p class="highlight selected first">Hello</p>
2059  * @result [ <p class="first">Hello</p> ]
2060  *
2061  * @name removeClass
2062  * @type jQuery
2063  * @param String class (optional) One or more CSS classes to remove from the elements
2064  * @cat DOM/Attributes
2065  * @see addClass(String)
2066  */
2067
2068 /**
2069  * Adds the specified class if it is not present, removes it if it is
2070  * present.
2071  *
2072  * @example $("p").toggleClass("selected")
2073  * @before <p>Hello</p><p class="selected">Hello Again</p>
2074  * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2075  *
2076  * @name toggleClass
2077  * @type jQuery
2078  * @param String class A CSS class with which to toggle the elements
2079  * @cat DOM/Attributes
2080  */
2081
2082 /**
2083  * Removes all matched elements from the DOM. This does NOT remove them from the
2084  * jQuery object, allowing you to use the matched elements further.
2085  *
2086  * Can be filtered with an optional expressions.
2087  *
2088  * @example $("p").remove();
2089  * @before <p>Hello</p> how are <p>you?</p>
2090  * @result how are
2091  *
2092  * @example $("p").remove(".hello");
2093  * @before <p class="hello">Hello</p> how are <p>you?</p>
2094  * @result how are <p>you?</p>
2095  *
2096  * @name remove
2097  * @type jQuery
2098  * @param String expr (optional) A jQuery expression to filter elements by.
2099  * @cat DOM/Manipulation
2100  */
2101
2102 /**
2103  * Removes all child nodes from the set of matched elements.
2104  *
2105  * @example $("p").empty()
2106  * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2107  * @result [ <p></p> ]
2108  *
2109  * @name empty
2110  * @type jQuery
2111  * @cat DOM/Manipulation
2112  */
2113
2114 jQuery.each( {
2115         removeAttr: function( key ) {
2116                 jQuery.attr( this, key, "" );
2117                 this.removeAttribute( key );
2118         },
2119         addClass: function(c){
2120                 jQuery.className.add(this,c);
2121         },
2122         removeClass: function(c){
2123                 jQuery.className.remove(this,c);
2124         },
2125         toggleClass: function( c ){
2126                 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2127         },
2128         remove: function(a){
2129                 if ( !a || jQuery.filter( a, [this] ).r.length )
2130                         this.parentNode.removeChild( this );
2131         },
2132         empty: function() {
2133                 while ( this.firstChild )
2134                         this.removeChild( this.firstChild );
2135         }
2136 }, function(i,n){
2137         jQuery.fn[ i ] = function() {
2138                 return this.each( n, arguments );
2139         };
2140 });
2141
2142 /**
2143  * Reduce the set of matched elements to a single element.
2144  * The position of the element in the set of matched elements
2145  * starts at 0 and goes to length - 1.
2146  *
2147  * @example $("p").eq(1)
2148  * @before <p>This is just a test.</p><p>So is this</p>
2149  * @result [ <p>So is this</p> ]
2150  *
2151  * @name eq
2152  * @type jQuery
2153  * @param Number pos The index of the element that you wish to limit to.
2154  * @cat Core
2155  */
2156
2157 /**
2158  * Reduce the set of matched elements to all elements before a given position.
2159  * The position of the element in the set of matched elements
2160  * starts at 0 and goes to length - 1.
2161  *
2162  * @example $("p").lt(1)
2163  * @before <p>This is just a test.</p><p>So is this</p>
2164  * @result [ <p>This is just a test.</p> ]
2165  *
2166  * @name lt
2167  * @type jQuery
2168  * @param Number pos Reduce the set to all elements below this position.
2169  * @cat Core
2170  */
2171
2172 /**
2173  * Reduce the set of matched elements to all elements after a given position.
2174  * The position of the element in the set of matched elements
2175  * starts at 0 and goes to length - 1.
2176  *
2177  * @example $("p").gt(0)
2178  * @before <p>This is just a test.</p><p>So is this</p>
2179  * @result [ <p>So is this</p> ]
2180  *
2181  * @name gt
2182  * @type jQuery
2183  * @param Number pos Reduce the set to all elements after this position.
2184  * @cat Core
2185  */
2186
2187 /**
2188  * Filter the set of elements to those that contain the specified text.
2189  *
2190  * @example $("p").contains("test")
2191  * @before <p>This is just a test.</p><p>So is this</p>
2192  * @result [ <p>This is just a test.</p> ]
2193  *
2194  * @name contains
2195  * @type jQuery
2196  * @param String str The string that will be contained within the text of an element.
2197  * @cat DOM/Traversing
2198  */
2199 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2200         jQuery.fn[ n ] = function(num,fn) {
2201                 return this.filter( ":" + n + "(" + num + ")", fn );
2202         };
2203 });
2204
2205 /**
2206  * Get the current computed, pixel, width of the first matched element.
2207  *
2208  * @example $("p").width();
2209  * @before <p>This is just a test.</p>
2210  * @result 300
2211  *
2212  * @name width
2213  * @type String
2214  * @cat CSS
2215  */
2216
2217 /**
2218  * Set the CSS width of every matched element. If no explicit unit
2219  * was specified (like 'em' or '%') then "px" is added to the width.
2220  *
2221  * @example $("p").width(20);
2222  * @before <p>This is just a test.</p>
2223  * @result <p style="width:20px;">This is just a test.</p>
2224  *
2225  * @example $("p").width("20em");
2226  * @before <p>This is just a test.</p>
2227  * @result <p style="width:20em;">This is just a test.</p>
2228  *
2229  * @name width
2230  * @type jQuery
2231  * @param String|Number val Set the CSS property to the specified value.
2232  * @cat CSS
2233  */
2234  
2235 /**
2236  * Get the current computed, pixel, height of the first matched element.
2237  *
2238  * @example $("p").height();
2239  * @before <p>This is just a test.</p>
2240  * @result 300
2241  *
2242  * @name height
2243  * @type String
2244  * @cat CSS
2245  */
2246
2247 /**
2248  * Set the CSS width of every matched element. If no explicit unit
2249  * was specified (like 'em' or '%') then "px" is added to the width.
2250  *
2251  * @example $("p").height(20);
2252  * @before <p>This is just a test.</p>
2253  * @result <p style="height:20px;">This is just a test.</p>
2254  *
2255  * @example $("p").height("20em");
2256  * @before <p>This is just a test.</p>
2257  * @result <p style="height:20em;">This is just a test.</p>
2258  *
2259  * @name height
2260  * @type jQuery
2261  * @param String|Number val Set the CSS property to the specified value.
2262  * @cat CSS
2263  */
2264
2265 jQuery.each( [ "height", "width" ], function(i,n){
2266         jQuery.fn[ n ] = function(h) {
2267                 return h == undefined ?
2268                         ( this.length ? jQuery.css( this[0], n ) : null ) :
2269                         this.css( n, h.constructor == String ? h : h + "px" );
2270         };
2271 });