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