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