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