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.
163 jQuery.fn = jQuery.prototype = {
165 * The current version of jQuery.
176 * The number of elements currently matched.
178 * @example $("img").length;
179 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
189 * The number of elements currently matched.
191 * @example $("img").size();
192 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
206 * Access all matched elements. This serves as a backwards-compatible
207 * way of accessing all matched elements (other than the jQuery object
208 * itself, which is, in fact, an array of elements).
210 * @example $("img").get();
211 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
212 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
213 * @desc Selects all images in the document and returns the DOM Elements as an Array
216 * @type Array<Element>
221 * Access a single matched element. num is used to access the
222 * Nth element matched.
224 * @example $("img").get(0);
225 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
226 * @result [ <img src="test1.jpg"/> ]
227 * @desc Selects all images in the document and returns the first one
231 * @param Number num Access the element in the Nth position.
234 get: function( num ) {
235 return num == undefined ?
237 // Return a 'clean' array
238 jQuery.makeArray( this ) :
240 // Return just the object
245 * Set the jQuery object to an array of elements, while maintaining
248 * @example $("img").pushStack([ document.body ]);
249 * @result $("img").pushStack() == [ document.body ]
254 * @param Elements elems An array of elements
257 pushStack: function( a ) {
258 var ret = jQuery(this);
259 ret.prevObject = this;
260 return ret.setArray( a );
264 * Set the jQuery object to an array of elements. This operation is
265 * completely destructive - be sure to use .pushStack() if you wish to maintain
268 * @example $("img").setArray([ document.body ]);
269 * @result $("img").setArray() == [ document.body ]
274 * @param Elements elems An array of elements
277 setArray: function( a ) {
279 [].push.apply( this, a );
284 * Execute a function within the context of every matched element.
285 * This means that every time the passed-in function is executed
286 * (which is once for every element matched) the 'this' keyword
287 * points to the specific element.
289 * Additionally, the function, when executed, is passed a single
290 * argument representing the position of the element in the matched
293 * @example $("img").each(function(i){
294 * this.src = "test" + i + ".jpg";
296 * @before <img/><img/>
297 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
298 * @desc Iterates over two images and sets their src property
302 * @param Function fn A function to execute
305 each: function( fn, args ) {
306 return jQuery.each( this, fn, args );
310 * Searches every matched element for the object and returns
311 * the index of the element, if found, starting with zero.
312 * Returns -1 if the object wasn't found.
314 * @example $("*").index( $('#foobar')[0] )
315 * @before <div id="foobar"></div><b></b><span id="foo"></span>
317 * @desc Returns the index for the element with ID foobar
319 * @example $("*").index( $('#foo'))
320 * @before <div id="foobar"></div><b></b><span id="foo"></span>
322 * @desc Returns the index for the element with ID foo
324 * @example $("*").index( $('#bar'))
325 * @before <div id="foobar"></div><b></b><span id="foo"></span>
327 * @desc Returns -1, as there is no element with ID bar
331 * @param Element subject Object to search for
334 index: function( obj ) {
336 this.each(function(i){
337 if ( this == obj ) pos = i;
343 * Access a property on the first matched element.
344 * This method makes it easy to retrieve a property value
345 * from the first matched element.
347 * @example $("img").attr("src");
348 * @before <img src="test.jpg"/>
350 * @desc Returns the src attribute from the first image in the document.
354 * @param String name The name of the property to access.
355 * @cat DOM/Attributes
359 * Set a key/value object as properties to all matched elements.
361 * This serves as the best way to set a large number of properties
362 * on all matched elements.
364 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
366 * @result <img src="test.jpg" alt="Test Image"/>
367 * @desc Sets src and alt attributes to all images.
371 * @param Map properties Key/value pairs to set as object properties.
372 * @cat DOM/Attributes
376 * Set a single property to a value, on all matched elements.
378 * Can compute values provided as ${formula}, see second example.
380 * Note that you can't set the name property of input elements in IE.
381 * Use $(html) or .append(html) or .html(html) to create elements
382 * on the fly including the name property.
384 * @example $("img").attr("src","test.jpg");
386 * @result <img src="test.jpg"/>
387 * @desc Sets src attribute to all images.
389 * @example $("img").attr("title", "${this.src}");
390 * @before <img src="test.jpg" />
391 * @result <img src="test.jpg" title="test.jpg" />
392 * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
396 * @param String key The name of the property to set.
397 * @param Object value The value to set the property to.
398 * @cat DOM/Attributes
402 * Set a single property to a computed value, on all matched elements.
404 * Instead of a value, a function is provided, that computes the value.
406 * @example $("img").attr("title", function() { return this.src });
407 * @before <img src="test.jpg" />
408 * @result <img src="test.jpg" title="test.jpg" />
409 * @desc Sets title attribute from src attribute.
413 * @param String key The name of the property to set.
414 * @param Function value A function returning the value to set.
415 * @cat DOM/Attributes
417 attr: function( key, value, type ) {
420 // Look for the case where we're accessing a style value
421 if ( key.constructor == String )
422 if ( value == undefined )
423 return jQuery[ type || "attr" ]( this[0], key );
429 // Check to see if we're setting style values
430 return this.each(function(){
431 // Set all the styles
432 for ( var prop in obj )
434 type ? this.style : this,
435 prop, jQuery.prop(this, obj[prop])
441 * Access a style property on the first matched element.
442 * This method makes it easy to retrieve a style property value
443 * from the first matched element.
445 * @example $("p").css("color");
446 * @before <p style="color:red;">Test Paragraph.</p>
448 * @desc Retrieves the color style of the first paragraph
450 * @example $("p").css("font-weight");
451 * @before <p style="font-weight: bold;">Test Paragraph.</p>
453 * @desc Retrieves the font-weight style of the first paragraph.
457 * @param String name The name of the property to access.
462 * Set a key/value object as style properties to all matched elements.
464 * This serves as the best way to set a large number of style properties
465 * on all matched elements.
467 * @example $("p").css({ color: "red", background: "blue" });
468 * @before <p>Test Paragraph.</p>
469 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
470 * @desc Sets color and background styles to all p elements.
474 * @param Map properties Key/value pairs to set as style properties.
479 * Set a single style property to a value, on all matched elements.
481 * @example $("p").css("color","red");
482 * @before <p>Test Paragraph.</p>
483 * @result <p style="color:red;">Test Paragraph.</p>
484 * @desc Changes the color of all paragraphs to red
488 * @param String key The name of the property to set.
489 * @param Object value The value to set the property to.
492 css: function( key, value ) {
493 return this.attr( key, value, "curCSS" );
497 * Get the text contents of all matched elements. The result is
498 * a string that contains the combined text contents of all matched
499 * elements. This method works on both HTML and XML documents.
501 * @example $("p").text();
502 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
503 * @result Test Paragraph.Paraparagraph
504 * @desc Gets the concatenated text of all paragraphs
508 * @cat DOM/Attributes
512 * Set the text contents of all matched elements.
514 * Similar to html(), but escapes HTML (replace "<" and ">" with their
517 * @example $("p").text("<b>Some</b> new text.");
518 * @before <p>Test Paragraph.</p>
519 * @result <p><b>Some</b> new text.</p>
520 * @desc Sets the text of all paragraphs.
522 * @example $("p").text("<b>Some</b> new text.", true);
523 * @before <p>Test Paragraph.</p>
524 * @result <p>Some new text.</p>
525 * @desc Sets the text of all paragraphs.
529 * @param String val The text value to set the contents of the element to.
530 * @cat DOM/Attributes
533 var type = this.length && this[0].innerText == undefined ?
534 "textContent" : "innerText";
536 return e == undefined ?
537 this.length && this[0][ type ] :
538 this.each(function(){ this[ type ] = e; });
542 * Wrap all matched elements with a structure of other elements.
543 * This wrapping process is most useful for injecting additional
544 * stucture into a document, without ruining the original semantic
545 * qualities of a document.
547 * This works by going through the first element
548 * provided (which is generated, on the fly, from the provided HTML)
549 * and finds the deepest ancestor element within its
550 * structure - it is that element that will en-wrap everything else.
552 * This does not work with elements that contain text. Any necessary text
553 * must be added after the wrapping is done.
555 * @example $("p").wrap("<div class='wrap'></div>");
556 * @before <p>Test Paragraph.</p>
557 * @result <div class='wrap'><p>Test Paragraph.</p></div>
561 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
562 * @cat DOM/Manipulation
566 * Wrap all matched elements with a structure of other elements.
567 * This wrapping process is most useful for injecting additional
568 * stucture into a document, without ruining the original semantic
569 * qualities of a document.
571 * This works by going through the first element
572 * provided and finding the deepest ancestor element within its
573 * structure - it is that element that will en-wrap everything else.
575 * This does not work with elements that contain text. Any necessary text
576 * must be added after the wrapping is done.
578 * @example $("p").wrap( document.getElementById('content') );
579 * @before <p>Test Paragraph.</p><div id="content"></div>
580 * @result <div id="content"><p>Test Paragraph.</p></div>
584 * @param Element elem A DOM element that will be wrapped around the target.
585 * @cat DOM/Manipulation
588 // The elements to wrap the target around
589 var a = jQuery.clean(arguments);
591 // Wrap each of the matched elements individually
592 return this.each(function(){
593 // Clone the structure that we're using to wrap
594 var b = a[0].cloneNode(true);
596 // Insert it before the element to be wrapped
597 this.parentNode.insertBefore( b, this );
599 // Find the deepest point in the wrap structure
600 while ( b.firstChild )
603 // Move the matched element to within the wrap structure
604 b.appendChild( this );
609 * Append content to the inside of every matched element.
611 * This operation is similar to doing an appendChild to all the
612 * specified elements, adding them into the document.
614 * @example $("p").append("<b>Hello</b>");
615 * @before <p>I would like to say: </p>
616 * @result <p>I would like to say: <b>Hello</b></p>
617 * @desc Appends some HTML to all paragraphs.
619 * @example $("p").append( $("#foo")[0] );
620 * @before <p>I would like to say: </p><b id="foo">Hello</b>
621 * @result <p>I would like to say: <b id="foo">Hello</b></p>
622 * @desc Appends an Element to all paragraphs.
624 * @example $("p").append( $("b") );
625 * @before <p>I would like to say: </p><b>Hello</b>
626 * @result <p>I would like to say: <b>Hello</b></p>
627 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
631 * @param <Content> content Content to append to the target
632 * @cat DOM/Manipulation
633 * @see prepend(<Content>)
634 * @see before(<Content>)
635 * @see after(<Content>)
638 return this.domManip(arguments, true, 1, function(a){
639 this.appendChild( a );
644 * Prepend content to the inside of every matched element.
646 * This operation is the best way to insert elements
647 * inside, at the beginning, of all matched elements.
649 * @example $("p").prepend("<b>Hello</b>");
650 * @before <p>I would like to say: </p>
651 * @result <p><b>Hello</b>I would like to say: </p>
652 * @desc Prepends some HTML to all paragraphs.
654 * @example $("p").prepend( $("#foo")[0] );
655 * @before <p>I would like to say: </p><b id="foo">Hello</b>
656 * @result <p><b id="foo">Hello</b>I would like to say: </p>
657 * @desc Prepends an Element to all paragraphs.
659 * @example $("p").prepend( $("b") );
660 * @before <p>I would like to say: </p><b>Hello</b>
661 * @result <p><b>Hello</b>I would like to say: </p>
662 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
666 * @param <Content> content Content to prepend to the target.
667 * @cat DOM/Manipulation
668 * @see append(<Content>)
669 * @see before(<Content>)
670 * @see after(<Content>)
672 prepend: function() {
673 return this.domManip(arguments, true, -1, function(a){
674 this.insertBefore( a, this.firstChild );
679 * Insert content before each of the matched elements.
681 * @example $("p").before("<b>Hello</b>");
682 * @before <p>I would like to say: </p>
683 * @result <b>Hello</b><p>I would like to say: </p>
684 * @desc Inserts some HTML before all paragraphs.
686 * @example $("p").before( $("#foo")[0] );
687 * @before <p>I would like to say: </p><b id="foo">Hello</b>
688 * @result <b id="foo">Hello</b><p>I would like to say: </p>
689 * @desc Inserts an Element before all paragraphs.
691 * @example $("p").before( $("b") );
692 * @before <p>I would like to say: </p><b>Hello</b>
693 * @result <b>Hello</b><p>I would like to say: </p>
694 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
698 * @param <Content> content Content to insert before each target.
699 * @cat DOM/Manipulation
700 * @see append(<Content>)
701 * @see prepend(<Content>)
702 * @see after(<Content>)
705 return this.domManip(arguments, false, 1, function(a){
706 this.parentNode.insertBefore( a, this );
711 * Insert content after each of the matched elements.
713 * @example $("p").after("<b>Hello</b>");
714 * @before <p>I would like to say: </p>
715 * @result <p>I would like to say: </p><b>Hello</b>
716 * @desc Inserts some HTML after all paragraphs.
718 * @example $("p").after( $("#foo")[0] );
719 * @before <b id="foo">Hello</b><p>I would like to say: </p>
720 * @result <p>I would like to say: </p><b id="foo">Hello</b>
721 * @desc Inserts an Element after all paragraphs.
723 * @example $("p").after( $("b") );
724 * @before <b>Hello</b><p>I would like to say: </p>
725 * @result <p>I would like to say: </p><b>Hello</b>
726 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
730 * @param <Content> content Content to insert after each target.
731 * @cat DOM/Manipulation
732 * @see append(<Content>)
733 * @see prepend(<Content>)
734 * @see before(<Content>)
737 return this.domManip(arguments, false, -1, function(a){
738 this.parentNode.insertBefore( a, this.nextSibling );
743 * End the most recent 'destructive' operation, reverting the list of matched elements
744 * back to its previous state. After an end operation, the list of matched elements will
745 * revert to the last state of matched elements.
747 * If there was no destructive operation before, an empty set is returned.
749 * @example $("p").find("span").end();
750 * @before <p><span>Hello</span>, how are you?</p>
751 * @result [ <p>...</p> ]
752 * @desc Selects all paragraphs, finds span elements inside these, and reverts the
753 * selection back to the paragraphs.
757 * @cat DOM/Traversing
760 return this.prevObject || jQuery([]);
764 * Searches for all elements that match the specified expression.
766 * This method is a good way to find additional descendant
767 * elements with which to process.
769 * All searching is done using a jQuery expression. The expression can be
770 * written using CSS 1-3 Selector syntax, or basic XPath.
772 * @example $("p").find("span");
773 * @before <p><span>Hello</span>, how are you?</p>
774 * @result [ <span>Hello</span> ]
775 * @desc Starts with all paragraphs and searches for descendant span
776 * elements, same as $("p span")
780 * @param String expr An expression to search with.
781 * @cat DOM/Traversing
784 return this.pushStack( jQuery.map( this, function(a){
785 return jQuery.find(t,a);
790 * Clone matched DOM Elements and select the clones.
792 * This is useful for moving copies of the elements to another
793 * location in the DOM.
795 * @example $("b").clone().prependTo("p");
796 * @before <b>Hello</b><p>, how are you?</p>
797 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
798 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
802 * @cat DOM/Manipulation
804 clone: function(deep) {
805 return this.pushStack( jQuery.map( this, function(a){
806 return a.cloneNode( deep != undefined ? deep : true );
811 * Removes all elements from the set of matched elements that do not
812 * match the specified expression(s). This method is used to narrow down
813 * the results of a search.
815 * Provide a String array of expressions to apply multiple filters at once.
817 * @example $("p").filter(".selected")
818 * @before <p class="selected">Hello</p><p>How are you?</p>
819 * @result [ <p class="selected">Hello</p> ]
820 * @desc Selects all paragraphs and removes those without a class "selected".
822 * @example $("p").filter([".selected", ":first"])
823 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
824 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
825 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
829 * @param String|Array<String> expression Expression(s) to search with.
830 * @cat DOM/Traversing
834 * Removes all elements from the set of matched elements that do not
835 * pass the specified filter. This method is used to narrow down
836 * the results of a search.
838 * @example $("p").filter(function(index) {
839 * return $("ol", this).length == 0;
841 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
842 * @result [ <p>How are you?</p> ]
843 * @desc Remove all elements that have a child ol element
847 * @param Function filter A function to use for filtering
848 * @cat DOM/Traversing
850 filter: function(t) {
851 return this.pushStack(
852 t.constructor == Array &&
853 jQuery.map(this,function(a){
854 for ( var i = 0, tl = t.length; i < tl; i++ )
855 if ( jQuery.filter(t[i],[a]).r.length )
860 t.constructor == Boolean &&
861 ( t ? this.get() : [] ) ||
863 typeof t == "function" &&
864 jQuery.grep( this, function(el, index) { return t.apply(el, [index]) }) ||
866 jQuery.filter(t,this).r );
870 * Removes the specified Element from the set of matched elements. This
871 * method is used to remove a single Element from a jQuery object.
873 * @example $("p").not( $("#selected")[0] )
874 * @before <p>Hello</p><p id="selected">Hello Again</p>
875 * @result [ <p>Hello</p> ]
876 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
880 * @param Element el An element to remove from the set
881 * @cat DOM/Traversing
885 * Removes elements matching the specified expression from the set
886 * of matched elements. This method is used to remove one or more
887 * elements from a jQuery object.
889 * @example $("p").not("#selected")
890 * @before <p>Hello</p><p id="selected">Hello Again</p>
891 * @result [ <p>Hello</p> ]
892 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
896 * @param String expr An expression with which to remove matching elements
897 * @cat DOM/Traversing
900 return this.pushStack( typeof t == "string" ?
901 jQuery.filter(t,this,true).r :
902 jQuery.grep(this,function(a){ return a != t; }) );
906 * Adds the elements matched by the expression to the jQuery object. This
907 * can be used to concatenate the result sets of two expressions.
909 * @example $("p").add("span")
910 * @before <p>Hello</p><p><span>Hello Again</span></p>
911 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
915 * @param String expr An expression whose matched elements are added
916 * @cat DOM/Traversing
920 * Adds the on the fly created elements to the jQuery object.
922 * @example $("p").add("<span>Again</span>")
923 * @before <p>Hello</p>
924 * @result [ <p>Hello</p>, <span>Again</span> ]
928 * @param String html A string of HTML to create on the fly.
929 * @cat DOM/Traversing
933 * Adds one or more Elements to the set of matched elements.
935 * This is used to add a set of Elements to a jQuery object.
937 * @example $("p").add( document.getElementById("a") )
938 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
939 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
941 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
942 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
943 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
947 * @param Element|Array<Element> elements One or more Elements to add
948 * @cat DOM/Traversing
951 return this.pushStack( jQuery.merge(
953 typeof t == "string" ? jQuery(t).get() : t )
958 * Checks the current selection against an expression and returns true,
959 * if at least one element of the selection fits the given expression.
961 * Does return false, if no element fits or the expression is not valid.
963 * filter(String) is used internally, therefore all rules that apply there
966 * @example $("input[@type='checkbox']").parent().is("form")
967 * @before <form><input type="checkbox" /></form>
969 * @desc Returns true, because the parent of the input is a form element
971 * @example $("input[@type='checkbox']").parent().is("form")
972 * @before <form><p><input type="checkbox" /></p></form>
974 * @desc Returns false, because the parent of the input is a p element
978 * @param String expr The expression with which to filter
979 * @cat DOM/Traversing
982 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
986 * Get the current value of the first matched element.
988 * @example $("input").val();
989 * @before <input type="text" value="some text"/>
990 * @result "some text"
994 * @cat DOM/Attributes
998 * Set the value of every matched element.
1000 * @example $("input").val("test");
1001 * @before <input type="text" value="some text"/>
1002 * @result <input type="text" value="test"/>
1006 * @param String val Set the property to the specified value.
1007 * @cat DOM/Attributes
1009 val: function( val ) {
1010 return val == undefined ?
\r ( this.length ? this[0].value : null ) :
\r this.attr( "value", val );
1014 * Get the html contents of the first matched element.
1015 * This property is not available on XML documents.
1017 * @example $("div").html();
1018 * @before <div><input/></div>
1023 * @cat DOM/Attributes
1027 * Set the html contents of every matched element.
1028 * This property is not available on XML documents.
1030 * @example $("div").html("<b>new stuff</b>");
1031 * @before <div><input/></div>
1032 * @result <div><b>new stuff</b></div>
1036 * @param String val Set the html contents to the specified value.
1037 * @cat DOM/Attributes
1039 html: function( val ) {
1040 return val == undefined ?
\r ( this.length ? this[0].innerHTML : null ) :
\r this.empty().append( val );
1047 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1048 * @param Number dir If dir<0, process args in reverse order.
1049 * @param Function fn The function doing the DOM manipulation.
1053 domManip: function(args, table, dir, fn){
1054 var clone = this.length > 1;
1055 var a = jQuery.clean(args);
1059 return this.each(function(){
1062 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1063 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1065 for ( var i = 0, al = a.length; i < al; i++ )
1066 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1073 * Extends the jQuery object itself. Can be used to add functions into
1074 * the jQuery namespace and to add plugin methods (plugins).
1076 * @example jQuery.fn.extend({
1077 * check: function() {
1078 * return this.each(function() { this.checked = true; });
1080 * uncheck: function() {
1081 * return this.each(function() { this.checked = false; });
1084 * $("input[@type=checkbox]").check();
1085 * $("input[@type=radio]").uncheck();
1086 * @desc Adds two plugin methods.
1088 * @example jQuery.extend({
1089 * min: function(a, b) { return a < b ? a : b; },
1090 * max: function(a, b) { return a > b ? a : b; }
1092 * @desc Adds two functions into the jQuery namespace
1095 * @param Object prop The object that will be merged into the jQuery object
1101 * Extend one object with one or more others, returning the original,
1102 * modified, object. This is a great utility for simple inheritance.
1104 * @example var settings = { validate: false, limit: 5, name: "foo" };
1105 * var options = { validate: true, name: "bar" };
1106 * jQuery.extend(settings, options);
1107 * @result settings == { validate: true, limit: 5, name: "bar" }
1108 * @desc Merge settings and options, modifying settings
1110 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1111 * var options = { validate: true, name: "bar" };
1112 * var settings = jQuery.extend({}, defaults, options);
1113 * @result settings == { validate: true, limit: 5, name: "bar" }
1114 * @desc Merge defaults and options, without modifying the defaults
1117 * @param Object target The object to extend
1118 * @param Object prop1 The object that will be merged into the first.
1119 * @param Object propN (optional) More objects to merge into the first
1123 jQuery.extend = jQuery.fn.extend = function() {
1124 // copy reference to target object
1125 var target = arguments[0],
1128 // extend jQuery itself if only one argument is passed
1129 if ( arguments.length == 1 ) {
1134 while (prop = arguments[a++])
1135 // Extend the base object
1136 for ( var i in prop ) target[i] = prop[i];
1138 // Return the modified object
1144 * Run this function to give control of the $ variable back
1145 * to whichever library first implemented it. This helps to make
1146 * sure that jQuery doesn't conflict with the $ object
1147 * of other libraries.
1149 * By using this function, you will only be able to access jQuery
1150 * using the 'jQuery' variable. For example, where you used to do
1151 * $("div p"), you now must do jQuery("div p").
1153 * @example jQuery.noConflict();
1154 * // Do something with jQuery
1155 * jQuery("div p").hide();
1156 * // Do something with another library's $()
1157 * $("content").style.display = 'none';
1158 * @desc Maps the original object that was referenced by $ back to $
1160 * @example jQuery.noConflict();
1163 * // more code using $ as alias to jQuery
1166 * // other code using $ as an alias to the other library
1167 * @desc Reverts the $ alias and then creates and executes a
1168 * function to provide the $ as a jQuery alias inside the functions
1169 * scope. Inside the function the original $ object is not available.
1170 * This works well for most plugins that don't rely on any other library.
1173 * @name $.noConflict
1177 noConflict: function() {
1183 * A generic iterator function, which can be used to seemlessly
1184 * iterate over both objects and arrays. This function is not the same
1185 * as $().each() - which is used to iterate, exclusively, over a jQuery
1186 * object. This function can be used to iterate over anything.
1188 * The callback has two arguments:the key (objects) or index (arrays) as first
1189 * the first, and the value as the second.
1191 * @example $.each( [0,1,2], function(i, n){
1192 * alert( "Item #" + i + ": " + n );
1194 * @desc This is an example of iterating over the items in an array,
1195 * accessing both the current item and its index.
1197 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1198 * alert( "Name: " + i + ", Value: " + n );
1201 * @desc This is an example of iterating over the properties in an
1202 * Object, accessing both the current item and its key.
1205 * @param Object obj The object, or array, to iterate over.
1206 * @param Function fn The function that will be executed on every object.
1210 // args is for internal usage only
1211 each: function( obj, fn, args ) {
1212 if ( obj.length == undefined )
1213 for ( var i in obj )
1214 fn.apply( obj[i], args || [i, obj[i]] );
1216 for ( var i = 0, ol = obj.length; i < ol; i++ )
1217 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1221 prop: function(elem, value){
1222 // Handle executable functions
1223 return value.constructor == Function &&
1224 value.call( elem ) || value;
1228 // internal only, use addClass("class")
1229 add: function( elem, c ){
1230 jQuery.each( c.split(/\s+/), function(i, cur){
1231 if ( !jQuery.className.has( elem.className, cur ) )
1232 elem.className += ( elem.className ? " " : "" ) + cur;
1236 // internal only, use removeClass("class")
1237 remove: function( elem, c ){
1238 elem.className = c ?
1239 jQuery.grep( elem.className.split(/\s+/), function(cur){
1240 return !jQuery.className.has( c, cur );
1244 // internal only, use is(".class")
1245 has: function( t, c ) {
1246 t = t.className || t;
1247 return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
1252 * Swap in/out style options.
1255 swap: function(e,o,f) {
1256 for ( var i in o ) {
1257 e.style["old"+i] = e.style[i];
1262 e.style[i] = e.style["old"+i];
1265 css: function(e,p) {
1266 if ( p == "height" || p == "width" ) {
1267 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1269 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1270 old["padding" + d[i]] = 0;
1271 old["border" + d[i] + "Width"] = 0;
1274 jQuery.swap( e, old, function() {
1275 if (jQuery.css(e,"display") != "none") {
1276 oHeight = e.offsetHeight;
1277 oWidth = e.offsetWidth;
1279 e = jQuery(e.cloneNode(true))
1280 .find(":radio").removeAttr("checked").end()
1282 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1283 }).appendTo(e.parentNode)[0];
1285 var parPos = jQuery.css(e.parentNode,"position");
1286 if ( parPos == "" || parPos == "static" )
1287 e.parentNode.style.position = "relative";
1289 oHeight = e.clientHeight;
1290 oWidth = e.clientWidth;
1292 if ( parPos == "" || parPos == "static" )
1293 e.parentNode.style.position = "static";
1295 e.parentNode.removeChild(e);
1299 return p == "height" ? oHeight : oWidth;
1302 return jQuery.curCSS( e, p );
1305 curCSS: function(elem, prop, force) {
1308 if (prop == 'opacity' && jQuery.browser.msie)
1309 return jQuery.attr(elem.style, 'opacity');
1311 if (prop == "float" || prop == "cssFloat")
1312 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1314 if (!force && elem.style[prop])
1315 ret = elem.style[prop];
1317 else if (document.defaultView && document.defaultView.getComputedStyle) {
1319 if (prop == "cssFloat" || prop == "styleFloat")
1322 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1323 var cur = document.defaultView.getComputedStyle(elem, null);
1326 ret = cur.getPropertyValue(prop);
1327 else if ( prop == 'display' )
1330 jQuery.swap(elem, { display: 'block' }, function() {
1331 var c = document.defaultView.getComputedStyle(this, '');
1332 ret = c && c.getPropertyValue(prop) || '';
1335 } else if (elem.currentStyle) {
1337 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1338 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1345 clean: function(a) {
1348 for ( var i = 0, al = a.length; i < al; i++ ) {
1351 // Convert html string into DOM nodes
1352 if ( typeof arg == "string" ) {
1353 // Trim whitespace, otherwise indexOf won't work as expected
1354 var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
1357 // option or optgroup
1358 !s.indexOf("<opt") &&
1359 [1, "<select>", "</select>"] ||
1361 (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
1362 [1, "<table>", "</table>"] ||
1364 !s.indexOf("<tr") &&
1365 [2, "<table><tbody>", "</tbody></table>"] ||
1367 // <thead> matched above
1368 (!s.indexOf("<td") || !s.indexOf("<th")) &&
1369 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1373 // Go to html and back, then peel off extra wrappers
1374 div.innerHTML = wrap[1] + s + wrap[2];
1376 // Move to the right depth
1378 div = div.firstChild;
1380 // Remove IE's autoinserted <tbody> from table fragments
1381 if ( jQuery.browser.msie ) {
1383 // String was a <table>, *may* have spurious <tbody>
1384 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
1385 tb = div.firstChild && div.firstChild.childNodes;
1387 // String was a bare <thead> or <tfoot>
1388 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1389 tb = div.childNodes;
1391 for ( var n = tb.length-1; n >= 0 ; --n )
1392 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1393 tb[n].parentNode.removeChild(tb[n]);
1397 arg = div.childNodes;
1403 r = jQuery.merge( r, arg );
1410 attr: function(elem, name, value){
1413 "class": "className",
1414 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1415 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1416 innerHTML: "innerHTML",
1417 className: "className",
1419 disabled: "disabled",
1421 readonly: "readOnly",
1422 selected: "selected"
1425 // IE actually uses filters for opacity ... elem is actually elem.style
1426 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1427 // IE has trouble with opacity if it does not have layout
1428 // Force it by setting the zoom level
1431 // Set the alpha filter to set the opacity
1432 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1433 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1435 } else if ( name == "opacity" && jQuery.browser.msie )
1436 return elem.filter ?
1437 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1439 // Mozilla doesn't play well with opacity 1
1440 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1443 // Certain attributes only work when accessed via the old DOM 0 way
1445 if ( value != undefined ) elem[fix[name]] = value;
1446 return elem[fix[name]];
1448 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') )
1449 return elem.getAttributeNode(name).nodeValue;
1451 // IE elem.getAttribute passes even for style
1452 else if ( elem.tagName ) {
1453 if ( value != undefined ) elem.setAttribute( name, value );
1454 return elem.getAttribute( name );
1457 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1458 if ( value != undefined ) elem[name] = value;
1464 * Remove the whitespace from the beginning and end of a string.
1466 * @example $.trim(" hello, how are you? ");
1467 * @result "hello, how are you?"
1471 * @param String str The string to trim.
1475 return t.replace(/^\s+|\s+$/g, "");
1478 makeArray: function( a ) {
1481 if ( a.constructor != Array )
1482 for ( var i = 0, al = a.length; i < al; i++ )
1490 inArray: function( b, a ) {
1491 for ( var i = 0, al = a.length; i < al; i++ )
1498 * Merge two arrays together, removing all duplicates.
1500 * The new array is: All the results from the first array, followed
1501 * by the unique results from the second array.
1503 * @example $.merge( [0,1,2], [2,3,4] )
1504 * @result [0,1,2,3,4]
1505 * @desc Merges two arrays, removing the duplicate 2
1507 * @example $.merge( [3,2,1], [4,3,2] )
1509 * @desc Merges two arrays, removing the duplicates 3 and 2
1513 * @param Array first The first array to merge.
1514 * @param Array second The second array to merge.
1517 merge: function(first, second) {
1518 var r = [].slice.call( first, 0 );
1520 // Now check for duplicates between the two arrays
1521 // and only add the unique items
1522 for ( var i = 0, sl = second.length; i < sl; i++ )
1523 // Check for duplicates
1524 if ( jQuery.inArray( second[i], r ) == -1 )
1525 // The item is unique, add it
1526 first.push( second[i] );
1532 * Filter items out of an array, by using a filter function.
1534 * The specified function will be passed two arguments: The
1535 * current array item and the index of the item in the array. The
1536 * function must return 'true' to keep the item in the array,
1537 * false to remove it.
1539 * @example $.grep( [0,1,2], function(i){
1546 * @param Array array The Array to find items in.
1547 * @param Function fn The function to process each item against.
1548 * @param Boolean inv Invert the selection - select the opposite of the function.
1551 grep: function(elems, fn, inv) {
1552 // If a string is passed in for the function, make a function
1553 // for it (a handy shortcut)
1554 if ( typeof fn == "string" )
1555 fn = new Function("a","i","return " + fn);
1559 // Go through the array, only saving the items
1560 // that pass the validator function
1561 for ( var i = 0, el = elems.length; i < el; i++ )
1562 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1563 result.push( elems[i] );
1569 * Translate all items in an array to another array of items.
1571 * The translation function that is provided to this method is
1572 * called for each item in the array and is passed one argument:
1573 * The item to be translated.
1575 * The function can then return the translated value, 'null'
1576 * (to remove the item), or an array of values - which will
1577 * be flattened into the full array.
1579 * @example $.map( [0,1,2], function(i){
1583 * @desc Maps the original array to a new one and adds 4 to each value.
1585 * @example $.map( [0,1,2], function(i){
1586 * return i > 0 ? i + 1 : null;
1589 * @desc Maps the original array to a new one and adds 1 to each
1590 * value if it is bigger then zero, otherwise it's removed-
1592 * @example $.map( [0,1,2], function(i){
1593 * return [ i, i + 1 ];
1595 * @result [0, 1, 1, 2, 2, 3]
1596 * @desc Maps the original array to a new one, each element is added
1597 * with it's original value and the value plus one.
1601 * @param Array array The Array to translate.
1602 * @param Function fn The function to process each item against.
1605 map: function(elems, fn) {
1606 // If a string is passed in for the function, make a function
1607 // for it (a handy shortcut)
1608 if ( typeof fn == "string" )
1609 fn = new Function("a","return " + fn);
1611 var result = [], r = [];
1613 // Go through the array, translating each of the items to their
1614 // new value (or values).
1615 for ( var i = 0, el = elems.length; i < el; i++ ) {
1616 var val = fn(elems[i],i);
1618 if ( val !== null && val != undefined ) {
1619 if ( val.constructor != Array ) val = [val];
1620 result = result.concat( val );
1624 var r = result.length ? [ result[0] ] : [];
1626 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1627 for ( var j = 0; j < i; j++ )
1628 if ( result[i] == r[j] )
1631 r.push( result[i] );
1639 * Contains flags for the useragent, read from navigator.userAgent.
1640 * Available flags are: safari, opera, msie, mozilla
1642 * This property is available before the DOM is ready, therefore you can
1643 * use it to add ready events only for certain browsers.
1645 * There are situations where object detections is not reliable enough, in that
1646 * cases it makes sense to use browser detection. Simply try to avoid both!
1648 * A combination of browser and object detection yields quite reliable results.
1650 * @example $.browser.msie
1651 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1653 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1654 * @desc Alerts "this is safari!" only for safari browsers
1663 * Wheather the W3C compliant box model is being used.
1671 var b = navigator.userAgent.toLowerCase();
1673 // Figure out what browser is being used
1675 safari: /webkit/.test(b),
1676 opera: /opera/.test(b),
1677 msie: /msie/.test(b) && !/opera/.test(b),
1678 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1681 // Check to see if the W3C box model is being used
1682 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1686 * Get a set of elements containing the unique parents of the matched
1689 * Can be filtered with an optional expressions.
1691 * @example $("p").parent()
1692 * @before <div><p>Hello</p><p>Hello</p></div>
1693 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1694 * @desc Find the parent element of each paragraph.
1696 * @example $("p").parent(".selected")
1697 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1698 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1699 * @desc Find the parent element of each paragraph with a class "selected".
1703 * @param String expr (optional) An expression to filter the parents with
1704 * @cat DOM/Traversing
1708 * Get a set of elements containing the unique ancestors of the matched
1709 * set of elements (except for the root element).
1711 * Can be filtered with an optional expressions.
1713 * @example $("span").parents()
1714 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1715 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1716 * @desc Find all parent elements of each span.
1718 * @example $("span").parents("p")
1719 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1720 * @result [ <p><span>Hello</span></p> ]
1721 * @desc Find all parent elements of each span that is a paragraph.
1725 * @param String expr (optional) An expression to filter the ancestors with
1726 * @cat DOM/Traversing
1730 * Get a set of elements containing the unique next siblings of each of the
1731 * matched set of elements.
1733 * It only returns the very next sibling, not all next siblings.
1735 * Can be filtered with an optional expressions.
1737 * @example $("p").next()
1738 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1739 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1740 * @desc Find the very next sibling of each paragraph.
1742 * @example $("p").next(".selected")
1743 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1744 * @result [ <p class="selected">Hello Again</p> ]
1745 * @desc Find the very next sibling of each paragraph that has a class "selected".
1749 * @param String expr (optional) An expression to filter the next Elements with
1750 * @cat DOM/Traversing
1754 * Get a set of elements containing the unique previous siblings of each of the
1755 * matched set of elements.
1757 * Can be filtered with an optional expressions.
1759 * It only returns the immediately previous sibling, not all previous siblings.
1761 * @example $("p").prev()
1762 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1763 * @result [ <div><span>Hello Again</span></div> ]
1764 * @desc Find the very previous sibling of each paragraph.
1766 * @example $("p").prev(".selected")
1767 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1768 * @result [ <div><span>Hello</span></div> ]
1769 * @desc Find the very previous sibling of each paragraph that has a class "selected".
1773 * @param String expr (optional) An expression to filter the previous Elements with
1774 * @cat DOM/Traversing
1778 * Get a set of elements containing all of the unique siblings of each of the
1779 * matched set of elements.
1781 * Can be filtered with an optional expressions.
1783 * @example $("div").siblings()
1784 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1785 * @result [ <p>Hello</p>, <p>And Again</p> ]
1786 * @desc Find all siblings of each div.
1788 * @example $("div").siblings(".selected")
1789 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1790 * @result [ <p class="selected">Hello Again</p> ]
1791 * @desc Find all siblings with a class "selected" of each div.
1795 * @param String expr (optional) An expression to filter the sibling Elements with
1796 * @cat DOM/Traversing
1800 * Get a set of elements containing all of the unique children of each of the
1801 * matched set of elements.
1803 * Can be filtered with an optional expressions.
1805 * @example $("div").children()
1806 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1807 * @result [ <span>Hello Again</span> ]
1808 * @desc Find all children of each div.
1810 * @example $("div").children(".selected")
1811 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1812 * @result [ <p class="selected">Hello Again</p> ]
1813 * @desc Find all children with a class "selected" of each div.
1817 * @param String expr (optional) An expression to filter the child Elements with
1818 * @cat DOM/Traversing
1821 parent: "a.parentNode",
1822 parents: "jQuery.parents(a)",
1823 next: "jQuery.nth(a,2,'nextSibling')",
1824 prev: "jQuery.nth(a,2,'previousSibling')",
1825 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1826 children: "jQuery.sibling(a.firstChild)"
1828 jQuery.fn[ i ] = function(a) {
1829 var ret = jQuery.map(this,n);
1830 if ( a && typeof a == "string" )
1831 ret = jQuery.filter(a,ret).r;
1832 return this.pushStack( ret );
1837 * Append all of the matched elements to another, specified, set of elements.
1838 * This operation is, essentially, the reverse of doing a regular
1839 * $(A).append(B), in that instead of appending B to A, you're appending
1842 * @example $("p").appendTo("#foo");
1843 * @before <p>I would like to say: </p><div id="foo"></div>
1844 * @result <div id="foo"><p>I would like to say: </p></div>
1845 * @desc Appends all paragraphs to the element with the ID "foo"
1849 * @param <Content> content Content to append to the selected element to.
1850 * @cat DOM/Manipulation
1851 * @see append(<Content>)
1855 * Prepend all of the matched elements to another, specified, set of elements.
1856 * This operation is, essentially, the reverse of doing a regular
1857 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1860 * @example $("p").prependTo("#foo");
1861 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1862 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1863 * @desc Prepends all paragraphs to the element with the ID "foo"
1867 * @param <Content> content Content to prepend to the selected element to.
1868 * @cat DOM/Manipulation
1869 * @see prepend(<Content>)
1873 * Insert all of the matched elements before another, specified, set of elements.
1874 * This operation is, essentially, the reverse of doing a regular
1875 * $(A).before(B), in that instead of inserting B before A, you're inserting
1878 * @example $("p").insertBefore("#foo");
1879 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1880 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1881 * @desc Same as $("#foo").before("p")
1883 * @name insertBefore
1885 * @param <Content> content Content to insert the selected element before.
1886 * @cat DOM/Manipulation
1887 * @see before(<Content>)
1891 * Insert all of the matched elements after another, specified, set of elements.
1892 * This operation is, essentially, the reverse of doing a regular
1893 * $(A).after(B), in that instead of inserting B after A, you're inserting
1896 * @example $("p").insertAfter("#foo");
1897 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1898 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1899 * @desc Same as $("#foo").after("p")
1903 * @param <Content> content Content to insert the selected element after.
1904 * @cat DOM/Manipulation
1905 * @see after(<Content>)
1910 prependTo: "prepend",
1911 insertBefore: "before",
1912 insertAfter: "after"
1914 jQuery.fn[ i ] = function(){
1916 return this.each(function(){
1917 for ( var j = 0, al = a.length; j < al; j++ )
1918 jQuery(a[j])[n]( this );
1924 * Remove an attribute from each of the matched elements.
1926 * @example $("input").removeAttr("disabled")
1927 * @before <input disabled="disabled"/>
1932 * @param String name The name of the attribute to remove.
1933 * @cat DOM/Attributes
1937 * Adds the specified class(es) to each of the set of matched elements.
1939 * @example $("p").addClass("selected")
1940 * @before <p>Hello</p>
1941 * @result [ <p class="selected">Hello</p> ]
1943 * @example $("p").addClass("selected highlight")
1944 * @before <p>Hello</p>
1945 * @result [ <p class="selected highlight">Hello</p> ]
1949 * @param String class One or more CSS classes to add to the elements
1950 * @cat DOM/Attributes
1951 * @see removeClass(String)
1955 * Removes all or the specified class(es) from the set of matched elements.
1957 * @example $("p").removeClass()
1958 * @before <p class="selected">Hello</p>
1959 * @result [ <p>Hello</p> ]
1961 * @example $("p").removeClass("selected")
1962 * @before <p class="selected first">Hello</p>
1963 * @result [ <p class="first">Hello</p> ]
1965 * @example $("p").removeClass("selected highlight")
1966 * @before <p class="highlight selected first">Hello</p>
1967 * @result [ <p class="first">Hello</p> ]
1971 * @param String class (optional) One or more CSS classes to remove from the elements
1972 * @cat DOM/Attributes
1973 * @see addClass(String)
1977 * Adds the specified class if it is not present, removes it if it is
1980 * @example $("p").toggleClass("selected")
1981 * @before <p>Hello</p><p class="selected">Hello Again</p>
1982 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
1986 * @param String class A CSS class with which to toggle the elements
1987 * @cat DOM/Attributes
1991 * Removes all matched elements from the DOM. This does NOT remove them from the
1992 * jQuery object, allowing you to use the matched elements further.
1994 * Can be filtered with an optional expressions.
1996 * @example $("p").remove();
1997 * @before <p>Hello</p> how are <p>you?</p>
2000 * @example $("p").remove(".hello");
2001 * @before <p class="hello">Hello</p> how are <p>you?</p>
2002 * @result how are <p>you?</p>
2006 * @param String expr (optional) A jQuery expression to filter elements by.
2007 * @cat DOM/Manipulation
2011 * Removes all child nodes from the set of matched elements.
2013 * @example $("p").empty()
2014 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2015 * @result [ <p></p> ]
2019 * @cat DOM/Manipulation
2023 removeAttr: function( key ) {
2024 jQuery.attr( this, key, "" );
2025 this.removeAttribute( key );
2027 addClass: function(c){
2028 jQuery.className.add(this,c);
2030 removeClass: function(c){
2031 jQuery.className.remove(this,c);
2033 toggleClass: function( c ){
2034 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2036 remove: function(a){
2037 if ( !a || jQuery.filter( a, [this] ).r.length )
2038 this.parentNode.removeChild( this );
2041 while ( this.firstChild )
2042 this.removeChild( this.firstChild );
2045 jQuery.fn[ i ] = function() {
2046 return this.each( n, arguments );
2051 * Reduce the set of matched elements to a single element.
2052 * The position of the element in the set of matched elements
2053 * starts at 0 and goes to length - 1.
2055 * @example $("p").eq(1)
2056 * @before <p>This is just a test.</p><p>So is this</p>
2057 * @result [ <p>So is this</p> ]
2061 * @param Number pos The index of the element that you wish to limit to.
2066 * Reduce the set of matched elements to all elements before a given position.
2067 * The position of the element in the set of matched elements
2068 * starts at 0 and goes to length - 1.
2070 * @example $("p").lt(1)
2071 * @before <p>This is just a test.</p><p>So is this</p>
2072 * @result [ <p>This is just a test.</p> ]
2076 * @param Number pos Reduce the set to all elements below this position.
2081 * Reduce the set of matched elements to all elements after a given position.
2082 * The position of the element in the set of matched elements
2083 * starts at 0 and goes to length - 1.
2085 * @example $("p").gt(0)
2086 * @before <p>This is just a test.</p><p>So is this</p>
2087 * @result [ <p>So is this</p> ]
2091 * @param Number pos Reduce the set to all elements after this position.
2096 * Filter the set of elements to those that contain the specified text.
2098 * @example $("p").contains("test")
2099 * @before <p>This is just a test.</p><p>So is this</p>
2100 * @result [ <p>This is just a test.</p> ]
2104 * @param String str The string that will be contained within the text of an element.
2105 * @cat DOM/Traversing
2107 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2108 jQuery.fn[ n ] = function(num,fn) {
2109 return this.filter( ":" + n + "(" + num + ")", fn );
2114 * Get the current computed, pixel, width of the first matched element.
2116 * @example $("p").width();
2117 * @before <p>This is just a test.</p>
2126 * Set the CSS width of every matched element. If no explicit unit
2127 * was specified (like 'em' or '%') then "px" is added to the width.
2129 * @example $("p").width(20);
2130 * @before <p>This is just a test.</p>
2131 * @result <p style="width:20px;">This is just a test.</p>
2133 * @example $("p").width("20em");
2134 * @before <p>This is just a test.</p>
2135 * @result <p style="width:20em;">This is just a test.</p>
2139 * @param Number|String val Set the CSS property to the specified value.
2144 * Get the current computed, pixel, height of the first matched element.
2146 * @example $("p").height();
2147 * @before <p>This is just a test.</p>
2156 * Set the CSS width of every matched element. If no explicit unit
2157 * was specified (like 'em' or '%') then "px" is added to the width.
2159 * @example $("p").height(20);
2160 * @before <p>This is just a test.</p>
2161 * @result <p style="height:20px;">This is just a test.</p>
2163 * @example $("p").height("20em");
2164 * @before <p>This is just a test.</p>
2165 * @result <p style="height:20em;">This is just a test.</p>
2169 * @param Number|String val Set the CSS property to the specified value.
2173 jQuery.each( [ "height", "width" ], function(i,n){
2174 jQuery.fn[ n ] = function(h) {
2175 return h == undefined ?
2176 ( this.length ? jQuery.css( this[0], n ) : null ) :
2177 this.css( n, h.constructor == String ? h : h + "px" );