2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2007 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 return this.init(a,c);
33 // Map over the $ in case of overwrite
34 if ( typeof $ != "undefined" )
37 // Map the jQuery namespace to the '$' one
41 * This function accepts a string containing a CSS or
42 * basic XPath selector which is then used to match a set of elements.
44 * The core functionality of jQuery centers around this function.
45 * Everything in jQuery is based upon this, or uses this in some way.
46 * The most basic use of this function is to pass in an expression
47 * (usually consisting of CSS or XPath), which then finds all matching
50 * By default, if no context is specified, $() looks for DOM elements within the context of the
51 * current HTML document. If you do specify a context, such as a DOM
52 * element or jQuery object, the expression will be matched against
53 * the contents of that context.
55 * See [[DOM/Traversing/Selectors]] for the allowed CSS/XPath syntax for expressions.
57 * @example $("div > p")
58 * @desc Finds all p elements that are children of a div element.
59 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
60 * @result [ <p>two</p> ]
62 * @example $("input:radio", document.forms[0])
63 * @desc Searches for all inputs of type radio within the first form in the document
65 * @example $("div", xml.responseXML)
66 * @desc This finds all div elements within the specified XML document.
69 * @param String expr An expression to search with
70 * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
74 * @see $(Element<Array>)
78 * Create DOM elements on-the-fly from the provided String of raw HTML.
80 * @example $("<div><p>Hello</p></div>").appendTo("body")
81 * @desc Creates a div element (and all of its contents) dynamically,
82 * and appends it to the body element. Internally, an
83 * element is created and its innerHTML property set to the given markup.
84 * It is therefore both quite flexible and limited.
87 * @param String html A string of HTML to create on the fly.
90 * @see appendTo(String)
94 * Wrap jQuery functionality around a single or multiple DOM Element(s).
96 * This function also accepts XML Documents and Window objects
97 * as valid arguments (even though they are not DOM Elements).
99 * @example $(document.body).css( "background", "black" );
100 * @desc Sets the background color of the page to black.
102 * @example $( myForm.elements ).hide()
103 * @desc Hides all the input elements within a form
106 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
112 * A shorthand for $(document).ready(), allowing you to bind a function
113 * to be executed when the DOM document has finished loading. This function
114 * behaves just like $(document).ready(), in that it should be used to wrap
115 * other $() operations on your page that depend on the DOM being ready to be
116 * operated on. While this function is, technically, chainable - there really
117 * isn't much use for chaining against it.
119 * You can have as many $(document).ready events on your page as you like.
121 * See ready(Function) for details about the ready event.
123 * @example $(function(){
124 * // Document is ready
126 * @desc Executes the function when the DOM is ready to be used.
128 * @example jQuery(function($) {
129 * // Your code using failsafe $ alias here...
131 * @desc Uses both the shortcut for $(document).ready() and the argument
132 * to write failsafe jQuery code using the $ alias, without relying on the
136 * @param Function fn The function to execute when the DOM is ready.
139 * @see ready(Function)
142 jQuery.fn = jQuery.prototype = {
144 * Initialize a new jQuery object
148 * @param String|Function|Element|Array<Element>|jQuery a selector
149 * @param jQuery|Element|Array<Element> c context
152 init: function(a,c) {
153 // Make sure that a selection was provided
156 // HANDLE: $(function)
157 // Shortcut for document ready
158 if ( jQuery.isFunction(a) )
159 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
161 // Handle HTML strings
162 if ( typeof a == "string" ) {
163 // HANDLE: $(html) -> $(array)
164 var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a);
166 a = jQuery.clean( [ m[1] ] );
170 return new jQuery( c ).find( a );
173 return this.setArray(
175 a.constructor == Array && a ||
177 // HANDLE: $(arraylike)
178 // Watch for when an array-like object is passed as the selector
179 (a.jquery || a.length && a != window && (!a.nodeType || (jQuery.browser.msie && a.elements)) && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
186 * The current version of jQuery.
197 * The number of elements currently matched. The size function will return the same value.
199 * @example $("img").length;
200 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
210 * Get the number of elements currently matched. This returns the same
211 * number as the 'length' property of the jQuery object.
213 * @example $("img").size();
214 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
228 * Access all matched DOM elements. This serves as a backwards-compatible
229 * way of accessing all matched elements (other than the jQuery object
230 * itself, which is, in fact, an array of elements).
232 * It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions.
234 * @example $("img").get();
235 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
236 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
237 * @desc Selects all images in the document and returns the DOM Elements as an Array
240 * @type Array<Element>
245 * Access a single matched DOM element at a specified index in the matched set.
246 * This allows you to extract the actual DOM element and operate on it
247 * directly without necessarily using jQuery functionality on it.
249 * @example $("img").get(0);
250 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
251 * @result <img src="test1.jpg"/>
252 * @desc Selects all images in the document and returns the first one
256 * @param Number num Access the element in the Nth position.
259 get: function( num ) {
260 return num == undefined ?
262 // Return a 'clean' array
263 jQuery.makeArray( this ) :
265 // Return just the object
270 * Set the jQuery object to an array of elements, while maintaining
273 * @example $("img").pushStack([ document.body ]);
274 * @result $("img").pushStack() == [ document.body ]
279 * @param Elements elems An array of elements
282 pushStack: function( a ) {
284 ret.prevObject = this;
289 * Set the jQuery object to an array of elements. This operation is
290 * completely destructive - be sure to use .pushStack() if you wish to maintain
293 * @example $("img").setArray([ document.body ]);
294 * @result $("img").setArray() == [ document.body ]
299 * @param Elements elems An array of elements
302 setArray: function( a ) {
304 [].push.apply( this, a );
309 * Execute a function within the context of every matched element.
310 * This means that every time the passed-in function is executed
311 * (which is once for every element matched) the 'this' keyword
312 * points to the specific DOM element.
314 * Additionally, the function, when executed, is passed a single
315 * argument representing the position of the element in the matched
316 * set (integer, zero-index).
318 * @example $("img").each(function(i){
319 * this.src = "test" + i + ".jpg";
321 * @before <img/><img/>
322 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
323 * @desc Iterates over two images and sets their src property
327 * @param Function fn A function to execute
330 each: function( fn, args ) {
331 return jQuery.each( this, fn, args );
335 * Searches every matched element for the object and returns
336 * the index of the element, if found, starting with zero.
337 * Returns -1 if the object wasn't found.
339 * @example $("*").index( $('#foobar')[0] )
340 * @before <div id="foobar"><b></b><span id="foo"></span></div>
342 * @desc Returns the index for the element with ID foobar
344 * @example $("*").index( $('#foo')[0] )
345 * @before <div id="foobar"><b></b><span id="foo"></span></div>
347 * @desc Returns the index for the element with ID foo within another element
349 * @example $("*").index( $('#bar')[0] )
350 * @before <div id="foobar"><b></b><span id="foo"></span></div>
352 * @desc Returns -1, as there is no element with ID bar
356 * @param Element subject Object to search for
359 index: function( obj ) {
361 this.each(function(i){
362 if ( this == obj ) pos = i;
368 * Access a property on the first matched element.
369 * This method makes it easy to retrieve a property value
370 * from the first matched element.
372 * If the element does not have an attribute with such a
373 * name, undefined is returned.
375 * @example $("img").attr("src");
376 * @before <img src="test.jpg"/>
378 * @desc Returns the src attribute from the first image in the document.
382 * @param String name The name of the property to access.
383 * @cat DOM/Attributes
387 * Set a key/value object as properties to all matched elements.
389 * This serves as the best way to set a large number of properties
390 * on all matched elements.
392 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
394 * @result <img src="test.jpg" alt="Test Image"/>
395 * @desc Sets src and alt attributes to all images.
399 * @param Map properties Key/value pairs to set as object properties.
400 * @cat DOM/Attributes
404 * Set a single property to a value, on all matched elements.
406 * Note that you can't set the name property of input elements in IE.
407 * Use $(html) or .append(html) or .html(html) to create elements
408 * on the fly including the name property.
410 * @example $("img").attr("src","test.jpg");
412 * @result <img src="test.jpg"/>
413 * @desc Sets src attribute to all images.
417 * @param String key The name of the property to set.
418 * @param Object value The value to set the property to.
419 * @cat DOM/Attributes
423 * Set a single property to a computed value, on all matched elements.
425 * Instead of supplying a string value as described
426 * [[DOM/Attributes#attr.28_key.2C_value_.29|above]],
427 * a function is provided that computes the value.
429 * @example $("img").attr("title", function() { return this.src });
430 * @before <img src="test.jpg" />
431 * @result <img src="test.jpg" title="test.jpg" />
432 * @desc Sets title attribute from src attribute.
434 * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
435 * @before <img title="pic" /><img title="pic" /><img title="pic" />
436 * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
437 * @desc Enumerate title attribute.
441 * @param String key The name of the property to set.
442 * @param Function value A function returning the value to set.
443 * Scope: Current element, argument: Index of current element
444 * @cat DOM/Attributes
446 attr: function( key, value, type ) {
449 // Look for the case where we're accessing a style value
450 if ( key.constructor == String )
451 if ( value == undefined )
452 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
458 // Check to see if we're setting style values
459 return this.each(function(index){
460 // Set all the styles
461 for ( var prop in obj )
463 type ? this.style : this,
464 prop, jQuery.prop(this, obj[prop], type, index, prop)
470 * Access a style property on the first matched element.
471 * This method makes it easy to retrieve a style property value
472 * from the first matched element.
474 * @example $("p").css("color");
475 * @before <p style="color:red;">Test Paragraph.</p>
477 * @desc Retrieves the color style of the first paragraph
479 * @example $("p").css("font-weight");
480 * @before <p style="font-weight: bold;">Test Paragraph.</p>
482 * @desc Retrieves the font-weight style of the first paragraph.
486 * @param String name The name of the property to access.
491 * Set a key/value object as style properties to all matched elements.
493 * This serves as the best way to set a large number of style properties
494 * on all matched elements.
496 * @example $("p").css({ color: "red", background: "blue" });
497 * @before <p>Test Paragraph.</p>
498 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
499 * @desc Sets color and background styles to all p elements.
503 * @param Map properties Key/value pairs to set as style properties.
508 * Set a single style property to a value, on all matched elements.
509 * If a number is provided, it is automatically converted into a pixel value.
511 * @example $("p").css("color","red");
512 * @before <p>Test Paragraph.</p>
513 * @result <p style="color:red;">Test Paragraph.</p>
514 * @desc Changes the color of all paragraphs to red
516 * @example $("p").css("left",30);
517 * @before <p>Test Paragraph.</p>
518 * @result <p style="left:30px;">Test Paragraph.</p>
519 * @desc Changes the left of all paragraphs to "30px"
523 * @param String key The name of the property to set.
524 * @param String|Number value The value to set the property to.
527 css: function( key, value ) {
528 return this.attr( key, value, "curCSS" );
532 * Get the text contents of all matched elements. The result is
533 * a string that contains the combined text contents of all matched
534 * elements. This method works on both HTML and XML documents.
536 * @example $("p").text();
537 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
538 * @result Test Paragraph.Paraparagraph
539 * @desc Gets the concatenated text of all paragraphs
543 * @cat DOM/Attributes
547 * Set the text contents of all matched elements.
549 * Similar to html(), but escapes HTML (replace "<" and ">" with their
552 * @example $("p").text("<b>Some</b> new text.");
553 * @before <p>Test Paragraph.</p>
554 * @result <p><b>Some</b> new text.</p>
555 * @desc Sets the text of all paragraphs.
557 * @example $("p").text("<b>Some</b> new text.", true);
558 * @before <p>Test Paragraph.</p>
559 * @result <p>Some new text.</p>
560 * @desc Sets the text of all paragraphs.
564 * @param String val The text value to set the contents of the element to.
565 * @cat DOM/Attributes
568 if ( typeof e == "string" )
569 return this.empty().append( document.createTextNode( e ) );
572 jQuery.each( e || this, function(){
573 jQuery.each( this.childNodes, function(){
574 if ( this.nodeType != 8 )
575 t += this.nodeType != 1 ?
576 this.nodeValue : jQuery.fn.text([ this ]);
583 * Wrap all matched elements with a structure of other elements.
584 * This wrapping process is most useful for injecting additional
585 * stucture into a document, without ruining the original semantic
586 * qualities of a document.
588 * This works by going through the first element
589 * provided (which is generated, on the fly, from the provided HTML)
590 * and finds the deepest ancestor element within its
591 * structure - it is that element that will en-wrap everything else.
593 * This does not work with elements that contain text. Any necessary text
594 * must be added after the wrapping is done.
596 * @example $("p").wrap("<div class='wrap'></div>");
597 * @before <p>Test Paragraph.</p>
598 * @result <div class='wrap'><p>Test Paragraph.</p></div>
602 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
603 * @cat DOM/Manipulation
607 * Wrap all matched elements with a structure of other elements.
608 * This wrapping process is most useful for injecting additional
609 * stucture into a document, without ruining the original semantic
610 * qualities of a document.
612 * This works by going through the first element
613 * provided and finding the deepest ancestor element within its
614 * structure - it is that element that will en-wrap everything else.
616 * This does not work with elements that contain text. Any necessary text
617 * must be added after the wrapping is done.
619 * @example $("p").wrap( document.getElementById('content') );
620 * @before <p>Test Paragraph.</p><div id="content"></div>
621 * @result <div id="content"><p>Test Paragraph.</p></div>
625 * @param Element elem A DOM element that will be wrapped around the target.
626 * @cat DOM/Manipulation
629 // The elements to wrap the target around
630 var a, args = arguments;
632 // Wrap each of the matched elements individually
633 return this.each(function(){
635 a = jQuery.clean(args, this.ownerDocument);
637 // Clone the structure that we're using to wrap
638 var b = a[0].cloneNode(true);
640 // Insert it before the element to be wrapped
641 this.parentNode.insertBefore( b, this );
643 // Find the deepest point in the wrap structure
644 while ( b.firstChild )
647 // Move the matched element to within the wrap structure
648 b.appendChild( this );
653 * Append content to the inside of every matched element.
655 * This operation is similar to doing an appendChild to all the
656 * specified elements, adding them into the document.
658 * @example $("p").append("<b>Hello</b>");
659 * @before <p>I would like to say: </p>
660 * @result <p>I would like to say: <b>Hello</b></p>
661 * @desc Appends some HTML to all paragraphs.
663 * @example $("p").append( $("#foo")[0] );
664 * @before <p>I would like to say: </p><b id="foo">Hello</b>
665 * @result <p>I would like to say: <b id="foo">Hello</b></p>
666 * @desc Appends an Element to all paragraphs.
668 * @example $("p").append( $("b") );
669 * @before <p>I would like to say: </p><b>Hello</b>
670 * @result <p>I would like to say: <b>Hello</b></p>
671 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
675 * @param <Content> content Content to append to the target
676 * @cat DOM/Manipulation
677 * @see prepend(<Content>)
678 * @see before(<Content>)
679 * @see after(<Content>)
682 return this.domManip(arguments, true, 1, function(a){
683 this.appendChild( a );
688 * Prepend content to the inside of every matched element.
690 * This operation is the best way to insert elements
691 * inside, at the beginning, of all matched elements.
693 * @example $("p").prepend("<b>Hello</b>");
694 * @before <p>I would like to say: </p>
695 * @result <p><b>Hello</b>I would like to say: </p>
696 * @desc Prepends some HTML to all paragraphs.
698 * @example $("p").prepend( $("#foo")[0] );
699 * @before <p>I would like to say: </p><b id="foo">Hello</b>
700 * @result <p><b id="foo">Hello</b>I would like to say: </p>
701 * @desc Prepends an Element to all paragraphs.
703 * @example $("p").prepend( $("b") );
704 * @before <p>I would like to say: </p><b>Hello</b>
705 * @result <p><b>Hello</b>I would like to say: </p>
706 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
710 * @param <Content> content Content to prepend to the target.
711 * @cat DOM/Manipulation
712 * @see append(<Content>)
713 * @see before(<Content>)
714 * @see after(<Content>)
716 prepend: function() {
717 return this.domManip(arguments, true, -1, function(a){
718 this.insertBefore( a, this.firstChild );
723 * Insert content before each of the matched elements.
725 * @example $("p").before("<b>Hello</b>");
726 * @before <p>I would like to say: </p>
727 * @result <b>Hello</b><p>I would like to say: </p>
728 * @desc Inserts some HTML before all paragraphs.
730 * @example $("p").before( $("#foo")[0] );
731 * @before <p>I would like to say: </p><b id="foo">Hello</b>
732 * @result <b id="foo">Hello</b><p>I would like to say: </p>
733 * @desc Inserts an Element before all paragraphs.
735 * @example $("p").before( $("b") );
736 * @before <p>I would like to say: </p><b>Hello</b>
737 * @result <b>Hello</b><p>I would like to say: </p>
738 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
742 * @param <Content> content Content to insert before each target.
743 * @cat DOM/Manipulation
744 * @see append(<Content>)
745 * @see prepend(<Content>)
746 * @see after(<Content>)
749 return this.domManip(arguments, false, 1, function(a){
750 this.parentNode.insertBefore( a, this );
755 * Insert content after each of the matched elements.
757 * @example $("p").after("<b>Hello</b>");
758 * @before <p>I would like to say: </p>
759 * @result <p>I would like to say: </p><b>Hello</b>
760 * @desc Inserts some HTML after all paragraphs.
762 * @example $("p").after( $("#foo")[0] );
763 * @before <b id="foo">Hello</b><p>I would like to say: </p>
764 * @result <p>I would like to say: </p><b id="foo">Hello</b>
765 * @desc Inserts an Element after all paragraphs.
767 * @example $("p").after( $("b") );
768 * @before <b>Hello</b><p>I would like to say: </p>
769 * @result <p>I would like to say: </p><b>Hello</b>
770 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
774 * @param <Content> content Content to insert after each target.
775 * @cat DOM/Manipulation
776 * @see append(<Content>)
777 * @see prepend(<Content>)
778 * @see before(<Content>)
781 return this.domManip(arguments, false, -1, function(a){
782 this.parentNode.insertBefore( a, this.nextSibling );
787 * Revert the most recent 'destructive' operation, changing the set of matched elements
788 * to its previous state (right before the destructive operation).
790 * If there was no destructive operation before, an empty set is returned.
792 * A 'destructive' operation is any operation that changes the set of
793 * matched jQuery elements. These functions are: <code>add</code>,
794 * <code>children</code>, <code>clone</code>, <code>filter</code>,
795 * <code>find</code>, <code>not</code>, <code>next</code>,
796 * <code>parent</code>, <code>parents</code>, <code>prev</code> and <code>siblings</code>.
798 * @example $("p").find("span").end();
799 * @before <p><span>Hello</span>, how are you?</p>
800 * @result [ <p>...</p> ]
801 * @desc Selects all paragraphs, finds span elements inside these, and reverts the
802 * selection back to the paragraphs.
806 * @cat DOM/Traversing
809 return this.prevObject || jQuery([]);
813 * Searches for all elements that match the specified expression.
815 * This method is a good way to find additional descendant
816 * elements with which to process.
818 * All searching is done using a jQuery expression. The expression can be
819 * written using CSS 1-3 Selector syntax, or basic XPath.
821 * @example $("p").find("span");
822 * @before <p><span>Hello</span>, how are you?</p>
823 * @result [ <span>Hello</span> ]
824 * @desc Starts with all paragraphs and searches for descendant span
825 * elements, same as $("p span")
829 * @param String expr An expression to search with.
830 * @cat DOM/Traversing
833 return this.pushStack( jQuery.unique( jQuery.map( this, function(a){
834 return jQuery.find(t,a);
839 * Clone matched DOM Elements and select the clones.
841 * This is useful for moving copies of the elements to another
842 * location in the DOM.
844 * @example $("b").clone().prependTo("p");
845 * @before <b>Hello</b><p>, how are you?</p>
846 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
847 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
851 * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
852 * @cat DOM/Manipulation
854 clone: function(deep) {
855 return this.pushStack( jQuery.map( this, function(a){
856 a = a.cloneNode( deep != undefined ? deep : true );
857 a.$events = null; // drop $events expando to avoid firing incorrect events
863 * Removes all elements from the set of matched elements that do not
864 * match the specified expression(s). This method is used to narrow down
865 * the results of a search.
867 * Provide a comma-separated list of expressions to apply multiple filters at once.
869 * @example $("p").filter(".selected")
870 * @before <p class="selected">Hello</p><p>How are you?</p>
871 * @result [ <p class="selected">Hello</p> ]
872 * @desc Selects all paragraphs and removes those without a class "selected".
874 * @example $("p").filter(".selected, :first")
875 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
876 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
877 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
881 * @param String expression Expression(s) to search with.
882 * @cat DOM/Traversing
886 * Removes all elements from the set of matched elements that do not
887 * pass the specified filter. This method is used to narrow down
888 * the results of a search.
890 * @example $("p").filter(function(index) {
891 * return $("ol", this).length == 0;
893 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
894 * @result [ <p>How are you?</p> ]
895 * @desc Remove all elements that have a child ol element
899 * @param Function filter A function to use for filtering
900 * @cat DOM/Traversing
902 filter: function(t) {
903 return this.pushStack(
904 jQuery.isFunction( t ) &&
905 jQuery.grep(this, function(el, index){
906 return t.apply(el, [index])
909 jQuery.multiFilter(t,this) );
913 * Removes the specified Element from the set of matched elements. This
914 * method is used to remove a single Element from a jQuery object.
916 * @example $("p").not( $("#selected")[0] )
917 * @before <p>Hello</p><p id="selected">Hello Again</p>
918 * @result [ <p>Hello</p> ]
919 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
923 * @param Element el An element to remove from the set
924 * @cat DOM/Traversing
928 * Removes elements matching the specified expression from the set
929 * of matched elements. This method is used to remove one or more
930 * elements from a jQuery object.
932 * @example $("p").not("#selected")
933 * @before <p>Hello</p><p id="selected">Hello Again</p>
934 * @result [ <p>Hello</p> ]
935 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
939 * @param String expr An expression with which to remove matching elements
940 * @cat DOM/Traversing
944 * Removes any elements inside the array of elements from the set
945 * of matched elements. This method is used to remove one or more
946 * elements from a jQuery object.
948 * Please note: the expression cannot use a reference to the
949 * element name. See the two examples below.
951 * @example $("p").not( $("div p.selected") )
952 * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
953 * @result [ <p>Hello</p> ]
954 * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
958 * @param jQuery elems A set of elements to remove from the jQuery set of matched elements.
959 * @cat DOM/Traversing
962 return this.pushStack(
963 t.constructor == String &&
964 jQuery.multiFilter(t, this, true) ||
966 jQuery.grep(this, function(a) {
967 return ( t.constructor == Array || t.jquery )
968 ? jQuery.inArray( a, t ) < 0
975 * Adds more elements, matched by the given expression,
976 * to the set of matched elements.
978 * @example $("p").add("span")
979 * @before (HTML) <p>Hello</p><span>Hello Again</span>
980 * @result (jQuery object matching 2 elements) [ <p>Hello</p>, <span>Hello Again</span> ]
981 * @desc Compare the above result to the result of <code>$('p')</code>,
982 * which would just result in <code><nowiki>[ <p>Hello</p> ]</nowiki></code>.
983 * Using add(), matched elements of <code>$('span')</code> are simply
984 * added to the returned jQuery-object.
988 * @param String expr An expression whose matched elements are added
989 * @cat DOM/Traversing
993 * Adds more elements, created on the fly, to the set of
996 * @example $("p").add("<span>Again</span>")
997 * @before <p>Hello</p>
998 * @result [ <p>Hello</p>, <span>Again</span> ]
1002 * @param String html A string of HTML to create on the fly.
1003 * @cat DOM/Traversing
1007 * Adds one or more Elements to the set of matched elements.
1009 * @example $("p").add( document.getElementById("a") )
1010 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1011 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1013 * @example $("p").add( document.forms[0].elements )
1014 * @before <p>Hello</p><p><form><input/><button/></form>
1015 * @result [ <p>Hello</p>, <input/>, <button/> ]
1019 * @param Element|Array<Element> elements One or more Elements to add
1020 * @cat DOM/Traversing
1023 return this.pushStack( jQuery.merge(
1025 t.constructor == String ?
1027 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
1033 * Checks the current selection against an expression and returns true,
1034 * if at least one element of the selection fits the given expression.
1036 * Does return false, if no element fits or the expression is not valid.
1038 * filter(String) is used internally, therefore all rules that apply there
1041 * @example $("input[@type='checkbox']").parent().is("form")
1042 * @before <form><input type="checkbox" /></form>
1044 * @desc Returns true, because the parent of the input is a form element
1046 * @example $("input[@type='checkbox']").parent().is("form")
1047 * @before <form><p><input type="checkbox" /></p></form>
1049 * @desc Returns false, because the parent of the input is a p element
1053 * @param String expr The expression with which to filter
1054 * @cat DOM/Traversing
1056 is: function(expr) {
1057 return expr ? jQuery.multiFilter(expr,this).length > 0 : false;
1061 * Get the content of the value attribute of the first matched element.
1063 * Use caution when relying on this function to check the value of
1064 * multiple-select elements and checkboxes in a form. While it will
1065 * still work as intended, it may not accurately represent the value
1066 * the server will receive because these elements may send an array
1067 * of values. For more robust handling of field values, see the
1068 * [http://www.malsup.com/jquery/form/#fields fieldValue function of the Form Plugin].
1070 * @example $("input").val();
1071 * @before <input type="text" value="some text"/>
1072 * @result "some text"
1076 * @cat DOM/Attributes
1080 * Set the value attribute of every matched element.
1082 * @example $("input").val("test");
1083 * @before <input type="text" value="some text"/>
1084 * @result <input type="text" value="test"/>
1088 * @param String val Set the property to the specified value.
1089 * @cat DOM/Attributes
1091 val: function( val ) {
1092 return val == undefined ?
1093 ( this.length ? this[0].value : null ) :
1094 this.attr( "value", val );
1098 * Get the html contents of the first matched element.
1099 * This property is not available on XML documents.
1101 * @example $("div").html();
1102 * @before <div><input/></div>
1107 * @cat DOM/Attributes
1111 * Set the html contents of every matched element.
1112 * This property is not available on XML documents.
1114 * @example $("div").html("<b>new stuff</b>");
1115 * @before <div><input/></div>
1116 * @result <div><b>new stuff</b></div>
1120 * @param String val Set the html contents to the specified value.
1121 * @cat DOM/Attributes
1123 html: function( val ) {
1124 return val == undefined ?
1125 ( this.length ? this[0].innerHTML : null ) :
1126 this.empty().append( val );
1133 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1134 * @param Number dir If dir<0, process args in reverse order.
1135 * @param Function fn The function doing the DOM manipulation.
1139 domManip: function(args, table, dir, fn){
1140 var clone = this.length > 1, a;
1142 return this.each(function(){
1144 a = jQuery.clean(args, this.ownerDocument);
1151 if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
1152 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1154 jQuery.each( a, function(){
1155 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
1163 * Extends the jQuery object itself. Can be used to add functions into
1164 * the jQuery namespace and to [[Plugins/Authoring|add plugin methods]] (plugins).
1166 * @example jQuery.fn.extend({
1167 * check: function() {
1168 * return this.each(function() { this.checked = true; });
1170 * uncheck: function() {
1171 * return this.each(function() { this.checked = false; });
1174 * $("input[@type=checkbox]").check();
1175 * $("input[@type=radio]").uncheck();
1176 * @desc Adds two plugin methods.
1178 * @example jQuery.extend({
1179 * min: function(a, b) { return a < b ? a : b; },
1180 * max: function(a, b) { return a > b ? a : b; }
1182 * @desc Adds two functions into the jQuery namespace
1185 * @param Object prop The object that will be merged into the jQuery object
1191 * Extend one object with one or more others, returning the original,
1192 * modified, object. This is a great utility for simple inheritance.
1194 * @example var settings = { validate: false, limit: 5, name: "foo" };
1195 * var options = { validate: true, name: "bar" };
1196 * jQuery.extend(settings, options);
1197 * @result settings == { validate: true, limit: 5, name: "bar" }
1198 * @desc Merge settings and options, modifying settings
1200 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1201 * var options = { validate: true, name: "bar" };
1202 * var settings = jQuery.extend({}, defaults, options);
1203 * @result settings == { validate: true, limit: 5, name: "bar" }
1204 * @desc Merge defaults and options, without modifying the defaults
1207 * @param Object target The object to extend
1208 * @param Object prop1 The object that will be merged into the first.
1209 * @param Object propN (optional) More objects to merge into the first
1213 jQuery.extend = jQuery.fn.extend = function() {
1214 // copy reference to target object
1215 var target = arguments[0], a = 1;
1217 // extend jQuery itself if only one argument is passed
1218 if ( arguments.length == 1 ) {
1223 while ( (prop = arguments[a++]) != null )
1224 // Extend the base object
1225 for ( var i in prop ) target[i] = prop[i];
1227 // Return the modified object
1233 * Run this function to give control of the $ variable back
1234 * to whichever library first implemented it. This helps to make
1235 * sure that jQuery doesn't conflict with the $ object
1236 * of other libraries.
1238 * By using this function, you will only be able to access jQuery
1239 * using the 'jQuery' variable. For example, where you used to do
1240 * $("div p"), you now must do jQuery("div p").
1242 * @example jQuery.noConflict();
1243 * // Do something with jQuery
1244 * jQuery("div p").hide();
1245 * // Do something with another library's $()
1246 * $("content").style.display = 'none';
1247 * @desc Maps the original object that was referenced by $ back to $
1249 * @example jQuery.noConflict();
1252 * // more code using $ as alias to jQuery
1255 * // other code using $ as an alias to the other library
1256 * @desc Reverts the $ alias and then creates and executes a
1257 * function to provide the $ as a jQuery alias inside the functions
1258 * scope. Inside the function the original $ object is not available.
1259 * This works well for most plugins that don't rely on any other library.
1262 * @name $.noConflict
1266 noConflict: function() {
1272 // This may seem like some crazy code, but trust me when I say that this
1273 // is the only cross-browser way to do this. --John
1274 isFunction: function( fn ) {
1275 return !!fn && typeof fn != "string" && !fn.nodeName &&
1276 fn.constructor != Array && /function/i.test( fn + "" );
1279 // check if an element is in a XML document
1280 isXMLDoc: function(elem) {
1281 return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
1284 nodeName: function( elem, name ) {
1285 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
1289 * A generic iterator function, which can be used to seamlessly
1290 * iterate over both objects and arrays. This function is not the same
1291 * as $().each() - which is used to iterate, exclusively, over a jQuery
1292 * object. This function can be used to iterate over anything.
1294 * The callback has two arguments:the key (objects) or index (arrays) as first
1295 * the first, and the value as the second.
1297 * @example $.each( [0,1,2], function(i, n){
1298 * alert( "Item #" + i + ": " + n );
1300 * @desc This is an example of iterating over the items in an array,
1301 * accessing both the current item and its index.
1303 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1304 * alert( "Name: " + i + ", Value: " + n );
1307 * @desc This is an example of iterating over the properties in an
1308 * Object, accessing both the current item and its key.
1311 * @param Object obj The object, or array, to iterate over.
1312 * @param Function fn The function that will be executed on every object.
1316 // args is for internal usage only
1317 each: function( obj, fn, args ) {
1318 if ( obj.length == undefined )
1319 for ( var i in obj )
1320 fn.apply( obj[i], args || [i, obj[i]] );
1322 for ( var i = 0, ol = obj.length; i < ol; i++ )
1323 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1327 prop: function(elem, value, type, index, prop){
1328 // Handle executable functions
1329 if ( jQuery.isFunction( value ) )
1330 value = value.call( elem, [index] );
1332 // exclude the following css properties to add px
1333 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
1335 // Handle passing in a number to a CSS property
1336 return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
1342 // internal only, use addClass("class")
1343 add: function( elem, c ){
1344 jQuery.each( c.split(/\s+/), function(i, cur){
1345 if ( !jQuery.className.has( elem.className, cur ) )
1346 elem.className += ( elem.className ? " " : "" ) + cur;
1350 // internal only, use removeClass("class")
1351 remove: function( elem, c ){
1352 elem.className = c != undefined ?
1353 jQuery.grep( elem.className.split(/\s+/), function(cur){
1354 return !jQuery.className.has( c, cur );
1358 // internal only, use is(".class")
1359 has: function( t, c ) {
1360 return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1;
1365 * Swap in/out style options.
1368 swap: function(e,o,f) {
1369 for ( var i in o ) {
1370 e.style["old"+i] = e.style[i];
1375 e.style[i] = e.style["old"+i];
1378 css: function(e,p) {
1379 if ( p == "height" || p == "width" ) {
1380 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1382 jQuery.each( d, function(){
1383 old["padding" + this] = 0;
1384 old["border" + this + "Width"] = 0;
1387 jQuery.swap( e, old, function() {
1388 if ( jQuery(e).is(':visible') ) {
1389 oHeight = e.offsetHeight;
1390 oWidth = e.offsetWidth;
1392 e = jQuery(e.cloneNode(true))
1393 .find(":radio").removeAttr("checked").end()
1395 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1396 }).appendTo(e.parentNode)[0];
1398 var parPos = jQuery.css(e.parentNode,"position") || "static";
1399 if ( parPos == "static" )
1400 e.parentNode.style.position = "relative";
1402 oHeight = e.clientHeight;
1403 oWidth = e.clientWidth;
1405 if ( parPos == "static" )
1406 e.parentNode.style.position = "static";
1408 e.parentNode.removeChild(e);
1412 return p == "height" ? oHeight : oWidth;
1415 return jQuery.curCSS( e, p );
1418 curCSS: function(elem, prop, force) {
1421 if (prop == "opacity" && jQuery.browser.msie) {
1422 ret = jQuery.attr(elem.style, "opacity");
1423 return ret == "" ? "1" : ret;
1426 if (prop == "float" || prop == "cssFloat")
1427 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1429 if (!force && elem.style[prop])
1430 ret = elem.style[prop];
1432 else if (document.defaultView && document.defaultView.getComputedStyle) {
1434 if (prop == "cssFloat" || prop == "styleFloat")
1437 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1438 var cur = document.defaultView.getComputedStyle(elem, null);
1441 ret = cur.getPropertyValue(prop);
1442 else if ( prop == "display" )
1445 jQuery.swap(elem, { display: "block" }, function() {
1446 var c = document.defaultView.getComputedStyle(this, "");
1447 ret = c && c.getPropertyValue(prop) || "";
1450 } else if (elem.currentStyle) {
1451 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1452 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1458 clean: function(a, doc) {
1460 doc = doc || document;
1462 jQuery.each( a, function(i,arg){
1465 if ( arg.constructor == Number )
1466 arg = arg.toString();
1468 // Convert html string into DOM nodes
1469 if ( typeof arg == "string" ) {
1470 // Trim whitespace, otherwise indexOf won't work as expected
1471 var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = [];
1474 // option or optgroup
1475 !s.indexOf("<opt") &&
1476 [1, "<select>", "</select>"] ||
1478 !s.indexOf("<leg") &&
1479 [1, "<fieldset>", "</fieldset>"] ||
1481 (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot") || !s.indexOf("<colg")) &&
1482 [1, "<table>", "</table>"] ||
1484 !s.indexOf("<tr") &&
1485 [2, "<table><tbody>", "</tbody></table>"] ||
1487 // <thead> matched above
1488 (!s.indexOf("<td") || !s.indexOf("<th")) &&
1489 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1491 !s.indexOf("<col") &&
1492 [2, "<table><colgroup>", "</colgroup></table>"] ||
1496 // Go to html and back, then peel off extra wrappers
1497 div.innerHTML = wrap[1] + arg + wrap[2];
1499 // Move to the right depth
1501 div = div.firstChild;
1503 // Remove IE's autoinserted <tbody> from table fragments
1504 if ( jQuery.browser.msie ) {
1506 // String was a <table>, *may* have spurious <tbody>
1507 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
1508 tb = div.firstChild && div.firstChild.childNodes;
1510 // String was a bare <thead> or <tfoot>
1511 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1512 tb = div.childNodes;
1514 for ( var n = tb.length-1; n >= 0 ; --n )
1515 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
1516 tb[n].parentNode.removeChild(tb[n]);
1520 arg = jQuery.makeArray( div.childNodes );
1523 if ( 0 === arg.length && !jQuery(arg).is("form, select") )
1526 if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options )
1529 r = jQuery.merge( r, arg );
1536 attr: function(elem, name, value){
1537 var fix = jQuery.isXMLDoc(elem) ? {} : {
1539 "class": "className",
1540 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1541 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1542 innerHTML: "innerHTML",
1543 className: "className",
1545 disabled: "disabled",
1547 readonly: "readOnly",
1548 selected: "selected",
1549 maxlength: "maxLength"
1552 // IE actually uses filters for opacity ... elem is actually elem.style
1553 if ( name == "opacity" && jQuery.browser.msie ) {
1554 if ( value != undefined ) {
1555 // IE has trouble with opacity if it does not have layout
1556 // Force it by setting the zoom level
1559 // Set the alpha filter to set the opacity
1560 elem.filter = (elem.filter || "").replace(/alpha\([^)]*\)/,"") +
1561 (parseFloat(value).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1564 return elem.filter ?
1565 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : "";
1568 // Certain attributes only work when accessed via the old DOM 0 way
1570 if ( value != undefined ) elem[fix[name]] = value;
1571 return elem[fix[name]];
1573 } else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
1574 return elem.getAttributeNode(name).nodeValue;
1576 // IE elem.getAttribute passes even for style
1577 else if ( elem.tagName ) {
1578 if ( value != undefined ) elem.setAttribute( name, value );
1579 if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) )
1580 return elem.getAttribute( name, 2 );
1581 return elem.getAttribute( name );
1583 // elem is actually elem.style ... set the style
1585 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1586 if ( value != undefined ) elem[name] = value;
1592 * Remove the whitespace from the beginning and end of a string.
1594 * @example $.trim(" hello, how are you? ");
1595 * @result "hello, how are you?"
1599 * @param String str The string to trim.
1603 return t.replace(/^\s+|\s+$/g, "");
1606 makeArray: function( a ) {
1609 // Need to use typeof to fight Safari childNodes crashes
1610 if ( typeof a != "array" )
1611 for ( var i = 0, al = a.length; i < al; i++ )
1619 inArray: function( b, a ) {
1620 for ( var i = 0, al = a.length; i < al; i++ )
1627 * Merge two arrays together, removing all duplicates.
1629 * The result is the altered first argument with
1630 * the unique elements from the second array added.
1632 * @example $.merge( [0,1,2], [2,3,4] )
1633 * @result [0,1,2,3,4]
1634 * @desc Merges two arrays, removing the duplicate 2
1636 * @example var array = [3,2,1];
1637 * $.merge( array, [4,3,2] )
1638 * @result array == [3,2,1,4]
1639 * @desc Merges two arrays, removing the duplicates 3 and 2
1643 * @param Array first The first array to merge, the unique elements of second added.
1644 * @param Array second The second array to merge into the first, unaltered.
1647 merge: function(first, second) {
1648 // We have to loop this way because IE & Opera overwrite the length
1649 // expando of getElementsByTagName
1650 for ( var i = 0; second[i]; i++ )
1651 first.push(second[i]);
1655 unique: function(first) {
1656 var r = [], num = jQuery.mergeNum++;
1658 for ( var i = 0, fl = first.length; i < fl; i++ )
1659 if ( num != first[i].mergeNum ) {
1660 first[i].mergeNum = num;
1670 * Filter items out of an array, by using a filter function.
1672 * The specified function will be passed two arguments: The
1673 * current array item and the index of the item in the array. The
1674 * function must return 'true' to keep the item in the array,
1675 * false to remove it.
1677 * @example $.grep( [0,1,2], function(i){
1684 * @param Array array The Array to find items in.
1685 * @param Function fn The function to process each item against.
1686 * @param Boolean inv Invert the selection - select the opposite of the function.
1689 grep: function(elems, fn, inv) {
1690 // If a string is passed in for the function, make a function
1691 // for it (a handy shortcut)
1692 if ( typeof fn == "string" )
1693 fn = new Function("a","i","return " + fn);
1697 // Go through the array, only saving the items
1698 // that pass the validator function
1699 for ( var i = 0, el = elems.length; i < el; i++ )
1700 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1701 result.push( elems[i] );
1707 * Translate all items in an array to another array of items.
1709 * The translation function that is provided to this method is
1710 * called for each item in the array and is passed one argument:
1711 * The item to be translated.
1713 * The function can then return the translated value, 'null'
1714 * (to remove the item), or an array of values - which will
1715 * be flattened into the full array.
1717 * @example $.map( [0,1,2], function(i){
1721 * @desc Maps the original array to a new one and adds 4 to each value.
1723 * @example $.map( [0,1,2], function(i){
1724 * return i > 0 ? i + 1 : null;
1727 * @desc Maps the original array to a new one and adds 1 to each
1728 * value if it is bigger then zero, otherwise it's removed-
1730 * @example $.map( [0,1,2], function(i){
1731 * return [ i, i + 1 ];
1733 * @result [0, 1, 1, 2, 2, 3]
1734 * @desc Maps the original array to a new one, each element is added
1735 * with it's original value and the value plus one.
1739 * @param Array array The Array to translate.
1740 * @param Function fn The function to process each item against.
1743 map: function(elems, fn) {
1744 // If a string is passed in for the function, make a function
1745 // for it (a handy shortcut)
1746 if ( typeof fn == "string" )
1747 fn = new Function("a","return " + fn);
1749 var result = [], r = [];
1751 // Go through the array, translating each of the items to their
1752 // new value (or values).
1753 for ( var i = 0, el = elems.length; i < el; i++ ) {
1754 var val = fn(elems[i],i);
1756 if ( val !== null && val != undefined ) {
1757 if ( val.constructor != Array ) val = [val];
1758 result = result.concat( val );
1767 * Contains flags for the useragent, read from navigator.userAgent.
1768 * Available flags are: safari, opera, msie, mozilla
1770 * This property is available before the DOM is ready, therefore you can
1771 * use it to add ready events only for certain browsers.
1773 * There are situations where object detections is not reliable enough, in that
1774 * cases it makes sense to use browser detection. Simply try to avoid both!
1776 * A combination of browser and object detection yields quite reliable results.
1778 * @example $.browser.msie
1779 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1781 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1782 * @desc Alerts "this is safari!" only for safari browsers
1791 * Whether the W3C compliant box model is being used.
1799 var b = navigator.userAgent.toLowerCase();
1801 // Figure out what browser is being used
1803 version: b.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1],
1804 safari: /webkit/.test(b),
1805 opera: /opera/.test(b),
1806 msie: /msie/.test(b) && !/opera/.test(b),
1807 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1810 // Check to see if the W3C box model is being used
1811 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1815 * Get a set of elements containing the unique parents of the matched
1818 * You may use an optional expression to filter the set of parent elements that will match.
1820 * @example $("p").parent()
1821 * @before <div><p>Hello</p><p>Hello</p></div>
1822 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1823 * @desc Find the parent element of each paragraph.
1825 * @example $("p").parent(".selected")
1826 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1827 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1828 * @desc Find the parent element of each paragraph with a class "selected".
1832 * @param String expr (optional) An expression to filter the parents with
1833 * @cat DOM/Traversing
1837 * Get a set of elements containing the unique ancestors of the matched
1838 * set of elements (except for the root element).
1840 * The matched elements can be filtered with an optional expression.
1842 * @example $("span").parents()
1843 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1844 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1845 * @desc Find all parent elements of each span.
1847 * @example $("span").parents("p")
1848 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1849 * @result [ <p><span>Hello</span></p> ]
1850 * @desc Find all parent elements of each span that is a paragraph.
1854 * @param String expr (optional) An expression to filter the ancestors with
1855 * @cat DOM/Traversing
1859 * Get a set of elements containing the unique next siblings of each of the
1860 * matched set of elements.
1862 * It only returns the very next sibling for each element, not all
1865 * You may provide an optional expression to filter the match.
1867 * @example $("p").next()
1868 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1869 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1870 * @desc Find the very next sibling of each paragraph.
1872 * @example $("p").next(".selected")
1873 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1874 * @result [ <p class="selected">Hello Again</p> ]
1875 * @desc Find the very next sibling of each paragraph that has a class "selected".
1879 * @param String expr (optional) An expression to filter the next Elements with
1880 * @cat DOM/Traversing
1884 * Get a set of elements containing the unique previous siblings of each of the
1885 * matched set of elements.
1887 * Use an optional expression to filter the matched set.
1889 * Only the immediately previous sibling is returned, not all previous siblings.
1891 * @example $("p").prev()
1892 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1893 * @result [ <div><span>Hello Again</span></div> ]
1894 * @desc Find the very previous sibling of each paragraph.
1896 * @example $("p").prev(".selected")
1897 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1898 * @result [ <div><span>Hello</span></div> ]
1899 * @desc Find the very previous sibling of each paragraph that has a class "selected".
1903 * @param String expr (optional) An expression to filter the previous Elements with
1904 * @cat DOM/Traversing
1908 * Get a set of elements containing all of the unique siblings of each of the
1909 * matched set of elements.
1911 * Can be filtered with an optional expressions.
1913 * @example $("div").siblings()
1914 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1915 * @result [ <p>Hello</p>, <p>And Again</p> ]
1916 * @desc Find all siblings of each div.
1918 * @example $("div").siblings(".selected")
1919 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1920 * @result [ <p class="selected">Hello Again</p> ]
1921 * @desc Find all siblings with a class "selected" of each div.
1925 * @param String expr (optional) An expression to filter the sibling Elements with
1926 * @cat DOM/Traversing
1930 * Get a set of elements containing all of the unique children of each of the
1931 * matched set of elements.
1933 * This set can be filtered with an optional expression that will cause
1934 * only elements matching the selector to be collected.
1936 * @example $("div").children()
1937 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1938 * @result [ <span>Hello Again</span> ]
1939 * @desc Find all children of each div.
1941 * @example $("div").children(".selected")
1942 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1943 * @result [ <p class="selected">Hello Again</p> ]
1944 * @desc Find all children with a class "selected" of each div.
1948 * @param String expr (optional) An expression to filter the child Elements with
1949 * @cat DOM/Traversing
1952 parent: "a.parentNode",
1953 parents: "jQuery.parents(a)",
1954 next: "jQuery.nth(a,2,'nextSibling')",
1955 prev: "jQuery.nth(a,2,'previousSibling')",
1956 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1957 children: "jQuery.sibling(a.firstChild)"
1959 jQuery.fn[ i ] = function(a) {
1960 var ret = jQuery.map(this,n);
1961 if ( a && typeof a == "string" )
1962 ret = jQuery.multiFilter(a,ret);
1963 return this.pushStack( ret );
1968 * Append all of the matched elements to another, specified, set of elements.
1969 * This operation is, essentially, the reverse of doing a regular
1970 * $(A).append(B), in that instead of appending B to A, you're appending
1973 * @example $("p").appendTo("#foo");
1974 * @before <p>I would like to say: </p><div id="foo"></div>
1975 * @result <div id="foo"><p>I would like to say: </p></div>
1976 * @desc Appends all paragraphs to the element with the ID "foo"
1980 * @param <Content> content Content to append to the selected element to.
1981 * @cat DOM/Manipulation
1982 * @see append(<Content>)
1986 * Prepend all of the matched elements to another, specified, set of elements.
1987 * This operation is, essentially, the reverse of doing a regular
1988 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1991 * @example $("p").prependTo("#foo");
1992 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1993 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1994 * @desc Prepends all paragraphs to the element with the ID "foo"
1998 * @param <Content> content Content to prepend to the selected element to.
1999 * @cat DOM/Manipulation
2000 * @see prepend(<Content>)
2004 * Insert all of the matched elements before another, specified, set of elements.
2005 * This operation is, essentially, the reverse of doing a regular
2006 * $(A).before(B), in that instead of inserting B before A, you're inserting
2009 * @example $("p").insertBefore("#foo");
2010 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2011 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2012 * @desc Same as $("#foo").before("p")
2014 * @name insertBefore
2016 * @param <Content> content Content to insert the selected element before.
2017 * @cat DOM/Manipulation
2018 * @see before(<Content>)
2022 * Insert all of the matched elements after another, specified, set of elements.
2023 * This operation is, essentially, the reverse of doing a regular
2024 * $(A).after(B), in that instead of inserting B after A, you're inserting
2027 * @example $("p").insertAfter("#foo");
2028 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2029 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2030 * @desc Same as $("#foo").after("p")
2034 * @param <Content> content Content to insert the selected element after.
2035 * @cat DOM/Manipulation
2036 * @see after(<Content>)
2041 prependTo: "prepend",
2042 insertBefore: "before",
2043 insertAfter: "after"
2045 jQuery.fn[ i ] = function(){
2047 return this.each(function(){
2048 for ( var j = 0, al = a.length; j < al; j++ )
2049 jQuery(a[j])[n]( this );
2055 * Remove an attribute from each of the matched elements.
2057 * @example $("input").removeAttr("disabled")
2058 * @before <input disabled="disabled"/>
2063 * @param String name The name of the attribute to remove.
2064 * @cat DOM/Attributes
2068 * Adds the specified class(es) to each of the set of matched elements.
2070 * @example $("p").addClass("selected")
2071 * @before <p>Hello</p>
2072 * @result [ <p class="selected">Hello</p> ]
2074 * @example $("p").addClass("selected highlight")
2075 * @before <p>Hello</p>
2076 * @result [ <p class="selected highlight">Hello</p> ]
2080 * @param String class One or more CSS classes to add to the elements
2081 * @cat DOM/Attributes
2082 * @see removeClass(String)
2086 * Removes all or the specified class(es) from the set of matched elements.
2088 * @example $("p").removeClass()
2089 * @before <p class="selected">Hello</p>
2090 * @result [ <p>Hello</p> ]
2092 * @example $("p").removeClass("selected")
2093 * @before <p class="selected first">Hello</p>
2094 * @result [ <p class="first">Hello</p> ]
2096 * @example $("p").removeClass("selected highlight")
2097 * @before <p class="highlight selected first">Hello</p>
2098 * @result [ <p class="first">Hello</p> ]
2102 * @param String class (optional) One or more CSS classes to remove from the elements
2103 * @cat DOM/Attributes
2104 * @see addClass(String)
2108 * Adds the specified class if it is not present, removes it if it is
2111 * @example $("p").toggleClass("selected")
2112 * @before <p>Hello</p><p class="selected">Hello Again</p>
2113 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2117 * @param String class A CSS class with which to toggle the elements
2118 * @cat DOM/Attributes
2122 * Removes all matched elements from the DOM. This does NOT remove them from the
2123 * jQuery object, allowing you to use the matched elements further.
2125 * Can be filtered with an optional expressions.
2127 * @example $("p").remove();
2128 * @before <p>Hello</p> how are <p>you?</p>
2131 * @example $("p").remove(".hello");
2132 * @before <p class="hello">Hello</p> how are <p>you?</p>
2133 * @result how are <p>you?</p>
2137 * @param String expr (optional) A jQuery expression to filter elements by.
2138 * @cat DOM/Manipulation
2142 * Removes all child nodes from the set of matched elements.
2144 * @example $("p").empty()
2145 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2146 * @result [ <p></p> ]
2150 * @cat DOM/Manipulation
2154 removeAttr: function( key ) {
2155 jQuery.attr( this, key, "" );
2156 this.removeAttribute( key );
2158 addClass: function(c){
2159 jQuery.className.add(this,c);
2161 removeClass: function(c){
2162 jQuery.className.remove(this,c);
2164 toggleClass: function( c ){
2165 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2167 remove: function(a){
2168 if ( !a || jQuery.filter( a, [this] ).r.length )
2169 this.parentNode.removeChild( this );
2172 while ( this.firstChild )
2173 this.removeChild( this.firstChild );
2176 jQuery.fn[ i ] = function() {
2177 return this.each( n, arguments );
2182 * Reduce the set of matched elements to a single element.
2183 * The position of the element in the set of matched elements
2184 * starts at 0 and goes to length - 1.
2186 * @example $("p").eq(1)
2187 * @before <p>This is just a test.</p><p>So is this</p>
2188 * @result [ <p>So is this</p> ]
2192 * @param Number pos The index of the element that you wish to limit to.
2197 * Reduce the set of matched elements to all elements before a given position.
2198 * The position of the element in the set of matched elements
2199 * starts at 0 and goes to length - 1.
2201 * @example $("p").lt(1)
2202 * @before <p>This is just a test.</p><p>So is this</p>
2203 * @result [ <p>This is just a test.</p> ]
2207 * @param Number pos Reduce the set to all elements below this position.
2212 * Reduce the set of matched elements to all elements after a given position.
2213 * The position of the element in the set of matched elements
2214 * starts at 0 and goes to length - 1.
2216 * @example $("p").gt(0)
2217 * @before <p>This is just a test.</p><p>So is this</p>
2218 * @result [ <p>So is this</p> ]
2222 * @param Number pos Reduce the set to all elements after this position.
2227 * Filter the set of elements to those that contain the specified text.
2229 * @example $("p").contains("test")
2230 * @before <p>This is just a test.</p><p>So is this</p>
2231 * @result [ <p>This is just a test.</p> ]
2235 * @param String str The string that will be contained within the text of an element.
2236 * @cat DOM/Traversing
2238 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2239 jQuery.fn[ n ] = function(num,fn) {
2240 return this.filter( ":" + n + "(" + num + ")", fn );
2245 * Get the current computed, pixel, width of the first matched element.
2247 * @example $("p").width();
2248 * @before <p>This is just a test.</p>
2257 * Set the CSS width of every matched element. If no explicit unit
2258 * was specified (like 'em' or '%') then "px" is added to the width.
2260 * @example $("p").width(20);
2261 * @before <p>This is just a test.</p>
2262 * @result <p style="width:20px;">This is just a test.</p>
2264 * @example $("p").width("20em");
2265 * @before <p>This is just a test.</p>
2266 * @result <p style="width:20em;">This is just a test.</p>
2270 * @param String|Number val Set the CSS property to the specified value.
2275 * Get the current computed, pixel, height of the first matched element.
2277 * @example $("p").height();
2278 * @before <p>This is just a test.</p>
2287 * Set the CSS height of every matched element. If no explicit unit
2288 * was specified (like 'em' or '%') then "px" is added to the width.
2290 * @example $("p").height(20);
2291 * @before <p>This is just a test.</p>
2292 * @result <p style="height:20px;">This is just a test.</p>
2294 * @example $("p").height("20em");
2295 * @before <p>This is just a test.</p>
2296 * @result <p style="height:20em;">This is just a test.</p>
2300 * @param String|Number val Set the CSS property to the specified value.
2304 jQuery.each( [ "height", "width" ], function(i,n){
2305 jQuery.fn[ n ] = function(h) {
2306 return h == undefined ?
2307 ( this.length ? jQuery.css( this[0], n ) : null ) :
2308 this.css( n, h.constructor == String ? h : h + "px" );