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 // Make sure that a selection was provided
33 // HANDLE: $(function)
34 // Shortcut for document ready
35 if ( jQuery.isFunction(a) )
36 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
38 // Handle HTML strings
39 if ( typeof a == "string" ) {
40 // HANDLE: $(html) -> $(array)
41 var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a);
43 a = jQuery.clean( [ m[1] ] );
47 return new jQuery( c ).find( a );
52 a.constructor == Array && a ||
54 // HANDLE: $(arraylike)
55 // Watch for when an array-like object is passed as the selector
56 (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
62 // Map over the $ in case of overwrite
63 if ( typeof $ != "undefined" )
66 // Map the jQuery namespace to the '$' one
70 * This function accepts a string containing a CSS or
71 * basic XPath selector which is then used to match a set of elements.
73 * The core functionality of jQuery centers around this function.
74 * Everything in jQuery is based upon this, or uses this in some way.
75 * The most basic use of this function is to pass in an expression
76 * (usually consisting of CSS or XPath), which then finds all matching
79 * By default, if no context is specified, $() looks for DOM elements within the context of the
80 * current HTML document. If you do specify a context, such as a DOM
81 * element or jQuery object, the expression will be matched against
82 * the contents of that context.
84 * See [[DOM/Traversing/Selectors]] for the allowed CSS/XPath syntax for expressions.
86 * @example $("div > p")
87 * @desc Finds all p elements that are children of a div element.
88 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
89 * @result [ <p>two</p> ]
91 * @example $("input:radio", document.forms[0])
92 * @desc Searches for all inputs of type radio within the first form in the document
94 * @example $("div", xml.responseXML)
95 * @desc This finds all div elements within the specified XML document.
98 * @param String expr An expression to search with
99 * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
103 * @see $(Element<Array>)
107 * Create DOM elements on-the-fly from the provided String of raw HTML.
109 * @example $("<div><p>Hello</p></div>").appendTo("body")
110 * @desc Creates a div element (and all of its contents) dynamically,
111 * and appends it to the body element. Internally, an
112 * element is created and its innerHTML property set to the given markup.
113 * It is therefore both quite flexible and limited.
116 * @param String html A string of HTML to create on the fly.
119 * @see appendTo(String)
123 * Wrap jQuery functionality around a single or multiple DOM Element(s).
125 * This function also accepts XML Documents and Window objects
126 * as valid arguments (even though they are not DOM Elements).
128 * @example $(document.body).css( "background", "black" );
129 * @desc Sets the background color of the page to black.
131 * @example $( myForm.elements ).hide()
132 * @desc Hides all the input elements within a form
135 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
141 * A shorthand for $(document).ready(), allowing you to bind a function
142 * to be executed when the DOM document has finished loading. This function
143 * behaves just like $(document).ready(), in that it should be used to wrap
144 * other $() operations on your page that depend on the DOM being ready to be
145 * operated on. While this function is, technically, chainable - there really
146 * 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.
157 * @example jQuery(function($) {
158 * // Your code using failsafe $ alias here...
160 * @desc Uses both the shortcut for $(document).ready() and the argument
161 * to write failsafe jQuery code using the $ alias, without relying on the
165 * @param Function fn The function to execute when the DOM is ready.
168 * @see ready(Function)
171 jQuery.fn = jQuery.prototype = {
173 * The current version of jQuery.
184 * The number of elements currently matched. The size function will return the same value.
186 * @example $("img").length;
187 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
197 * Get the number of elements currently matched. This returns the same
198 * number as the 'length' property of the jQuery object.
200 * @example $("img").size();
201 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
215 * Access all matched DOM elements. This serves as a backwards-compatible
216 * way of accessing all matched elements (other than the jQuery object
217 * itself, which is, in fact, an array of elements).
219 * It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions.
221 * @example $("img").get();
222 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
223 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
224 * @desc Selects all images in the document and returns the DOM Elements as an Array
227 * @type Array<Element>
232 * Access a single matched DOM element at a specified index in the matched set.
233 * This allows you to extract the actual DOM element and operate on it
234 * directly without necessarily using jQuery functionality on it.
236 * @example $("img").get(0);
237 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
238 * @result <img src="test1.jpg"/>
239 * @desc Selects all images in the document and returns the first one
243 * @param Number num Access the element in the Nth position.
246 get: function( num ) {
247 return num == undefined ?
249 // Return a 'clean' array
250 jQuery.makeArray( this ) :
252 // Return just the object
257 * Set the jQuery object to an array of elements, while maintaining
260 * @example $("img").pushStack([ document.body ]);
261 * @result $("img").pushStack() == [ document.body ]
266 * @param Elements elems An array of elements
269 pushStack: function( a ) {
271 ret.prevObject = this;
276 * Set the jQuery object to an array of elements. This operation is
277 * completely destructive - be sure to use .pushStack() if you wish to maintain
280 * @example $("img").setArray([ document.body ]);
281 * @result $("img").setArray() == [ document.body ]
286 * @param Elements elems An array of elements
289 setArray: function( a ) {
291 [].push.apply( this, a );
296 * Execute a function within the context of every matched element.
297 * This means that every time the passed-in function is executed
298 * (which is once for every element matched) the 'this' keyword
299 * points to the specific DOM element.
301 * Additionally, the function, when executed, is passed a single
302 * argument representing the position of the element in the matched
303 * set (integer, zero-index).
305 * @example $("img").each(function(i){
306 * this.src = "test" + i + ".jpg";
308 * @before <img/><img/>
309 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
310 * @desc Iterates over two images and sets their src property
314 * @param Function fn A function to execute
317 each: function( fn, args ) {
318 return jQuery.each( this, fn, args );
322 * Searches every matched element for the object and returns
323 * the index of the element, if found, starting with zero.
324 * Returns -1 if the object wasn't found.
326 * @example $("*").index( $('#foobar')[0] )
327 * @before <div id="foobar"><b></b><span id="foo"></span></div>
329 * @desc Returns the index for the element with ID foobar
331 * @example $("*").index( $('#foo')[0] )
332 * @before <div id="foobar"><b></b><span id="foo"></span></div>
334 * @desc Returns the index for the element with ID foo within another element
336 * @example $("*").index( $('#bar')[0] )
337 * @before <div id="foobar"><b></b><span id="foo"></span></div>
339 * @desc Returns -1, as there is no element with ID bar
343 * @param Element subject Object to search for
346 index: function( obj ) {
348 this.each(function(i){
349 if ( this == obj ) pos = i;
355 * Access a property on the first matched element.
356 * This method makes it easy to retrieve a property value
357 * from the first matched element.
359 * If the element does not have an attribute with such a
360 * name, undefined is returned.
362 * @example $("img").attr("src");
363 * @before <img src="test.jpg"/>
365 * @desc Returns the src attribute from the first image in the document.
369 * @param String name The name of the property to access.
370 * @cat DOM/Attributes
374 * Set a key/value object as properties to all matched elements.
376 * This serves as the best way to set a large number of properties
377 * on all matched elements.
379 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
381 * @result <img src="test.jpg" alt="Test Image"/>
382 * @desc Sets src and alt attributes to all images.
386 * @param Map properties Key/value pairs to set as object properties.
387 * @cat DOM/Attributes
391 * Set a single property to a value, on all matched elements.
393 * Note that you can't set the name property of input elements in IE.
394 * Use $(html) or .append(html) or .html(html) to create elements
395 * on the fly including the name property.
397 * @example $("img").attr("src","test.jpg");
399 * @result <img src="test.jpg"/>
400 * @desc Sets src attribute to all images.
404 * @param String key The name of the property to set.
405 * @param Object value The value to set the property to.
406 * @cat DOM/Attributes
410 * Set a single property to a computed value, on all matched elements.
412 * Instead of supplying a string value as described
413 * [[DOM/Attributes#attr.28_key.2C_value_.29|above]],
414 * a function is provided that computes the value.
416 * @example $("img").attr("title", function() { return this.src });
417 * @before <img src="test.jpg" />
418 * @result <img src="test.jpg" title="test.jpg" />
419 * @desc Sets title attribute from src attribute.
421 * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
422 * @before <img title="pic" /><img title="pic" /><img title="pic" />
423 * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
424 * @desc Enumerate title attribute.
428 * @param String key The name of the property to set.
429 * @param Function value A function returning the value to set.
430 * Scope: Current element, argument: Index of current element
431 * @cat DOM/Attributes
433 attr: function( key, value, type ) {
436 // Look for the case where we're accessing a style value
437 if ( key.constructor == String )
438 if ( value == undefined )
439 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
445 // Check to see if we're setting style values
446 return this.each(function(index){
447 // Set all the styles
448 for ( var prop in obj )
450 type ? this.style : this,
451 prop, jQuery.prop(this, obj[prop], type, index, prop)
457 * Access a style property on the first matched element.
458 * This method makes it easy to retrieve a style property value
459 * from the first matched element.
461 * @example $("p").css("color");
462 * @before <p style="color:red;">Test Paragraph.</p>
464 * @desc Retrieves the color style of the first paragraph
466 * @example $("p").css("font-weight");
467 * @before <p style="font-weight: bold;">Test Paragraph.</p>
469 * @desc Retrieves the font-weight style of the first paragraph.
473 * @param String name The name of the property to access.
478 * Set a key/value object as style properties to all matched elements.
480 * This serves as the best way to set a large number of style properties
481 * on all matched elements.
483 * @example $("p").css({ color: "red", background: "blue" });
484 * @before <p>Test Paragraph.</p>
485 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
486 * @desc Sets color and background styles to all p elements.
490 * @param Map properties Key/value pairs to set as style properties.
495 * Set a single style property to a value, on all matched elements.
496 * If a number is provided, it is automatically converted into a pixel value.
498 * @example $("p").css("color","red");
499 * @before <p>Test Paragraph.</p>
500 * @result <p style="color:red;">Test Paragraph.</p>
501 * @desc Changes the color of all paragraphs to red
503 * @example $("p").css("left",30);
504 * @before <p>Test Paragraph.</p>
505 * @result <p style="left:30px;">Test Paragraph.</p>
506 * @desc Changes the left of all paragraphs to "30px"
510 * @param String key The name of the property to set.
511 * @param String|Number value The value to set the property to.
514 css: function( key, value ) {
515 return this.attr( key, value, "curCSS" );
519 * Get the text contents of all matched elements. The result is
520 * a string that contains the combined text contents of all matched
521 * elements. This method works on both HTML and XML documents.
523 * @example $("p").text();
524 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
525 * @result Test Paragraph.Paraparagraph
526 * @desc Gets the concatenated text of all paragraphs
530 * @cat DOM/Attributes
534 * Set the text contents of all matched elements.
536 * Similar to html(), but escapes HTML (replace "<" and ">" with their
539 * @example $("p").text("<b>Some</b> new text.");
540 * @before <p>Test Paragraph.</p>
541 * @result <p><b>Some</b> new text.</p>
542 * @desc Sets the text of all paragraphs.
544 * @example $("p").text("<b>Some</b> new text.", true);
545 * @before <p>Test Paragraph.</p>
546 * @result <p>Some new text.</p>
547 * @desc Sets the text of all paragraphs.
551 * @param String val The text value to set the contents of the element to.
552 * @cat DOM/Attributes
555 if ( typeof e == "string" )
556 return this.empty().append( document.createTextNode( e ) );
559 jQuery.each( e || this, function(){
560 jQuery.each( this.childNodes, function(){
561 if ( this.nodeType != 8 )
562 t += this.nodeType != 1 ?
563 this.nodeValue : jQuery.fn.text([ this ]);
570 * Wrap all matched elements with a structure of other elements.
571 * This wrapping process is most useful for injecting additional
572 * stucture into a document, without ruining the original semantic
573 * qualities of a document.
575 * This works by going through the first element
576 * provided (which is generated, on the fly, from the provided HTML)
577 * and finds the deepest ancestor element within its
578 * structure - it is that element that will en-wrap everything else.
580 * This does not work with elements that contain text. Any necessary text
581 * must be added after the wrapping is done.
583 * @example $("p").wrap("<div class='wrap'></div>");
584 * @before <p>Test Paragraph.</p>
585 * @result <div class='wrap'><p>Test Paragraph.</p></div>
589 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
590 * @cat DOM/Manipulation
594 * Wrap all matched elements with a structure of other elements.
595 * This wrapping process is most useful for injecting additional
596 * stucture into a document, without ruining the original semantic
597 * qualities of a document.
599 * This works by going through the first element
600 * provided and finding the deepest ancestor element within its
601 * structure - it is that element that will en-wrap everything else.
603 * This does not work with elements that contain text. Any necessary text
604 * must be added after the wrapping is done.
606 * @example $("p").wrap( document.getElementById('content') );
607 * @before <p>Test Paragraph.</p><div id="content"></div>
608 * @result <div id="content"><p>Test Paragraph.</p></div>
612 * @param Element elem A DOM element that will be wrapped around the target.
613 * @cat DOM/Manipulation
616 // The elements to wrap the target around
617 var a = jQuery.clean(arguments);
619 // Wrap each of the matched elements individually
620 return this.each(function(){
621 // Clone the structure that we're using to wrap
622 var b = a[0].cloneNode(true);
624 // Insert it before the element to be wrapped
625 this.parentNode.insertBefore( b, this );
627 // Find the deepest point in the wrap structure
628 while ( b.firstChild )
631 // Move the matched element to within the wrap structure
632 b.appendChild( this );
637 * Append content to the inside of every matched element.
639 * This operation is similar to doing an appendChild to all the
640 * specified elements, adding them into the document.
642 * @example $("p").append("<b>Hello</b>");
643 * @before <p>I would like to say: </p>
644 * @result <p>I would like to say: <b>Hello</b></p>
645 * @desc Appends some HTML to all paragraphs.
647 * @example $("p").append( $("#foo")[0] );
648 * @before <p>I would like to say: </p><b id="foo">Hello</b>
649 * @result <p>I would like to say: <b id="foo">Hello</b></p>
650 * @desc Appends an Element to all paragraphs.
652 * @example $("p").append( $("b") );
653 * @before <p>I would like to say: </p><b>Hello</b>
654 * @result <p>I would like to say: <b>Hello</b></p>
655 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
659 * @param <Content> content Content to append to the target
660 * @cat DOM/Manipulation
661 * @see prepend(<Content>)
662 * @see before(<Content>)
663 * @see after(<Content>)
666 return this.domManip(arguments, true, 1, function(a){
667 this.appendChild( a );
672 * Prepend content to the inside of every matched element.
674 * This operation is the best way to insert elements
675 * inside, at the beginning, of all matched elements.
677 * @example $("p").prepend("<b>Hello</b>");
678 * @before <p>I would like to say: </p>
679 * @result <p><b>Hello</b>I would like to say: </p>
680 * @desc Prepends some HTML to all paragraphs.
682 * @example $("p").prepend( $("#foo")[0] );
683 * @before <p>I would like to say: </p><b id="foo">Hello</b>
684 * @result <p><b id="foo">Hello</b>I would like to say: </p>
685 * @desc Prepends an Element to all paragraphs.
687 * @example $("p").prepend( $("b") );
688 * @before <p>I would like to say: </p><b>Hello</b>
689 * @result <p><b>Hello</b>I would like to say: </p>
690 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
694 * @param <Content> content Content to prepend to the target.
695 * @cat DOM/Manipulation
696 * @see append(<Content>)
697 * @see before(<Content>)
698 * @see after(<Content>)
700 prepend: function() {
701 return this.domManip(arguments, true, -1, function(a){
702 this.insertBefore( a, this.firstChild );
707 * Insert content before each of the matched elements.
709 * @example $("p").before("<b>Hello</b>");
710 * @before <p>I would like to say: </p>
711 * @result <b>Hello</b><p>I would like to say: </p>
712 * @desc Inserts some HTML before all paragraphs.
714 * @example $("p").before( $("#foo")[0] );
715 * @before <p>I would like to say: </p><b id="foo">Hello</b>
716 * @result <b id="foo">Hello</b><p>I would like to say: </p>
717 * @desc Inserts an Element before all paragraphs.
719 * @example $("p").before( $("b") );
720 * @before <p>I would like to say: </p><b>Hello</b>
721 * @result <b>Hello</b><p>I would like to say: </p>
722 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
726 * @param <Content> content Content to insert before each target.
727 * @cat DOM/Manipulation
728 * @see append(<Content>)
729 * @see prepend(<Content>)
730 * @see after(<Content>)
733 return this.domManip(arguments, false, 1, function(a){
734 this.parentNode.insertBefore( a, this );
739 * Insert content after each of the matched elements.
741 * @example $("p").after("<b>Hello</b>");
742 * @before <p>I would like to say: </p>
743 * @result <p>I would like to say: </p><b>Hello</b>
744 * @desc Inserts some HTML after all paragraphs.
746 * @example $("p").after( $("#foo")[0] );
747 * @before <b id="foo">Hello</b><p>I would like to say: </p>
748 * @result <p>I would like to say: </p><b id="foo">Hello</b>
749 * @desc Inserts an Element after all paragraphs.
751 * @example $("p").after( $("b") );
752 * @before <b>Hello</b><p>I would like to say: </p>
753 * @result <p>I would like to say: </p><b>Hello</b>
754 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
758 * @param <Content> content Content to insert after each target.
759 * @cat DOM/Manipulation
760 * @see append(<Content>)
761 * @see prepend(<Content>)
762 * @see before(<Content>)
765 return this.domManip(arguments, false, -1, function(a){
766 this.parentNode.insertBefore( a, this.nextSibling );
771 * Revert the most recent 'destructive' operation, changing the set of matched elements
772 * to its previous state (right before the destructive operation).
774 * If there was no destructive operation before, an empty set is returned.
776 * A 'destructive' operation is any operation that changes the set of
777 * matched jQuery elements. These functions are:
778 * These functions are:
782 * <code>children</code>
786 * <code>filter</code>
794 * <code>parent</code>
796 * <code>parents</code>
800 * <code>siblings</code>
802 * @example $("p").find("span").end();
803 * @before <p><span>Hello</span>, how are you?</p>
804 * @result [ <p>...</p> ]
805 * @desc Selects all paragraphs, finds span elements inside these, and reverts the
806 * selection back to the paragraphs.
810 * @cat DOM/Traversing
813 return this.prevObject || jQuery([]);
817 * Searches for all elements that match the specified expression.
819 * This method is a good way to find additional descendant
820 * elements with which to process.
822 * All searching is done using a jQuery expression. The expression can be
823 * written using CSS 1-3 Selector syntax, or basic XPath.
825 * @example $("p").find("span");
826 * @before <p><span>Hello</span>, how are you?</p>
827 * @result [ <span>Hello</span> ]
828 * @desc Starts with all paragraphs and searches for descendant span
829 * elements, same as $("p span")
833 * @param String expr An expression to search with.
834 * @cat DOM/Traversing
837 return this.pushStack( jQuery.map( this, function(a){
838 return jQuery.find(t,a);
843 * Clone matched DOM Elements and select the clones.
845 * This is useful for moving copies of the elements to another
846 * location in the DOM.
848 * @example $("b").clone().prependTo("p");
849 * @before <b>Hello</b><p>, how are you?</p>
850 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
851 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
855 * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
856 * @cat DOM/Manipulation
858 clone: function(deep) {
859 return this.pushStack( jQuery.map( this, function(a){
860 var a = a.cloneNode( deep != undefined ? deep : true );
861 a.$events = null; // drop $events expando to avoid firing incorrect events
867 * Removes all elements from the set of matched elements that do not
868 * match the specified expression(s). This method is used to narrow down
869 * the results of a search.
871 * Provide a comma-separated list of expressions to apply multiple filters at once.
873 * @example $("p").filter(".selected")
874 * @before <p class="selected">Hello</p><p>How are you?</p>
875 * @result [ <p class="selected">Hello</p> ]
876 * @desc Selects all paragraphs and removes those without a class "selected".
878 * @example $("p").filter(".selected, :first")
879 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
880 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
881 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
885 * @param String expression Expression(s) to search with.
886 * @cat DOM/Traversing
890 * Removes all elements from the set of matched elements that do not
891 * pass the specified filter. This method is used to narrow down
892 * the results of a search.
894 * @example $("p").filter(function(index) {
895 * return $("ol", this).length == 0;
897 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
898 * @result [ <p>How are you?</p> ]
899 * @desc Remove all elements that have a child ol element
903 * @param Function filter A function to use for filtering
904 * @cat DOM/Traversing
906 filter: function(t) {
907 return this.pushStack(
908 jQuery.isFunction( t ) &&
909 jQuery.grep(this, function(el, index){
910 return t.apply(el, [index])
913 jQuery.multiFilter(t,this) );
917 * Removes the specified Element from the set of matched elements. This
918 * method is used to remove a single Element from a jQuery object.
920 * @example $("p").not( $("#selected")[0] )
921 * @before <p>Hello</p><p id="selected">Hello Again</p>
922 * @result [ <p>Hello</p> ]
923 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
927 * @param Element el An element to remove from the set
928 * @cat DOM/Traversing
932 * Removes elements matching the specified expression from the set
933 * of matched elements. This method is used to remove one or more
934 * elements from a jQuery object.
936 * @example $("p").not("#selected")
937 * @before <p>Hello</p><p id="selected">Hello Again</p>
938 * @result [ <p>Hello</p> ]
939 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
943 * @param String expr An expression with which to remove matching elements
944 * @cat DOM/Traversing
948 * Removes any elements inside the array of elements from the set
949 * of matched elements. This method is used to remove one or more
950 * elements from a jQuery object.
952 * Please note: the expression cannot use a reference to the
953 * element name. See the two examples below.
955 * This will not work: $(".res img").not("img[@src$=on]")
957 * This will: $(".res img").not("[@src$=on]"); // also could be written $(".res img:not([@src$=on])")
959 * @example $("p").not( $("div p.selected") )
960 * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
961 * @result [ <p>Hello</p> ]
962 * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
966 * @param jQuery elems A set of elements to remove from the jQuery set of matched elements.
967 * @cat DOM/Traversing
970 return this.pushStack(
971 t.constructor == String &&
972 jQuery.multiFilter(t, this, true) ||
974 jQuery.grep(this, function(a) {
975 return ( t.constructor == Array || t.jquery )
976 ? jQuery.inArray( a, t ) < 0
983 * Adds more elements, matched by the given expression,
984 * to the set of matched elements.
986 * @example $("p").add("span")
987 * @before (HTML) <p>Hello</p><span>Hello Again</span>
988 * @result (jQuery object matching 2 elements) [ <p>Hello</p>, <span>Hello Again</span> ]
989 * @desc Compare the above result to the result of <code>$('p')</code>,
990 * which would just result in <code><nowiki>[ <p>Hello</p> ]</nowiki></code>.
991 * Using add(), matched elements of <code>$('span')</code> are simply
992 * added to the returned jQuery-object.
996 * @param String expr An expression whose matched elements are added
997 * @cat DOM/Traversing
1001 * Adds more elements, created on the fly, to the set of
1004 * @example $("p").add("<span>Again</span>")
1005 * @before <p>Hello</p>
1006 * @result [ <p>Hello</p>, <span>Again</span> ]
1010 * @param String html A string of HTML to create on the fly.
1011 * @cat DOM/Traversing
1015 * Adds one or more Elements to the set of matched elements.
1017 * @example $("p").add( document.getElementById("a") )
1018 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1019 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1021 * @example $("p").add( document.forms[0].elements )
1022 * @before <p>Hello</p><p><form><input/><button/></form>
1023 * @result [ <p>Hello</p>, <input/>, <button/> ]
1027 * @param Element|Array<Element> elements One or more Elements to add
1028 * @cat DOM/Traversing
1031 return this.pushStack( jQuery.merge(
1033 t.constructor == String ?
1035 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
1041 * Checks the current selection against an expression and returns true,
1042 * if at least one element of the selection fits the given expression.
1044 * Does return false, if no element fits or the expression is not valid.
1046 * filter(String) is used internally, therefore all rules that apply there
1049 * @example $("input[@type='checkbox']").parent().is("form")
1050 * @before <form><input type="checkbox" /></form>
1052 * @desc Returns true, because the parent of the input is a form element
1054 * @example $("input[@type='checkbox']").parent().is("form")
1055 * @before <form><p><input type="checkbox" /></p></form>
1057 * @desc Returns false, because the parent of the input is a p element
1061 * @param String expr The expression with which to filter
1062 * @cat DOM/Traversing
1064 is: function(expr) {
1065 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1069 * Get the content of the value attribute of the first matched element.
1071 * Use caution when relying on this function to check the value of
1072 * multiple-select elements and checkboxes in a form. While it will
1073 * still work as intended, it may not accurately represent the value
1074 * the server will receive because these elements may send an array
1075 * of values. For more robust handling of field values, see the
1076 * [http://www.malsup.com/jquery/form/#fields fieldValue function of the Form Plugin].
1078 * @example $("input").val();
1079 * @before <input type="text" value="some text"/>
1080 * @result "some text"
1084 * @cat DOM/Attributes
1088 * Set the value attribute of every matched element.
1090 * @example $("input").val("test");
1091 * @before <input type="text" value="some text"/>
1092 * @result <input type="text" value="test"/>
1096 * @param String val Set the property to the specified value.
1097 * @cat DOM/Attributes
1099 val: function( val ) {
1100 return val == undefined ?
1101 ( this.length ? this[0].value : null ) :
1102 this.attr( "value", val );
1106 * Get the html contents of the first matched element.
1107 * This property is not available on XML documents.
1109 * @example $("div").html();
1110 * @before <div><input/></div>
1115 * @cat DOM/Attributes
1119 * Set the html contents of every matched element.
1120 * This property is not available on XML documents.
1122 * @example $("div").html("<b>new stuff</b>");
1123 * @before <div><input/></div>
1124 * @result <div><b>new stuff</b></div>
1128 * @param String val Set the html contents to the specified value.
1129 * @cat DOM/Attributes
1131 html: function( val ) {
1132 return val == undefined ?
1133 ( this.length ? this[0].innerHTML : null ) :
1134 this.empty().append( val );
1141 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1142 * @param Number dir If dir<0, process args in reverse order.
1143 * @param Function fn The function doing the DOM manipulation.
1147 domManip: function(args, table, dir, fn){
1148 var clone = this.length > 1;
1149 var a = jQuery.clean(args);
1153 return this.each(function(){
1156 if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
1157 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1159 jQuery.each( a, function(){
1160 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
1168 * Extends the jQuery object itself. Can be used to add functions into
1169 * the jQuery namespace and to [[Plugins/Authoring|add plugin methods]] (plugins).
1171 * @example jQuery.fn.extend({
1172 * check: function() {
1173 * return this.each(function() { this.checked = true; });
1175 * uncheck: function() {
1176 * return this.each(function() { this.checked = false; });
1179 * $("input[@type=checkbox]").check();
1180 * $("input[@type=radio]").uncheck();
1181 * @desc Adds two plugin methods.
1183 * @example jQuery.extend({
1184 * min: function(a, b) { return a < b ? a : b; },
1185 * max: function(a, b) { return a > b ? a : b; }
1187 * @desc Adds two functions into the jQuery namespace
1190 * @param Object prop The object that will be merged into the jQuery object
1196 * Extend one object with one or more others, returning the original,
1197 * modified, object. This is a great utility for simple inheritance.
1199 * @example var settings = { validate: false, limit: 5, name: "foo" };
1200 * var options = { validate: true, name: "bar" };
1201 * jQuery.extend(settings, options);
1202 * @result settings == { validate: true, limit: 5, name: "bar" }
1203 * @desc Merge settings and options, modifying settings
1205 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1206 * var options = { validate: true, name: "bar" };
1207 * var settings = jQuery.extend({}, defaults, options);
1208 * @result settings == { validate: true, limit: 5, name: "bar" }
1209 * @desc Merge defaults and options, without modifying the defaults
1212 * @param Object target The object to extend
1213 * @param Object prop1 The object that will be merged into the first.
1214 * @param Object propN (optional) More objects to merge into the first
1218 jQuery.extend = jQuery.fn.extend = function() {
1219 // copy reference to target object
1220 var target = arguments[0],
1223 // extend jQuery itself if only one argument is passed
1224 if ( arguments.length == 1 ) {
1229 while (prop = arguments[a++])
1230 // Extend the base object
1231 for ( var i in prop ) target[i] = prop[i];
1233 // Return the modified object
1239 * Run this function to give control of the $ variable back
1240 * to whichever library first implemented it. This helps to make
1241 * sure that jQuery doesn't conflict with the $ object
1242 * of other libraries.
1244 * By using this function, you will only be able to access jQuery
1245 * using the 'jQuery' variable. For example, where you used to do
1246 * $("div p"), you now must do jQuery("div p").
1248 * @example jQuery.noConflict();
1249 * // Do something with jQuery
1250 * jQuery("div p").hide();
1251 * // Do something with another library's $()
1252 * $("content").style.display = 'none';
1253 * @desc Maps the original object that was referenced by $ back to $
1255 * @example jQuery.noConflict();
1258 * // more code using $ as alias to jQuery
1261 * // other code using $ as an alias to the other library
1262 * @desc Reverts the $ alias and then creates and executes a
1263 * function to provide the $ as a jQuery alias inside the functions
1264 * scope. Inside the function the original $ object is not available.
1265 * This works well for most plugins that don't rely on any other library.
1268 * @name $.noConflict
1272 noConflict: function() {
1278 // This may seem like some crazy code, but trust me when I say that this
1279 // is the only cross-browser way to do this. --John
1280 isFunction: function( fn ) {
1281 return !!fn && typeof fn != "string" && !fn.nodeName &&
1282 typeof fn[0] == "undefined" && /function/i.test( fn + "" );
1285 // check if an element is in a XML document
1286 isXMLDoc: function(elem) {
1287 return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
1290 nodeName: function( elem, name ) {
1291 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
1295 * A generic iterator function, which can be used to seemlessly
1296 * iterate over both objects and arrays. This function is not the same
1297 * as $().each() - which is used to iterate, exclusively, over a jQuery
1298 * object. This function can be used to iterate over anything.
1300 * The callback has two arguments:the key (objects) or index (arrays) as first
1301 * the first, and the value as the second.
1303 * @example $.each( [0,1,2], function(i, n){
1304 * alert( "Item #" + i + ": " + n );
1306 * @desc This is an example of iterating over the items in an array,
1307 * accessing both the current item and its index.
1309 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1310 * alert( "Name: " + i + ", Value: " + n );
1313 * @desc This is an example of iterating over the properties in an
1314 * Object, accessing both the current item and its key.
1317 * @param Object obj The object, or array, to iterate over.
1318 * @param Function fn The function that will be executed on every object.
1322 // args is for internal usage only
1323 each: function( obj, fn, args ) {
1324 if ( obj.length == undefined )
1325 for ( var i in obj )
1326 fn.apply( obj[i], args || [i, obj[i]] );
1328 for ( var i = 0, ol = obj.length; i < ol; i++ )
1329 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1333 prop: function(elem, value, type, index, prop){
1334 // Handle executable functions
1335 if ( jQuery.isFunction( value ) )
1336 value = value.call( elem, [index] );
1338 // exclude the following css properties to add px
1339 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
1341 // Handle passing in a number to a CSS property
1342 return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
1348 // internal only, use addClass("class")
1349 add: function( elem, c ){
1350 jQuery.each( c.split(/\s+/), function(i, cur){
1351 if ( !jQuery.className.has( elem.className, cur ) )
1352 elem.className += ( elem.className ? " " : "" ) + cur;
1356 // internal only, use removeClass("class")
1357 remove: function( elem, c ){
1358 elem.className = c ?
1359 jQuery.grep( elem.className.split(/\s+/), function(cur){
1360 return !jQuery.className.has( c, cur );
1364 // internal only, use is(".class")
1365 has: function( t, c ) {
1366 t = t.className || t;
1367 // escape regex characters
1368 c = c.replace(/([\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
1369 return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
1374 * Swap in/out style options.
1377 swap: function(e,o,f) {
1378 for ( var i in o ) {
1379 e.style["old"+i] = e.style[i];
1384 e.style[i] = e.style["old"+i];
1387 css: function(e,p) {
1388 if ( p == "height" || p == "width" ) {
1389 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1391 jQuery.each( d, function(){
1392 old["padding" + this] = 0;
1393 old["border" + this + "Width"] = 0;
1396 jQuery.swap( e, old, function() {
1397 if (jQuery.css(e,"display") != "none") {
1398 oHeight = e.offsetHeight;
1399 oWidth = e.offsetWidth;
1401 e = jQuery(e.cloneNode(true))
1402 .find(":radio").removeAttr("checked").end()
1404 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1405 }).appendTo(e.parentNode)[0];
1407 var parPos = jQuery.css(e.parentNode,"position");
1408 if ( parPos == "" || parPos == "static" )
1409 e.parentNode.style.position = "relative";
1411 oHeight = e.clientHeight;
1412 oWidth = e.clientWidth;
1414 if ( parPos == "" || parPos == "static" )
1415 e.parentNode.style.position = "static";
1417 e.parentNode.removeChild(e);
1421 return p == "height" ? oHeight : oWidth;
1424 return jQuery.curCSS( e, p );
1427 curCSS: function(elem, prop, force) {
1430 if (prop == "opacity" && jQuery.browser.msie)
1431 return jQuery.attr(elem.style, "opacity");
1433 if (prop == "float" || prop == "cssFloat")
1434 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1436 if (!force && elem.style[prop])
1437 ret = elem.style[prop];
1439 else if (document.defaultView && document.defaultView.getComputedStyle) {
1441 if (prop == "cssFloat" || prop == "styleFloat")
1444 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1445 var cur = document.defaultView.getComputedStyle(elem, null);
1448 ret = cur.getPropertyValue(prop);
1449 else if ( prop == "display" )
1452 jQuery.swap(elem, { display: "block" }, function() {
1453 var c = document.defaultView.getComputedStyle(this, "");
1454 ret = c && c.getPropertyValue(prop) || "";
1457 } else if (elem.currentStyle) {
1459 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1460 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1467 clean: function(a) {
1470 jQuery.each( a, function(i,arg){
1473 if ( arg.constructor == Number )
1474 arg = arg.toString();
1476 // Convert html string into DOM nodes
1477 if ( typeof arg == "string" ) {
1478 // Trim whitespace, otherwise indexOf won't work as expected
1479 var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
1482 // option or optgroup
1483 !s.indexOf("<opt") &&
1484 [1, "<select>", "</select>"] ||
1486 (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
1487 [1, "<table>", "</table>"] ||
1489 !s.indexOf("<tr") &&
1490 [2, "<table><tbody>", "</tbody></table>"] ||
1492 // <thead> matched above
1493 (!s.indexOf("<td") || !s.indexOf("<th")) &&
1494 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1498 // Go to html and back, then peel off extra wrappers
1499 div.innerHTML = wrap[1] + s + wrap[2];
1501 // Move to the right depth
1503 div = div.firstChild;
1505 // Remove IE's autoinserted <tbody> from table fragments
1506 if ( jQuery.browser.msie ) {
1508 // String was a <table>, *may* have spurious <tbody>
1509 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
1510 tb = div.firstChild && div.firstChild.childNodes;
1512 // String was a bare <thead> or <tfoot>
1513 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1514 tb = div.childNodes;
1516 for ( var n = tb.length-1; n >= 0 ; --n )
1517 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
1518 tb[n].parentNode.removeChild(tb[n]);
1522 arg = div.childNodes;
1525 if ( arg.length === 0 && !jQuery.nodeName(arg, "form") )
1528 if ( arg[0] == undefined || jQuery.nodeName(arg, "form") )
1531 r = jQuery.merge( r, arg );
1538 attr: function(elem, name, value){
1539 var fix = jQuery.isXMLDoc(elem) ? {} : {
1541 "class": "className",
1542 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1543 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1544 innerHTML: "innerHTML",
1545 className: "className",
1547 disabled: "disabled",
1549 readonly: "readOnly",
1550 selected: "selected"
1553 // IE actually uses filters for opacity ... elem is actually elem.style
1554 if ( name == "opacity" && jQuery.browser.msie && 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 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1561 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1563 } else if ( name == "opacity" && jQuery.browser.msie )
1564 return elem.filter ?
1565 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1567 // Mozilla doesn't play well with opacity 1
1568 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1572 // Certain attributes only work when accessed via the old DOM 0 way
1574 if ( value != undefined ) elem[fix[name]] = value;
1575 return elem[fix[name]];
1577 } else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
1578 return elem.getAttributeNode(name).nodeValue;
1580 // IE elem.getAttribute passes even for style
1581 else if ( elem.tagName ) {
1582 if ( value != undefined ) elem.setAttribute( name, value );
1583 if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) )
1584 return elem.getAttribute( name, 2 );
1585 return elem.getAttribute( name );
1587 // elem is actually elem.style ... set the style
1589 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1590 if ( value != undefined ) elem[name] = value;
1596 * Remove the whitespace from the beginning and end of a string.
1598 * @example $.trim(" hello, how are you? ");
1599 * @result "hello, how are you?"
1603 * @param String str The string to trim.
1607 return t.replace(/^\s+|\s+$/g, "");
1610 makeArray: function( a ) {
1613 if ( a.constructor != Array )
1614 for ( var i = 0, al = a.length; i < al; i++ )
1622 inArray: function( b, a ) {
1623 for ( var i = 0, al = a.length; i < al; i++ )
1630 * Merge two arrays together, removing all duplicates.
1632 * The result is the altered first argument with
1633 * the unique elements from the second array added.
1635 * @example $.merge( [0,1,2], [2,3,4] )
1636 * @result [0,1,2,3,4]
1637 * @desc Merges two arrays, removing the duplicate 2
1639 * @example var array = [3,2,1];
1640 * $.merge( array, [4,3,2] )
1641 * @result array == [3,2,1,4]
1642 * @desc Merges two arrays, removing the duplicates 3 and 2
1646 * @param Array first The first array to merge, the unique elements of second added.
1647 * @param Array second The second array to merge into the first, unaltered.
1650 merge: function(first, second) {
1651 var r = [].slice.call( first, 0 );
1653 // Now check for duplicates between the two arrays
1654 // and only add the unique items
1655 for ( var i = 0, sl = second.length; i < sl; i++ )
1656 // Check for duplicates
1657 if ( jQuery.inArray( second[i], r ) == -1 )
1658 // The item is unique, add it
1659 first.push( second[i] );
1665 * Filter items out of an array, by using a filter function.
1667 * The specified function will be passed two arguments: The
1668 * current array item and the index of the item in the array. The
1669 * function must return 'true' to keep the item in the array,
1670 * false to remove it.
1672 * @example $.grep( [0,1,2], function(i){
1679 * @param Array array The Array to find items in.
1680 * @param Function fn The function to process each item against.
1681 * @param Boolean inv Invert the selection - select the opposite of the function.
1684 grep: function(elems, fn, inv) {
1685 // If a string is passed in for the function, make a function
1686 // for it (a handy shortcut)
1687 if ( typeof fn == "string" )
1688 fn = new Function("a","i","return " + fn);
1692 // Go through the array, only saving the items
1693 // that pass the validator function
1694 for ( var i = 0, el = elems.length; i < el; i++ )
1695 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1696 result.push( elems[i] );
1702 * Translate all items in an array to another array of items.
1704 * The translation function that is provided to this method is
1705 * called for each item in the array and is passed one argument:
1706 * The item to be translated.
1708 * The function can then return the translated value, 'null'
1709 * (to remove the item), or an array of values - which will
1710 * be flattened into the full array.
1712 * @example $.map( [0,1,2], function(i){
1716 * @desc Maps the original array to a new one and adds 4 to each value.
1718 * @example $.map( [0,1,2], function(i){
1719 * return i > 0 ? i + 1 : null;
1722 * @desc Maps the original array to a new one and adds 1 to each
1723 * value if it is bigger then zero, otherwise it's removed-
1725 * @example $.map( [0,1,2], function(i){
1726 * return [ i, i + 1 ];
1728 * @result [0, 1, 1, 2, 2, 3]
1729 * @desc Maps the original array to a new one, each element is added
1730 * with it's original value and the value plus one.
1734 * @param Array array The Array to translate.
1735 * @param Function fn The function to process each item against.
1738 map: function(elems, fn) {
1739 // If a string is passed in for the function, make a function
1740 // for it (a handy shortcut)
1741 if ( typeof fn == "string" )
1742 fn = new Function("a","return " + fn);
1744 var result = [], r = [];
1746 // Go through the array, translating each of the items to their
1747 // new value (or values).
1748 for ( var i = 0, el = elems.length; i < el; i++ ) {
1749 var val = fn(elems[i],i);
1751 if ( val !== null && val != undefined ) {
1752 if ( val.constructor != Array ) val = [val];
1753 result = result.concat( val );
1757 var r = result.length ? [ result[0] ] : [];
1759 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1760 for ( var j = 0; j < i; j++ )
1761 if ( result[i] == r[j] )
1764 r.push( result[i] );
1772 * Contains flags for the useragent, read from navigator.userAgent.
1773 * Available flags are: safari, opera, msie, mozilla
1775 * This property is available before the DOM is ready, therefore you can
1776 * use it to add ready events only for certain browsers.
1778 * There are situations where object detections is not reliable enough, in that
1779 * cases it makes sense to use browser detection. Simply try to avoid both!
1781 * A combination of browser and object detection yields quite reliable results.
1783 * @example $.browser.msie
1784 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1786 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1787 * @desc Alerts "this is safari!" only for safari browsers
1796 * Whether the W3C compliant box model is being used.
1804 var b = navigator.userAgent.toLowerCase();
1806 // Figure out what browser is being used
1808 safari: /webkit/.test(b),
1809 opera: /opera/.test(b),
1810 msie: /msie/.test(b) && !/opera/.test(b),
1811 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1814 // Check to see if the W3C box model is being used
1815 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1819 * Get a set of elements containing the unique parents of the matched
1822 * You may use an optional expression to filter the set of parent elements that will match.
1824 * @example $("p").parent()
1825 * @before <div><p>Hello</p><p>Hello</p></div>
1826 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1827 * @desc Find the parent element of each paragraph.
1829 * @example $("p").parent(".selected")
1830 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1831 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1832 * @desc Find the parent element of each paragraph with a class "selected".
1836 * @param String expr (optional) An expression to filter the parents with
1837 * @cat DOM/Traversing
1841 * Get a set of elements containing the unique ancestors of the matched
1842 * set of elements (except for the root element).
1844 * The matched elements can be filtered with an optional expression.
1846 * @example $("span").parents()
1847 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1848 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1849 * @desc Find all parent elements of each span.
1851 * @example $("span").parents("p")
1852 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1853 * @result [ <p><span>Hello</span></p> ]
1854 * @desc Find all parent elements of each span that is a paragraph.
1858 * @param String expr (optional) An expression to filter the ancestors with
1859 * @cat DOM/Traversing
1863 * Get a set of elements containing the unique next siblings of each of the
1864 * matched set of elements.
1866 * It only returns the very next sibling for each element, not all
1869 * You may provide an optional expression to filter the match.
1871 * @example $("p").next()
1872 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1873 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1874 * @desc Find the very next sibling of each paragraph.
1876 * @example $("p").next(".selected")
1877 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1878 * @result [ <p class="selected">Hello Again</p> ]
1879 * @desc Find the very next sibling of each paragraph that has a class "selected".
1883 * @param String expr (optional) An expression to filter the next Elements with
1884 * @cat DOM/Traversing
1888 * Get a set of elements containing the unique previous siblings of each of the
1889 * matched set of elements.
1891 * Use an optional expression to filter the matched set.
1893 * Only the immediately previous sibling is returned, not all previous siblings.
1895 * @example $("p").prev()
1896 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1897 * @result [ <div><span>Hello Again</span></div> ]
1898 * @desc Find the very previous sibling of each paragraph.
1900 * @example $("p").prev(".selected")
1901 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1902 * @result [ <div><span>Hello</span></div> ]
1903 * @desc Find the very previous sibling of each paragraph that has a class "selected".
1907 * @param String expr (optional) An expression to filter the previous Elements with
1908 * @cat DOM/Traversing
1912 * Get a set of elements containing all of the unique siblings of each of the
1913 * matched set of elements.
1915 * Can be filtered with an optional expressions.
1917 * @example $("div").siblings()
1918 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1919 * @result [ <p>Hello</p>, <p>And Again</p> ]
1920 * @desc Find all siblings of each div.
1922 * @example $("div").siblings(".selected")
1923 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1924 * @result [ <p class="selected">Hello Again</p> ]
1925 * @desc Find all siblings with a class "selected" of each div.
1929 * @param String expr (optional) An expression to filter the sibling Elements with
1930 * @cat DOM/Traversing
1934 * Get a set of elements containing all of the unique children of each of the
1935 * matched set of elements.
1937 * This set can be filtered with an optional expression that will cause
1938 * only elements matching the selector to be collected.
1940 * @example $("div").children()
1941 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1942 * @result [ <span>Hello Again</span> ]
1943 * @desc Find all children of each div.
1945 * @example $("div").children(".selected")
1946 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1947 * @result [ <p class="selected">Hello Again</p> ]
1948 * @desc Find all children with a class "selected" of each div.
1952 * @param String expr (optional) An expression to filter the child Elements with
1953 * @cat DOM/Traversing
1956 parent: "a.parentNode",
1957 parents: "jQuery.parents(a)",
1958 next: "jQuery.nth(a,2,'nextSibling')",
1959 prev: "jQuery.nth(a,2,'previousSibling')",
1960 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1961 children: "jQuery.sibling(a.firstChild)"
1963 jQuery.fn[ i ] = function(a) {
1964 var ret = jQuery.map(this,n);
1965 if ( a && typeof a == "string" )
1966 ret = jQuery.multiFilter(a,ret);
1967 return this.pushStack( ret );
1972 * Append all of the matched elements to another, specified, set of elements.
1973 * This operation is, essentially, the reverse of doing a regular
1974 * $(A).append(B), in that instead of appending B to A, you're appending
1977 * @example $("p").appendTo("#foo");
1978 * @before <p>I would like to say: </p><div id="foo"></div>
1979 * @result <div id="foo"><p>I would like to say: </p></div>
1980 * @desc Appends all paragraphs to the element with the ID "foo"
1984 * @param <Content> content Content to append to the selected element to.
1985 * @cat DOM/Manipulation
1986 * @see append(<Content>)
1990 * Prepend all of the matched elements to another, specified, set of elements.
1991 * This operation is, essentially, the reverse of doing a regular
1992 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1995 * @example $("p").prependTo("#foo");
1996 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1997 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1998 * @desc Prepends all paragraphs to the element with the ID "foo"
2002 * @param <Content> content Content to prepend to the selected element to.
2003 * @cat DOM/Manipulation
2004 * @see prepend(<Content>)
2008 * Insert all of the matched elements before another, specified, set of elements.
2009 * This operation is, essentially, the reverse of doing a regular
2010 * $(A).before(B), in that instead of inserting B before A, you're inserting
2013 * @example $("p").insertBefore("#foo");
2014 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2015 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2016 * @desc Same as $("#foo").before("p")
2018 * @name insertBefore
2020 * @param <Content> content Content to insert the selected element before.
2021 * @cat DOM/Manipulation
2022 * @see before(<Content>)
2026 * Insert all of the matched elements after another, specified, set of elements.
2027 * This operation is, essentially, the reverse of doing a regular
2028 * $(A).after(B), in that instead of inserting B after A, you're inserting
2031 * @example $("p").insertAfter("#foo");
2032 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2033 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2034 * @desc Same as $("#foo").after("p")
2038 * @param <Content> content Content to insert the selected element after.
2039 * @cat DOM/Manipulation
2040 * @see after(<Content>)
2045 prependTo: "prepend",
2046 insertBefore: "before",
2047 insertAfter: "after"
2049 jQuery.fn[ i ] = function(){
2051 return this.each(function(){
2052 for ( var j = 0, al = a.length; j < al; j++ )
2053 jQuery(a[j])[n]( this );
2059 * Remove an attribute from each of the matched elements.
2061 * @example $("input").removeAttr("disabled")
2062 * @before <input disabled="disabled"/>
2067 * @param String name The name of the attribute to remove.
2068 * @cat DOM/Attributes
2072 * Adds the specified class(es) to each of the set of matched elements.
2074 * @example $("p").addClass("selected")
2075 * @before <p>Hello</p>
2076 * @result [ <p class="selected">Hello</p> ]
2078 * @example $("p").addClass("selected highlight")
2079 * @before <p>Hello</p>
2080 * @result [ <p class="selected highlight">Hello</p> ]
2084 * @param String class One or more CSS classes to add to the elements
2085 * @cat DOM/Attributes
2086 * @see removeClass(String)
2090 * Removes all or the specified class(es) from the set of matched elements.
2092 * @example $("p").removeClass()
2093 * @before <p class="selected">Hello</p>
2094 * @result [ <p>Hello</p> ]
2096 * @example $("p").removeClass("selected")
2097 * @before <p class="selected first">Hello</p>
2098 * @result [ <p class="first">Hello</p> ]
2100 * @example $("p").removeClass("selected highlight")
2101 * @before <p class="highlight selected first">Hello</p>
2102 * @result [ <p class="first">Hello</p> ]
2106 * @param String class (optional) One or more CSS classes to remove from the elements
2107 * @cat DOM/Attributes
2108 * @see addClass(String)
2112 * Adds the specified class if it is not present, removes it if it is
2115 * @example $("p").toggleClass("selected")
2116 * @before <p>Hello</p><p class="selected">Hello Again</p>
2117 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2121 * @param String class A CSS class with which to toggle the elements
2122 * @cat DOM/Attributes
2126 * Removes all matched elements from the DOM. This does NOT remove them from the
2127 * jQuery object, allowing you to use the matched elements further.
2129 * Can be filtered with an optional expressions.
2131 * @example $("p").remove();
2132 * @before <p>Hello</p> how are <p>you?</p>
2135 * @example $("p").remove(".hello");
2136 * @before <p class="hello">Hello</p> how are <p>you?</p>
2137 * @result how are <p>you?</p>
2141 * @param String expr (optional) A jQuery expression to filter elements by.
2142 * @cat DOM/Manipulation
2146 * Removes all child nodes from the set of matched elements.
2148 * @example $("p").empty()
2149 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2150 * @result [ <p></p> ]
2154 * @cat DOM/Manipulation
2158 removeAttr: function( key ) {
2159 jQuery.attr( this, key, "" );
2160 this.removeAttribute( key );
2162 addClass: function(c){
2163 jQuery.className.add(this,c);
2165 removeClass: function(c){
2166 jQuery.className.remove(this,c);
2168 toggleClass: function( c ){
2169 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2171 remove: function(a){
2172 if ( !a || jQuery.filter( a, [this] ).r.length )
2173 this.parentNode.removeChild( this );
2176 while ( this.firstChild )
2177 this.removeChild( this.firstChild );
2180 jQuery.fn[ i ] = function() {
2181 return this.each( n, arguments );
2186 * Reduce the set of matched elements to a single element.
2187 * The position of the element in the set of matched elements
2188 * starts at 0 and goes to length - 1.
2190 * @example $("p").eq(1)
2191 * @before <p>This is just a test.</p><p>So is this</p>
2192 * @result [ <p>So is this</p> ]
2196 * @param Number pos The index of the element that you wish to limit to.
2201 * Reduce the set of matched elements to all elements before a given position.
2202 * The position of the element in the set of matched elements
2203 * starts at 0 and goes to length - 1.
2205 * @example $("p").lt(1)
2206 * @before <p>This is just a test.</p><p>So is this</p>
2207 * @result [ <p>This is just a test.</p> ]
2211 * @param Number pos Reduce the set to all elements below this position.
2216 * Reduce the set of matched elements to all elements after a given position.
2217 * The position of the element in the set of matched elements
2218 * starts at 0 and goes to length - 1.
2220 * @example $("p").gt(0)
2221 * @before <p>This is just a test.</p><p>So is this</p>
2222 * @result [ <p>So is this</p> ]
2226 * @param Number pos Reduce the set to all elements after this position.
2231 * Filter the set of elements to those that contain the specified text.
2233 * @example $("p").contains("test")
2234 * @before <p>This is just a test.</p><p>So is this</p>
2235 * @result [ <p>This is just a test.</p> ]
2239 * @param String str The string that will be contained within the text of an element.
2240 * @cat DOM/Traversing
2242 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2243 jQuery.fn[ n ] = function(num,fn) {
2244 return this.filter( ":" + n + "(" + num + ")", fn );
2249 * Get the current computed, pixel, width of the first matched element.
2251 * @example $("p").width();
2252 * @before <p>This is just a test.</p>
2261 * Set the CSS width of every matched element. If no explicit unit
2262 * was specified (like 'em' or '%') then "px" is added to the width.
2264 * @example $("p").width(20);
2265 * @before <p>This is just a test.</p>
2266 * @result <p style="width:20px;">This is just a test.</p>
2268 * @example $("p").width("20em");
2269 * @before <p>This is just a test.</p>
2270 * @result <p style="width:20em;">This is just a test.</p>
2274 * @param String|Number val Set the CSS property to the specified value.
2279 * Get the current computed, pixel, height of the first matched element.
2281 * @example $("p").height();
2282 * @before <p>This is just a test.</p>
2291 * Set the CSS width of every matched element. If no explicit unit
2292 * was specified (like 'em' or '%') then "px" is added to the width.
2294 * @example $("p").height(20);
2295 * @before <p>This is just a test.</p>
2296 * @result <p style="height:20px;">This is just a test.</p>
2298 * @example $("p").height("20em");
2299 * @before <p>This is just a test.</p>
2300 * @result <p style="height:20em;">This is just a test.</p>
2304 * @param String|Number val Set the CSS property to the specified value.
2308 jQuery.each( [ "height", "width" ], function(i,n){
2309 jQuery.fn[ n ] = function(h) {
2310 return h == undefined ?
2311 ( this.length ? jQuery.css( this[0], n ) : null ) :
2312 this.css( n, h.constructor == String ? h : h + "px" );