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