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