2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
21 * @param String|Function|Element|Array<Element>|jQuery a selector
22 * @param jQuery|Element|Array<Element> c context
25 var jQuery = function(a,c) {
26 // If the context is global, return a new object
28 return new jQuery(a,c);
30 // Make sure that a selection was provided
33 // HANDLE: $(function)
34 // Shortcut for document ready
35 // Safari reports typeof on DOM NodeLists as a function
36 if ( typeof a == "function" && !a.nodeType && a[0] == undefined )
37 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
39 // Handle HTML strings
40 if ( typeof a == "string" ) {
41 // HANDLE: $(html) -> $(array)
42 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
44 a = jQuery.clean( [ m[1] ] );
48 return new jQuery( c ).find( a );
53 a.constructor == Array && a ||
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 ) ||
63 // Map over the $ in case of overwrite
64 if ( typeof $ != "undefined" )
67 // Map the jQuery namespace to the '$' one
71 * This function accepts a string containing a CSS or
72 * basic XPath selector which is then used to match a set of elements.
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
80 * By default, $() looks for DOM elements within the context of the
81 * current HTML document.
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> ]
88 * @example $("input:radio", document.forms[0])
89 * @desc Searches for all inputs of type radio within the first form in the document
91 * @example $("div", xml.responseXML)
92 * @desc This finds all div elements within the specified XML document.
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
100 * @see $(Element<Array>)
104 * Create DOM elements on-the-fly from the provided String of raw HTML.
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.
113 * @param String html A string of HTML to create on the fly.
116 * @see appendTo(String)
120 * Wrap jQuery functionality around a single or multiple DOM Element(s).
122 * This function also accepts XML Documents and Window objects
123 * as valid arguments (even though they are not DOM Elements).
125 * @example $(document).find("div > p")
126 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
127 * @result [ <p>two</p> ]
128 * @desc Same as $("div > p") because the document
130 * @example $(document.body).background( "black" );
131 * @desc Sets the background color of the page to black.
133 * @example $( myForm.elements ).hide()
134 * @desc Hides all the input elements within a form
137 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
143 * A shorthand for $(document).ready(), allowing you to bind a function
144 * to be executed when the DOM document has finished loading. This function
145 * behaves just like $(document).ready(), in that it should be used to wrap
146 * all of the other $() operations on your page. While this function is,
147 * technically, chainable - there really isn't much use for chaining against it.
148 * You can have as many $(document).ready events on your page as you like.
150 * See ready(Function) for details about the ready event.
152 * @example $(function(){
153 * // Document is ready
155 * @desc Executes the function when the DOM is ready to be used.
158 * @param Function fn The function to execute when the DOM is ready.
164 * A means of creating a cloned copy of a jQuery object. This function
165 * copies the set of matched elements from one jQuery object and creates
166 * another, new, jQuery object containing the same elements.
168 * @example var div = $("div");
169 * $( div ).find("p");
170 * @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).
173 * @param jQuery obj The jQuery object to be cloned.
178 jQuery.fn = jQuery.prototype = {
180 * The current version of jQuery.
191 * The number of elements currently matched.
193 * @example $("img").length;
194 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
204 * The number of elements currently matched.
206 * @example $("img").size();
207 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
221 * Access all matched elements. This serves as a backwards-compatible
222 * way of accessing all matched elements (other than the jQuery object
223 * itself, which is, in fact, an array of elements).
225 * @example $("img").get();
226 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
227 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
228 * @desc Selects all images in the document and returns the DOM Elements as an Array
231 * @type Array<Element>
236 * Access a single matched element. num is used to access the
237 * Nth element matched.
239 * @example $("img").get(0);
240 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
241 * @result [ <img src="test1.jpg"/> ]
242 * @desc Selects all images in the document and returns the first one
246 * @param Number num Access the element in the Nth position.
249 get: function( num ) {
250 return num == undefined ?
252 // Return a 'clean' array
253 jQuery.makeArray( this ) :
255 // Return just the object
260 * Set the jQuery object to an array of elements, while maintaining
263 * @example $("img").set([ document.body ]);
264 * @result $("img").set() == [ document.body ]
269 * @param Elements elems An array of elements
273 var ret = jQuery(this);
274 ret.prevObject = this;
275 return ret.setArray( a );
279 * Set the jQuery object to an array of elements. This operation is
280 * completely destructive - be sure to use .set() if you wish to maintain
283 * @example $("img").setArray([ document.body ]);
284 * @result $("img").setArray() == [ document.body ]
289 * @param Elements elems An array of elements
292 setArray: function( a ) {
294 [].push.apply( this, a );
299 * Execute a function within the context of every matched element.
300 * This means that every time the passed-in function is executed
301 * (which is once for every element matched) the 'this' keyword
302 * points to the specific element.
304 * Additionally, the function, when executed, is passed a single
305 * argument representing the position of the element in the matched
308 * @example $("img").each(function(i){
309 * this.src = "test" + i + ".jpg";
311 * @before <img/><img/>
312 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
313 * @desc Iterates over two images and sets their src property
317 * @param Function fn A function to execute
320 each: function( fn, args ) {
321 return jQuery.each( this, fn, args );
325 * Searches every matched element for the object and returns
326 * the index of the element, if found, starting with zero.
327 * Returns -1 if the object wasn't found.
329 * @example $("*").index( $('#foobar')[0] )
330 * @before <div id="foobar"></div><b></b><span id="foo"></span>
332 * @desc Returns the index for the element with ID foobar
334 * @example $("*").index( $('#foo'))
335 * @before <div id="foobar"></div><b></b><span id="foo"></span>
337 * @desc Returns the index for the element with ID foo
339 * @example $("*").index( $('#bar'))
340 * @before <div id="foobar"></div><b></b><span id="foo"></span>
342 * @desc Returns -1, as there is no element with ID bar
346 * @param Element subject Object to search for
349 index: function( obj ) {
351 this.each(function(i){
352 if ( this == obj ) pos = i;
358 * Access a property on the first matched element.
359 * This method makes it easy to retrieve a property value
360 * from the first matched element.
362 * @example $("img").attr("src");
363 * @before <img src="test.jpg"/>
365 * @desc Returns the src attribute from the first image in the document.
369 * @param String name The name of the property to access.
370 * @cat DOM/Attributes
374 * Set a key/value object as properties to all matched elements.
376 * This serves as the best way to set a large number of properties
377 * on all matched elements.
379 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
381 * @result <img src="test.jpg" alt="Test Image"/>
382 * @desc Sets src and alt attributes to all images.
386 * @param Map properties Key/value pairs to set as object properties.
387 * @cat DOM/Attributes
391 * Set a single property to a value, on all matched elements.
393 * Can compute values provided as ${formula}, see second example.
395 * Note that you can't set the name property of input elements in IE.
396 * Use $(html) or .append(html) or .html(html) to create elements
397 * on the fly including the name property.
399 * @example $("img").attr("src","test.jpg");
401 * @result <img src="test.jpg"/>
402 * @desc Sets src attribute to all images.
404 * @example $("img").attr("title", "${this.src}");
405 * @before <img src="test.jpg" />
406 * @result <img src="test.jpg" title="test.jpg" />
407 * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
411 * @param String key The name of the property to set.
412 * @param Object value The value to set the property to.
413 * @cat DOM/Attributes
417 * Set a single property to a computed value, on all matched elements.
419 * Instead of a value, a function is provided, that computes the value.
421 * @example $("img").attr("title", function() { return this.src });
422 * @before <img src="test.jpg" />
423 * @result <img src="test.jpg" title="test.jpg" />
424 * @desc Sets title attribute from src attribute.
428 * @param String key The name of the property to set.
429 * @param Function value A function returning the value to set.
430 * @cat DOM/Attributes
432 attr: function( key, value, type ) {
435 // Look for the case where we're accessing a style value
436 if ( key.constructor == String )
437 if ( value == undefined )
438 return jQuery[ type || "attr" ]( this[0], key );
444 // Check to see if we're setting style values
445 return this.each(function(){
446 // Set all the styles
447 for ( var prop in obj )
449 type ? this.style : this,
450 prop, jQuery.prop(this, prop, obj[prop], type)
456 * Access a style property on the first matched element.
457 * This method makes it easy to retrieve a style property value
458 * from the first matched element.
460 * @example $("p").css("color");
461 * @before <p style="color:red;">Test Paragraph.</p>
463 * @desc Retrieves the color style of the first paragraph
465 * @example $("p").css("font-weight");
466 * @before <p style="font-weight: bold;">Test Paragraph.</p>
468 * @desc Retrieves the font-weight style of the first paragraph.
472 * @param String name The name of the property to access.
477 * Set a key/value object as style properties to all matched elements.
479 * This serves as the best way to set a large number of style properties
480 * on all matched elements.
482 * @example $("p").css({ color: "red", background: "blue" });
483 * @before <p>Test Paragraph.</p>
484 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
485 * @desc Sets color and background styles to all p elements.
489 * @param Map properties Key/value pairs to set as style properties.
494 * Set a single style property to a value, on all matched elements.
496 * @example $("p").css("color","red");
497 * @before <p>Test Paragraph.</p>
498 * @result <p style="color:red;">Test Paragraph.</p>
499 * @desc Changes the color of all paragraphs to red
503 * @param String key The name of the property to set.
504 * @param Object value The value to set the property to.
507 css: function( key, value ) {
508 return this.attr( key, value, "curCSS" );
512 * Get the text contents of all matched elements. The result is
513 * a string that contains the combined text contents of all matched
514 * elements. This method works on both HTML and XML documents.
516 * @example $("p").text();
517 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
518 * @result Test Paragraph.Paraparagraph
519 * @desc Gets the concatenated text of all paragraphs
523 * @cat DOM/Attributes
527 * Set the text contents of all matched elements.
529 * Similar to html(), but escapes HTML (replace "<" and ">" with their
532 * @example $("p").text("<b>Some</b> new text.");
533 * @before <p>Test Paragraph.</p>
534 * @result <p><b>Some</b> new text.</p>
535 * @desc Sets the text of all paragraphs.
537 * @example $("p").text("<b>Some</b> new text.", true);
538 * @before <p>Test Paragraph.</p>
539 * @result <p>Some new text.</p>
540 * @desc Sets the text of all paragraphs.
544 * @param String val The text value to set the contents of the element to.
545 * @cat DOM/Attributes
548 var type = this.length && this[0].innerText == undefined ?
549 "textContent" : "innerText";
551 return e == undefined ?
552 this.length && this[0][ type ] :
553 this.each(function(){ this[ type ] = e; });
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.
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.
567 * This does not work with elements that contain text. Any necessary text
568 * must be added after the wrapping is done.
570 * @example $("p").wrap("<div class='wrap'></div>");
571 * @before <p>Test Paragraph.</p>
572 * @result <div class='wrap'><p>Test Paragraph.</p></div>
576 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
577 * @cat DOM/Manipulation
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.
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.
590 * This does not work with elements that contain text. Any necessary text
591 * must be added after the wrapping is done.
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>
599 * @param Element elem A DOM element that will be wrapped around the target.
600 * @cat DOM/Manipulation
603 // The elements to wrap the target around
604 var a = jQuery.clean(arguments);
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);
611 // Insert it before the element to be wrapped
612 this.parentNode.insertBefore( b, this );
614 // Find the deepest point in the wrap structure
615 while ( b.firstChild )
618 // Move the matched element to within the wrap structure
619 b.appendChild( this );
624 * Append content to the inside of every matched element.
626 * This operation is similar to doing an appendChild to all the
627 * specified elements, adding them into the document.
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.
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.
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.
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>)
653 return this.domManip(arguments, true, 1, function(a){
654 this.appendChild( a );
659 * Prepend content to the inside of every matched element.
661 * This operation is the best way to insert elements
662 * inside, at the beginning, of all matched elements.
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.
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.
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.
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>)
687 prepend: function() {
688 return this.domManip(arguments, true, -1, function(a){
689 this.insertBefore( a, this.firstChild );
694 * Insert content before each of the matched elements.
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.
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.
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.
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>)
720 return this.domManip(arguments, false, 1, function(a){
721 this.parentNode.insertBefore( a, this );
726 * Insert content after each of the matched elements.
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.
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.
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.
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>)
752 return this.domManip(arguments, false, -1, function(a){
753 this.parentNode.insertBefore( a, this.nextSibling );
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.
762 * If there was no destructive operation before, an empty set is returned.
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.
772 * @cat DOM/Traversing
775 return this.prevObject || jQuery([]);
779 * Searches for all elements that match the specified expression.
781 * This method is a good way to find additional descendant
782 * elements with which to process.
784 * All searching is done using a jQuery expression. The expression can be
785 * written using CSS 1-3 Selector syntax, or basic XPath.
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")
795 * @param String expr An expression to search with.
796 * @cat DOM/Traversing
799 return this.set( jQuery.map( this, function(a){
800 return jQuery.find(t,a);
805 * Clone matched DOM Elements and select the clones.
807 * This is useful for moving copies of the elements to another
808 * location in the DOM.
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.
817 * @cat DOM/Manipulation
819 clone: function(deep) {
820 return this.set( jQuery.map( this, function(a){
821 return a.cloneNode( deep != undefined ? deep : true );
826 * Removes all elements from the set of matched elements that do not
827 * match the specified expression(s). This method is used to narrow down
828 * the results of a search.
830 * Provide a String array of expressions to apply multiple filters at once.
832 * @example $("p").filter(".selected")
833 * @before <p class="selected">Hello</p><p>How are you?</p>
834 * @result [ <p class="selected">Hello</p> ]
835 * @desc Selects all paragraphs and removes those without a class "selected".
837 * @example $("p").filter([".selected", ":first"])
838 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
839 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
840 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
844 * @param String|Array<String> expression Expression(s) to search with.
845 * @cat DOM/Traversing
849 * Removes all elements from the set of matched elements that do not
850 * pass the specified filter. This method is used to narrow down
851 * the results of a search.
853 * @example $("p").filter(function(index) {
854 * return $("ol", this).length == 0;
856 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
857 * @result [ <p>How are you?</p> ]
858 * @desc Remove all elements that have a child ol element
862 * @param Function filter A function to use for filtering
863 * @cat DOM/Traversing
865 filter: function(t) {
867 t.constructor == Array &&
868 jQuery.map(this,function(a){
869 for ( var i = 0, tl = t.length; i < tl; i++ )
870 if ( jQuery.filter(t[i],[a]).r.length )
875 t.constructor == Boolean &&
876 ( t ? this.get() : [] ) ||
878 typeof t == "function" &&
879 jQuery.grep( this, function(el, index) { return t.apply(el, [index]) }) ||
881 jQuery.filter(t,this).r );
885 * Removes the specified Element from the set of matched elements. This
886 * method is used to remove a single Element from a jQuery object.
888 * @example $("p").not( $("#selected")[0] )
889 * @before <p>Hello</p><p id="selected">Hello Again</p>
890 * @result [ <p>Hello</p> ]
891 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
895 * @param Element el An element to remove from the set
896 * @cat DOM/Traversing
900 * Removes elements matching the specified expression from the set
901 * of matched elements. This method is used to remove one or more
902 * elements from a jQuery object.
904 * @example $("p").not("#selected")
905 * @before <p>Hello</p><p id="selected">Hello Again</p>
906 * @result [ <p>Hello</p> ]
907 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
911 * @param String expr An expression with which to remove matching elements
912 * @cat DOM/Traversing
915 return this.set( typeof t == "string" ?
916 jQuery.filter(t,this,true).r :
917 jQuery.grep(this,function(a){ return a != t; }) );
921 * Adds the elements matched by the expression to the jQuery object. This
922 * can be used to concatenate the result sets of two expressions.
924 * @example $("p").add("span")
925 * @before <p>Hello</p><p><span>Hello Again</span></p>
926 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
930 * @param String expr An expression whose matched elements are added
931 * @cat DOM/Traversing
935 * Adds one or more Elements to the set of matched elements.
937 * This is used to add a set of Elements to a jQuery object.
939 * @example $("p").add( document.getElementById("a") )
940 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
941 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
943 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
944 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
945 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
949 * @param Element|Array<Element> elements One or more Elements to add
950 * @cat DOM/Traversing
953 return this.set( jQuery.merge(
954 this.get(), typeof t == "string" ?
956 t.constructor == Array ? t : [t] ) );
960 * Checks the current selection against an expression and returns true,
961 * if at least one element of the selection fits the given expression.
963 * Does return false, if no element fits or the expression is not valid.
965 * filter(String) is used internally, therefore all rules that apply there
968 * @example $("input[@type='checkbox']").parent().is("form")
969 * @before <form><input type="checkbox" /></form>
971 * @desc Returns true, because the parent of the input is a form element
973 * @example $("input[@type='checkbox']").parent().is("form")
974 * @before <form><p><input type="checkbox" /></p></form>
976 * @desc Returns false, because the parent of the input is a p element
980 * @param String expr The expression with which to filter
981 * @cat DOM/Traversing
984 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
988 * Get the current value of the first matched element.
990 * @example $("input").val();
991 * @before <input type="text" value="some text"/>
992 * @result "some text"
996 * @cat DOM/Attributes
1000 * Set the value of every matched element.
1002 * @example $("input").val("test");
1003 * @before <input type="text" value="some text"/>
1004 * @result <input type="text" value="test"/>
1008 * @param String val Set the property to the specified value.
1009 * @cat DOM/Attributes
1011 val: function( val ) {
1012 return val == undefined ?
\r ( this.length ? this[0].value : null ) :
\r this.attr( "value", val );
1016 * Get the html contents of the first matched element.
1017 * This property is not available on XML documents.
1019 * @example $("div").html();
1020 * @before <div><input/></div>
1025 * @cat DOM/Attributes
1029 * Set the html contents of every matched element.
1030 * This property is not available on XML documents.
1032 * @example $("div").html("<b>new stuff</b>");
1033 * @before <div><input/></div>
1034 * @result <div><b>new stuff</b></div>
1038 * @param String val Set the html contents to the specified value.
1039 * @cat DOM/Attributes
1041 html: function( val ) {
1042 return val == undefined ?
\r ( this.length ? this[0].innerHTML : null ) :
\r this.empty().append( val );
1049 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1050 * @param Number dir If dir<0, process args in reverse order.
1051 * @param Function fn The function doing the DOM manipulation.
1055 domManip: function(args, table, dir, fn){
1056 var clone = this.length > 1;
1057 var a = jQuery.clean(args);
1061 return this.each(function(){
1064 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1065 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1067 for ( var i = 0, al = a.length; i < al; i++ )
1068 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1075 * Extends the jQuery object itself. Can be used to add functions into
1076 * the jQuery namespace and to add plugin methods (plugins).
1078 * @example jQuery.fn.extend({
1079 * check: function() {
1080 * return this.each(function() { this.checked = true; });
1082 * uncheck: function() {
1083 * return this.each(function() { this.checked = false; });
1086 * $("input[@type=checkbox]").check();
1087 * $("input[@type=radio]").uncheck();
1088 * @desc Adds two plugin methods.
1090 * @example jQuery.extend({
1091 * min: function(a, b) { return a < b ? a : b; },
1092 * max: function(a, b) { return a > b ? a : b; }
1094 * @desc Adds two functions into the jQuery namespace
1097 * @param Object prop The object that will be merged into the jQuery object
1103 * Extend one object with one or more others, returning the original,
1104 * modified, object. This is a great utility for simple inheritance.
1106 * @example var settings = { validate: false, limit: 5, name: "foo" };
1107 * var options = { validate: true, name: "bar" };
1108 * jQuery.extend(settings, options);
1109 * @result settings == { validate: true, limit: 5, name: "bar" }
1110 * @desc Merge settings and options, modifying settings
1112 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1113 * var options = { validate: true, name: "bar" };
1114 * var settings = jQuery.extend({}, defaults, options);
1115 * @result settings == { validate: true, limit: 5, name: "bar" }
1116 * @desc Merge defaults and options, without modifying the defaults
1119 * @param Object target The object to extend
1120 * @param Object prop1 The object that will be merged into the first.
1121 * @param Object propN (optional) More objects to merge into the first
1125 jQuery.extend = jQuery.fn.extend = function() {
1126 // copy reference to target object
1127 var target = arguments[0],
1130 // extend jQuery itself if only one argument is passed
1131 if ( arguments.length == 1 ) {
1136 while (prop = arguments[a++])
1137 // Extend the base object
1138 for ( var i in prop ) target[i] = prop[i];
1140 // Return the modified object
1146 * Run this function to give control of the $ variable back
1147 * to whichever library first implemented it. This helps to make
1148 * sure that jQuery doesn't conflict with the $ object
1149 * of other libraries.
1151 * By using this function, you will only be able to access jQuery
1152 * using the 'jQuery' variable. For example, where you used to do
1153 * $("div p"), you now must do jQuery("div p").
1155 * @example jQuery.noConflict();
1156 * // Do something with jQuery
1157 * jQuery("div p").hide();
1158 * // Do something with another library's $()
1159 * $("content").style.display = 'none';
1160 * @desc Maps the original object that was referenced by $ back to $
1162 * @example jQuery.noConflict();
1165 * // more code using $ as alias to jQuery
1168 * // other code using $ as an alias to the other library
1169 * @desc Reverts the $ alias and then creates and executes a
1170 * function to provide the $ as a jQuery alias inside the functions
1171 * scope. Inside the function the original $ object is not available.
1172 * This works well for most plugins that don't rely on any other library.
1175 * @name $.noConflict
1179 noConflict: function() {
1185 * A generic iterator function, which can be used to seemlessly
1186 * iterate over both objects and arrays. This function is not the same
1187 * as $().each() - which is used to iterate, exclusively, over a jQuery
1188 * object. This function can be used to iterate over anything.
1190 * The callback has two arguments:the key (objects) or index (arrays) as first
1191 * the first, and the value as the second.
1193 * @example $.each( [0,1,2], function(i, n){
1194 * alert( "Item #" + i + ": " + n );
1196 * @desc This is an example of iterating over the items in an array,
1197 * accessing both the current item and its index.
1199 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1200 * alert( "Name: " + i + ", Value: " + n );
1203 * @desc This is an example of iterating over the properties in an
1204 * Object, accessing both the current item and its key.
1207 * @param Object obj The object, or array, to iterate over.
1208 * @param Function fn The function that will be executed on every object.
1212 // args is for internal usage only
1213 each: function( obj, fn, args ) {
1214 if ( obj.length == undefined )
1215 for ( var i in obj )
1216 fn.apply( obj[i], args || [i, obj[i]] );
1218 for ( var i = 0, ol = obj.length; i < ol; i++ )
1219 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1223 prop: function(elem, key, value){
1224 // Handle executable functions
1225 return value.constructor == Function &&
1226 value.call( elem ) || value;
1230 add: function( elem, c ){
1231 jQuery.each( c.split(/\s+/), function(i, cur){
1232 if ( !jQuery.className.has( elem.className, cur ) )
1233 elem.className += ( elem.className ? " " : "" ) + cur;
1236 remove: function( elem, c ){
1237 elem.className = c ?
1238 jQuery.grep( elem.className.split(/\s+/), function(cur){
1239 return !jQuery.className.has( c, cur );
1242 has: function( classes, c ){
1243 return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
1248 * Swap in/out style options.
1251 swap: function(e,o,f) {
1252 for ( var i in o ) {
1253 e.style["old"+i] = e.style[i];
1258 e.style[i] = e.style["old"+i];
1261 css: function(e,p) {
1262 if ( p == "height" || p == "width" ) {
1263 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1265 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1266 old["padding" + d[i]] = 0;
1267 old["border" + d[i] + "Width"] = 0;
1270 jQuery.swap( e, old, function() {
1271 if (jQuery.css(e,"display") != "none") {
1272 oHeight = e.offsetHeight;
1273 oWidth = e.offsetWidth;
1275 e = jQuery(e.cloneNode(true))
1276 .find(":radio").removeAttr("checked").end()
1278 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1279 }).appendTo(e.parentNode)[0];
1281 var parPos = jQuery.css(e.parentNode,"position");
1282 if ( parPos == "" || parPos == "static" )
1283 e.parentNode.style.position = "relative";
1285 oHeight = e.clientHeight;
1286 oWidth = e.clientWidth;
1288 if ( parPos == "" || parPos == "static" )
1289 e.parentNode.style.position = "static";
1291 e.parentNode.removeChild(e);
1295 return p == "height" ? oHeight : oWidth;
1298 return jQuery.curCSS( e, p );
1301 curCSS: function(elem, prop, force) {
1304 if (prop == 'opacity' && jQuery.browser.msie)
1305 return jQuery.attr(elem.style, 'opacity');
1307 if (prop == "float" || prop == "cssFloat")
1308 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1310 if (!force && elem.style[prop])
1311 ret = elem.style[prop];
1313 else if (document.defaultView && document.defaultView.getComputedStyle) {
1315 if (prop == "cssFloat" || prop == "styleFloat")
1318 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1319 var cur = document.defaultView.getComputedStyle(elem, null);
1322 ret = cur.getPropertyValue(prop);
1323 else if ( prop == 'display' )
1326 jQuery.swap(elem, { display: 'block' }, function() {
1327 var c = document.defaultView.getComputedStyle(this, '');
1328 ret = c && c.getPropertyValue(prop) || '';
1331 } else if (elem.currentStyle) {
1333 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1334 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1341 clean: function(a) {
1344 for ( var i = 0, al = a.length; i < al; i++ ) {
1347 // Convert html string into DOM nodes
1348 if ( typeof arg == "string" ) {
1349 // Trim whitespace, otherwise indexOf won't work as expected
1350 var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
1353 // option or optgroup
1354 !s.indexOf("<opt") && [1, "<select>", "</select>"] ||
1356 !s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot") &&
1357 [1, "<table>", "</table>"] ||
1359 !s.indexOf("<tr") &&
1360 [2, "<table><tbody>", "</tbody></table>"] ||
1362 // <thead> matched above
1363 !s.indexOf("<td") || !s.indexOf("<th") &&
1364 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1368 // Go to html and back, then peel off extra wrappers
1369 div.innerHTML = wrap[1] + s + wrap[2];
1371 // Move to the right depth
1373 div = div.firstChild;
1375 // Remove IE's autoinserted <tbody> from table fragments
1376 if ( jQuery.browser.msie ) {
1378 // String was a <table>, *may* have spurious <tbody>
1379 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
1380 tb = div.firstChild && div.firstChild.childNodes;
1382 // String was a bare <thead> or <tfoot>
1383 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1384 tb = div.childNodes;
1386 for ( var n = tb.length-1; n >= 0 ; --n )
1387 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1388 tb[n].parentNode.removeChild(tb[n]);
1392 arg = div.childNodes;
1398 r = jQuery.merge( r, arg );
1404 attr: function(elem, name, value){
1407 "class": "className",
1408 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1409 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1410 innerHTML: "innerHTML",
1411 className: "className",
1413 disabled: "disabled",
1415 readonly: "readOnly",
1416 selected: "selected"
1419 // IE actually uses filters for opacity ... elem is actually elem.style
1420 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1421 // IE has trouble with opacity if it does not have layout
1422 // Force it by setting the zoom level
1425 // Set the alpha filter to set the opacity
1426 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1427 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1429 } else if ( name == "opacity" && jQuery.browser.msie )
1430 return elem.filter ?
1431 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1433 // Mozilla doesn't play well with opacity 1
1434 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1437 // Certain attributes only work when accessed via the old DOM 0 way
1439 if ( value != undefined ) elem[fix[name]] = value;
1440 return elem[fix[name]];
1442 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') )
1443 return elem.getAttributeNode(name).nodeValue;
1445 // IE elem.getAttribute passes even for style
1446 else if ( elem.tagName ) {
1447 if ( value != undefined ) elem.setAttribute( name, value );
1448 return elem.getAttribute( name );
1451 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1452 if ( value != undefined ) elem[name] = value;
1458 * Remove the whitespace from the beginning and end of a string.
1460 * @example $.trim(" hello, how are you? ");
1461 * @result "hello, how are you?"
1465 * @param String str The string to trim.
1469 return t.replace(/^\s+|\s+$/g, "");
1472 makeArray: function( a ) {
1475 if ( a.constructor != Array )
1476 for ( var i = 0, al = a.length; i < al; i++ )
1484 inArray: function( b, a ) {
1485 for ( var i = 0, al = a.length; i < al; i++ )
1492 * Merge two arrays together, removing all duplicates.
1494 * The new array is: All the results from the first array, followed
1495 * by the unique results from the second array.
1497 * @example $.merge( [0,1,2], [2,3,4] )
1498 * @result [0,1,2,3,4]
1499 * @desc Merges two arrays, removing the duplicate 2
1501 * @example $.merge( [3,2,1], [4,3,2] )
1503 * @desc Merges two arrays, removing the duplicates 3 and 2
1507 * @param Array first The first array to merge.
1508 * @param Array second The second array to merge.
1511 merge: function(first, second) {
1512 var r = [].slice.call( first, 0 );
1514 // Now check for duplicates between the two arrays
1515 // and only add the unique items
1516 for ( var i = 0, sl = second.length; i < sl; i++ )
1517 // Check for duplicates
1518 if ( jQuery.inArray( second[i], r ) == -1 )
1519 // The item is unique, add it
1520 first.push( second[i] );
1526 * Filter items out of an array, by using a filter function.
1528 * The specified function will be passed two arguments: The
1529 * current array item and the index of the item in the array. The
1530 * function must return 'true' to keep the item in the array,
1531 * false to remove it.
1533 * @example $.grep( [0,1,2], function(i){
1540 * @param Array array The Array to find items in.
1541 * @param Function fn The function to process each item against.
1542 * @param Boolean inv Invert the selection - select the opposite of the function.
1545 grep: function(elems, fn, inv) {
1546 // If a string is passed in for the function, make a function
1547 // for it (a handy shortcut)
1548 if ( typeof fn == "string" )
1549 fn = new Function("a","i","return " + fn);
1553 // Go through the array, only saving the items
1554 // that pass the validator function
1555 for ( var i = 0, el = elems.length; i < el; i++ )
1556 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1557 result.push( elems[i] );
1563 * Translate all items in an array to another array of items.
1565 * The translation function that is provided to this method is
1566 * called for each item in the array and is passed one argument:
1567 * The item to be translated.
1569 * The function can then return the translated value, 'null'
1570 * (to remove the item), or an array of values - which will
1571 * be flattened into the full array.
1573 * @example $.map( [0,1,2], function(i){
1577 * @desc Maps the original array to a new one and adds 4 to each value.
1579 * @example $.map( [0,1,2], function(i){
1580 * return i > 0 ? i + 1 : null;
1583 * @desc Maps the original array to a new one and adds 1 to each
1584 * value if it is bigger then zero, otherwise it's removed-
1586 * @example $.map( [0,1,2], function(i){
1587 * return [ i, i + 1 ];
1589 * @result [0, 1, 1, 2, 2, 3]
1590 * @desc Maps the original array to a new one, each element is added
1591 * with it's original value and the value plus one.
1595 * @param Array array The Array to translate.
1596 * @param Function fn The function to process each item against.
1599 map: function(elems, fn) {
1600 // If a string is passed in for the function, make a function
1601 // for it (a handy shortcut)
1602 if ( typeof fn == "string" )
1603 fn = new Function("a","return " + fn);
1605 var result = [], r = [];
1607 // Go through the array, translating each of the items to their
1608 // new value (or values).
1609 for ( var i = 0, el = elems.length; i < el; i++ ) {
1610 var val = fn(elems[i],i);
1612 if ( val !== null && val != undefined ) {
1613 if ( val.constructor != Array ) val = [val];
1614 result = result.concat( val );
1618 var r = result.length ? [ result[0] ] : [];
1620 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1621 for ( var j = 0; j < i; j++ )
1622 if ( result[i] == r[j] )
1625 r.push( result[i] );
1633 * Contains flags for the useragent, read from navigator.userAgent.
1634 * Available flags are: safari, opera, msie, mozilla
1636 * This property is available before the DOM is ready, therefore you can
1637 * use it to add ready events only for certain browsers.
1639 * There are situations where object detections is not reliable enough, in that
1640 * cases it makes sense to use browser detection. Simply try to avoid both!
1642 * A combination of browser and object detection yields quite reliable results.
1644 * @example $.browser.msie
1645 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1647 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1648 * @desc Alerts "this is safari!" only for safari browsers
1657 * Wheather the W3C compliant box model is being used.
1665 var b = navigator.userAgent.toLowerCase();
1667 // Figure out what browser is being used
1669 safari: /webkit/.test(b),
1670 opera: /opera/.test(b),
1671 msie: /msie/.test(b) && !/opera/.test(b),
1672 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1675 // Check to see if the W3C box model is being used
1676 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1680 * Get a set of elements containing the unique parents of the matched
1683 * Can be filtered with an optional expressions.
1685 * @example $("p").parent()
1686 * @before <div><p>Hello</p><p>Hello</p></div>
1687 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1688 * @desc Find the parent element of each paragraph.
1690 * @example $("p").parent(".selected")
1691 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1692 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1693 * @desc Find the parent element of each paragraph with a class "selected".
1697 * @param String expr (optional) An expression to filter the parents with
1698 * @cat DOM/Traversing
1702 * Get a set of elements containing the unique ancestors of the matched
1703 * set of elements (except for the root element).
1705 * Can be filtered with an optional expressions.
1707 * @example $("span").parents()
1708 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1709 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1710 * @desc Find all parent elements of each span.
1712 * @example $("span").parents("p")
1713 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1714 * @result [ <p><span>Hello</span></p> ]
1715 * @desc Find all parent elements of each span that is a paragraph.
1719 * @param String expr (optional) An expression to filter the ancestors with
1720 * @cat DOM/Traversing
1724 * Get a set of elements containing the unique next siblings of each of the
1725 * matched set of elements.
1727 * It only returns the very next sibling, not all next siblings.
1729 * Can be filtered with an optional expressions.
1731 * @example $("p").next()
1732 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1733 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1734 * @desc Find the very next sibling of each paragraph.
1736 * @example $("p").next(".selected")
1737 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1738 * @result [ <p class="selected">Hello Again</p> ]
1739 * @desc Find the very next sibling of each paragraph that has a class "selected".
1743 * @param String expr (optional) An expression to filter the next Elements with
1744 * @cat DOM/Traversing
1748 * Get a set of elements containing the unique previous siblings of each of the
1749 * matched set of elements.
1751 * Can be filtered with an optional expressions.
1753 * It only returns the immediately previous sibling, not all previous siblings.
1755 * @example $("p").prev()
1756 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1757 * @result [ <div><span>Hello Again</span></div> ]
1758 * @desc Find the very previous sibling of each paragraph.
1760 * @example $("p").prev(".selected")
1761 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1762 * @result [ <div><span>Hello</span></div> ]
1763 * @desc Find the very previous sibling of each paragraph that has a class "selected".
1767 * @param String expr (optional) An expression to filter the previous Elements with
1768 * @cat DOM/Traversing
1772 * Get a set of elements containing all of the unique siblings of each of the
1773 * matched set of elements.
1775 * Can be filtered with an optional expressions.
1777 * @example $("div").siblings()
1778 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1779 * @result [ <p>Hello</p>, <p>And Again</p> ]
1780 * @desc Find all siblings of each div.
1782 * @example $("div").siblings(".selected")
1783 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1784 * @result [ <p class="selected">Hello Again</p> ]
1785 * @desc Find all siblings with a class "selected" of each div.
1789 * @param String expr (optional) An expression to filter the sibling Elements with
1790 * @cat DOM/Traversing
1794 * Get a set of elements containing all of the unique children of each of the
1795 * matched set of elements.
1797 * Can be filtered with an optional expressions.
1799 * @example $("div").children()
1800 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1801 * @result [ <span>Hello Again</span> ]
1802 * @desc Find all children of each div.
1804 * @example $("div").children(".selected")
1805 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1806 * @result [ <p class="selected">Hello Again</p> ]
1807 * @desc Find all children with a class "selected" of each div.
1811 * @param String expr (optional) An expression to filter the child Elements with
1812 * @cat DOM/Traversing
1815 parent: "a.parentNode",
1816 parents: jQuery.parents,
1817 next: "jQuery.nth(a,1,'nextSibling')",
1818 prev: "jQuery.nth(a,1,'previousSibling')",
1819 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1820 children: "jQuery.sibling(a.firstChild)"
1822 jQuery.fn[ i ] = function(a) {
1823 var ret = jQuery.map(this,n);
1824 if ( a && typeof a == "string" )
1825 ret = jQuery.filter(a,ret).r;
1826 return this.set( ret );
1831 * Append all of the matched elements to another, specified, set of elements.
1832 * This operation is, essentially, the reverse of doing a regular
1833 * $(A).append(B), in that instead of appending B to A, you're appending
1836 * @example $("p").appendTo("#foo");
1837 * @before <p>I would like to say: </p><div id="foo"></div>
1838 * @result <div id="foo"><p>I would like to say: </p></div>
1839 * @desc Appends all paragraphs to the element with the ID "foo"
1843 * @param String expr A jQuery expression of elements to match.
1844 * @cat DOM/Manipulation
1848 * Prepend all of the matched elements to another, specified, set of elements.
1849 * This operation is, essentially, the reverse of doing a regular
1850 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1853 * @example $("p").prependTo("#foo");
1854 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1855 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1856 * @desc Prepends all paragraphs to the element with the ID "foo"
1860 * @param String expr A jQuery expression of elements to match.
1861 * @cat DOM/Manipulation
1865 * Insert all of the matched elements before another, specified, set of elements.
1866 * This operation is, essentially, the reverse of doing a regular
1867 * $(A).before(B), in that instead of inserting B before A, you're inserting
1870 * @example $("p").insertBefore("#foo");
1871 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1872 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1873 * @desc Same as $("#foo").before("p")
1875 * @name insertBefore
1877 * @param String expr A jQuery expression of elements to match.
1878 * @cat DOM/Manipulation
1882 * Insert all of the matched elements after another, specified, set of elements.
1883 * This operation is, essentially, the reverse of doing a regular
1884 * $(A).after(B), in that instead of inserting B after A, you're inserting
1887 * @example $("p").insertAfter("#foo");
1888 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1889 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1890 * @desc Same as $("#foo").after("p")
1894 * @param String expr A jQuery expression of elements to match.
1895 * @cat DOM/Manipulation
1900 prependTo: "prepend",
1901 insertBefore: "before",
1902 insertAfter: "after"
1904 jQuery.fn[ i ] = function(){
1906 return this.each(function(){
1907 for ( var j = 0, al = a.length; j < al; j++ )
1908 jQuery(a[j])[n]( this );
1914 * Remove an attribute from each of the matched elements.
1916 * @example $("input").removeAttr("disabled")
1917 * @before <input disabled="disabled"/>
1922 * @param String name The name of the attribute to remove.
1923 * @cat DOM/Attributes
1927 * Displays each of the set of matched elements if they are hidden.
1929 * @example $("p").show()
1930 * @before <p style="display: none">Hello</p>
1931 * @result [ <p style="display: block">Hello</p> ]
1939 * Hides each of the set of matched elements if they are shown.
1941 * @example $("p").hide()
1942 * @before <p>Hello</p>
1943 * @result [ <p style="display: none">Hello</p> ]
1945 * var pass = true, div = $("div");
1946 * div.hide().each(function(){
1947 * if ( this.style.display != "none" ) pass = false;
1949 * ok( pass, "Hide" );
1957 * Toggles each of the set of matched elements. If they are shown,
1958 * toggle makes them hidden. If they are hidden, toggle
1961 * @example $("p").toggle()
1962 * @before <p>Hello</p><p style="display: none">Hello Again</p>
1963 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
1971 * Adds the specified class to each of the set of matched elements.
1973 * @example $("p").addClass("selected")
1974 * @before <p>Hello</p>
1975 * @result [ <p class="selected">Hello</p> ]
1979 * @param String class A CSS class to add to the elements
1980 * @cat DOM/Attributes
1981 * @see removeClass(String)
1985 * Removes all or the specified class from the set of matched elements.
1987 * @example $("p").removeClass()
1988 * @before <p class="selected">Hello</p>
1989 * @result [ <p>Hello</p> ]
1991 * @example $("p").removeClass("selected")
1992 * @before <p class="selected first">Hello</p>
1993 * @result [ <p class="first">Hello</p> ]
1997 * @param String class (optional) A CSS class to remove from the elements
1998 * @cat DOM/Attributes
1999 * @see addClass(String)
2003 * Adds the specified class if it is not present, removes it if it is
2006 * @example $("p").toggleClass("selected")
2007 * @before <p>Hello</p><p class="selected">Hello Again</p>
2008 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2012 * @param String class A CSS class with which to toggle the elements
2013 * @cat DOM/Attributes
2017 * Removes all matched elements from the DOM. This does NOT remove them from the
2018 * jQuery object, allowing you to use the matched elements further.
2020 * Can be filtered with an optional expressions.
2022 * @example $("p").remove();
2023 * @before <p>Hello</p> how are <p>you?</p>
2026 * @example $("p").remove(".hello");
2027 * @before <p class="hello">Hello</p> how are <p>you?</p>
2028 * @result how are <p>you?</p>
2032 * @param String expr (optional) A jQuery expression to filter elements by.
2033 * @cat DOM/Manipulation
2037 * Removes all child nodes from the set of matched elements.
2039 * @example $("p").empty()
2040 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2041 * @result [ <p></p> ]
2045 * @cat DOM/Manipulation
2049 removeAttr: function( key ) {
2050 jQuery.attr( this, key, "" );
2051 this.removeAttribute( key );
2054 this.style.display = this.oldblock ? this.oldblock : "";
2055 if ( jQuery.css(this,"display") == "none" )
2056 this.style.display = "block";
2059 this.oldblock = this.oldblock || jQuery.css(this,"display");
2060 if ( this.oldblock == "none" )
2061 this.oldblock = "block";
2062 this.style.display = "none";
2065 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2067 addClass: function(c){
2068 jQuery.className.add(this,c);
2070 removeClass: function(c){
2071 jQuery.className.remove(this,c);
2073 toggleClass: function( c ){
2074 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2076 remove: function(a){
2077 if ( !a || jQuery.filter( a, [this] ).r )
2078 this.parentNode.removeChild( this );
2081 while ( this.firstChild )
2082 this.removeChild( this.firstChild );
2085 jQuery.fn[ i ] = function() {
2086 return this.each( n, arguments );
2091 * Reduce the set of matched elements to a single element.
2092 * The position of the element in the set of matched elements
2093 * starts at 0 and goes to length - 1.
2095 * @example $("p").eq(1)
2096 * @before <p>This is just a test.</p><p>So is this</p>
2097 * @result [ <p>So is this</p> ]
2101 * @param Number pos The index of the element that you wish to limit to.
2106 * Reduce the set of matched elements to all elements before a given position.
2107 * The position of the element in the set of matched elements
2108 * starts at 0 and goes to length - 1.
2110 * @example $("p").lt(1)
2111 * @before <p>This is just a test.</p><p>So is this</p>
2112 * @result [ <p>This is just a test.</p> ]
2116 * @param Number pos Reduce the set to all elements below this position.
2121 * Reduce the set of matched elements to all elements after a given position.
2122 * The position of the element in the set of matched elements
2123 * starts at 0 and goes to length - 1.
2125 * @example $("p").gt(0)
2126 * @before <p>This is just a test.</p><p>So is this</p>
2127 * @result [ <p>So is this</p> ]
2131 * @param Number pos Reduce the set to all elements after this position.
2136 * Filter the set of elements to those that contain the specified text.
2138 * @example $("p").contains("test")
2139 * @before <p>This is just a test.</p><p>So is this</p>
2140 * @result [ <p>This is just a test.</p> ]
2144 * @param String str The string that will be contained within the text of an element.
2145 * @cat DOM/Traversing
2147 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2148 jQuery.fn[ n ] = function(num,fn) {
2149 return this.filter( ":" + n + "(" + num + ")", fn );