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