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