2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
21 * @param String|Function|Element|Array<Element>|jQuery a selector
22 * @param jQuery|Element|Array<Element> c context
25 var jQuery = function(a,c) {
26 // If the context is global, return a new object
28 return new jQuery(a,c);
30 // Make sure that a selection was provided
33 // HANDLE: $(function)
34 // Shortcut for document ready
35 // Safari reports typeof on DOM NodeLists as a function
36 if ( typeof a == "function" && !a.nodeType && a[0] == undefined )
37 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
39 // Handle HTML strings
40 if ( typeof a == "string" ) {
41 // HANDLE: $(html) -> $(array)
42 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
44 a = jQuery.clean( [ m[1] ] );
48 return new jQuery( c ).find( a );
53 a.constructor == Array && a ||
55 // HANDLE: $(arraylike)
56 // Watch for when an array-like object is passed as the selector
57 (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
63 // Map over the $ in case of overwrite
64 if ( typeof $ != "undefined" )
67 // Map the jQuery namespace to the '$' one
71 * This function accepts a string containing a CSS or
72 * basic XPath selector which is then used to match a set of elements.
74 * The core functionality of jQuery centers around this function.
75 * Everything in jQuery is based upon this, or uses this in some way.
76 * The most basic use of this function is to pass in an expression
77 * (usually consisting of CSS or XPath), which then finds all matching
80 * By default, $() looks for DOM elements within the context of the
81 * current HTML document.
83 * @example $("div > p")
84 * @desc Finds all p elements that are children of a div element.
85 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
86 * @result [ <p>two</p> ]
88 * @example $("input:radio", document.forms[0])
89 * @desc Searches for all inputs of type radio within the first form in the document
91 * @example $("div", xml.responseXML)
92 * @desc This finds all div elements within the specified XML document.
95 * @param String expr An expression to search with
96 * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
100 * @see $(Element<Array>)
104 * Create DOM elements on-the-fly from the provided String of raw HTML.
106 * @example $("<div><p>Hello</p></div>").appendTo("#body")
107 * @desc Creates a div element (and all of its contents) dynamically,
108 * and appends it to the element with the ID of body. Internally, an
109 * element is created and it's innerHTML property set to the given markup.
110 * It is therefore both quite flexible and limited.
113 * @param String html A string of HTML to create on the fly.
116 * @see appendTo(String)
120 * Wrap jQuery functionality around a single or multiple DOM Element(s).
122 * This function also accepts XML Documents and Window objects
123 * as valid arguments (even though they are not DOM Elements).
125 * @example $(document).find("div > p")
126 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
127 * @result [ <p>two</p> ]
128 * @desc Same as $("div > p") because the document
130 * @example $(document.body).background( "black" );
131 * @desc Sets the background color of the page to black.
133 * @example $( myForm.elements ).hide()
134 * @desc Hides all the input elements within a form
137 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
143 * A shorthand for $(document).ready(), allowing you to bind a function
144 * to be executed when the DOM document has finished loading. This function
145 * behaves just like $(document).ready(), in that it should be used to wrap
146 * all of the other $() operations on your page. While this function is,
147 * technically, chainable - there really isn't much use for chaining against it.
148 * You can have as many $(document).ready events on your page as you like.
150 * See ready(Function) for details about the ready event.
152 * @example $(function(){
153 * // Document is ready
155 * @desc Executes the function when the DOM is ready to be used.
158 * @param Function fn The function to execute when the DOM is ready.
164 * A means of creating a cloned copy of a jQuery object. This function
165 * copies the set of matched elements from one jQuery object and creates
166 * another, new, jQuery object containing the same elements.
168 * @example var div = $("div");
169 * $( div ).find("p");
170 * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div' (as would normally be the case if a simple div.find("p") was done).
173 * @param jQuery obj The jQuery object to be cloned.
178 jQuery.fn = jQuery.prototype = {
180 * The current version of jQuery.
191 * The number of elements currently matched.
193 * @example $("img").length;
194 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
204 * The number of elements currently matched.
206 * @example $("img").size();
207 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
221 * Access all matched elements. This serves as a backwards-compatible
222 * way of accessing all matched elements (other than the jQuery object
223 * itself, which is, in fact, an array of elements).
225 * @example $("img").get();
226 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
227 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
228 * @desc Selects all images in the document and returns the DOM Elements as an Array
231 * @type Array<Element>
236 * Access a single matched element. num is used to access the
237 * Nth element matched.
239 * @example $("img").get(0);
240 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
241 * @result [ <img src="test1.jpg"/> ]
242 * @desc Selects all images in the document and returns the first one
246 * @param Number num Access the element in the Nth position.
249 get: function( num ) {
250 return num == undefined ?
252 // Return a 'clean' array
253 jQuery.makeArray( this ) :
255 // Return just the object
260 * Set the jQuery object to an array of elements, while maintaining
263 * @example $("img").set([ document.body ]);
264 * @result $("img").set() == [ document.body ]
269 * @param Elements elems An array of elements
273 var ret = jQuery(this);
274 ret.prevObject = this;
275 return ret.setArray( a );
279 * Set the jQuery object to an array of elements. This operation is
280 * completely destructive - be sure to use .set() if you wish to maintain
283 * @example $("img").setArray([ document.body ]);
284 * @result $("img").setArray() == [ document.body ]
289 * @param Elements elems An array of elements
292 setArray: function( a ) {
294 [].push.apply( this, a );
299 * Execute a function within the context of every matched element.
300 * This means that every time the passed-in function is executed
301 * (which is once for every element matched) the 'this' keyword
302 * points to the specific element.
304 * Additionally, the function, when executed, is passed a single
305 * argument representing the position of the element in the matched
308 * @example $("img").each(function(i){
309 * this.src = "test" + i + ".jpg";
311 * @before <img/><img/>
312 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
313 * @desc Iterates over two images and sets their src property
317 * @param Function fn A function to execute
320 each: function( fn, args ) {
321 return jQuery.each( this, fn, args );
325 * Searches every matched element for the object and returns
326 * the index of the element, if found, starting with zero.
327 * Returns -1 if the object wasn't found.
329 * @example $("*").index( $('#foobar')[0] )
330 * @before <div id="foobar"></div><b></b><span id="foo"></span>
332 * @desc Returns the index for the element with ID foobar
334 * @example $("*").index( $('#foo'))
335 * @before <div id="foobar"></div><b></b><span id="foo"></span>
337 * @desc Returns the index for the element with ID foo
339 * @example $("*").index( $('#bar'))
340 * @before <div id="foobar"></div><b></b><span id="foo"></span>
342 * @desc Returns -1, as there is no element with ID bar
346 * @param Element subject Object to search for
349 index: function( obj ) {
351 this.each(function(i){
352 if ( this == obj ) pos = i;
358 * Access a property on the first matched element.
359 * This method makes it easy to retrieve a property value
360 * from the first matched element.
362 * @example $("img").attr("src");
363 * @before <img src="test.jpg"/>
365 * @desc Returns the src attribute from the first image in the document.
369 * @param String name The name of the property to access.
370 * @cat DOM/Attributes
374 * Set a key/value object as properties to all matched elements.
376 * This serves as the best way to set a large number of properties
377 * on all matched elements.
379 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
381 * @result <img src="test.jpg" alt="Test Image"/>
382 * @desc Sets src and alt attributes to all images.
386 * @param Map properties Key/value pairs to set as object properties.
387 * @cat DOM/Attributes
391 * Set a single property to a value, on all matched elements.
393 * Can compute values provided as ${formula}, see second example.
395 * Note that you can't set the name property of input elements in IE.
396 * Use $(html) or .append(html) or .html(html) to create elements
397 * on the fly including the name property.
399 * @example $("img").attr("src","test.jpg");
401 * @result <img src="test.jpg"/>
402 * @desc Sets src attribute to all images.
404 * @example $("img").attr("title", "${this.src}");
405 * @before <img src="test.jpg" />
406 * @result <img src="test.jpg" title="test.jpg" />
407 * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
411 * @param String key The name of the property to set.
412 * @param Object value The value to set the property to.
413 * @cat DOM/Attributes
417 * Set a single property to a computed value, on all matched elements.
419 * Instead of a value, a function is provided, that computes the value.
421 * @example $("img").attr("title", function() { return this.src });
422 * @before <img src="test.jpg" />
423 * @result <img src="test.jpg" title="test.jpg" />
424 * @desc Sets title attribute from src attribute.
428 * @param String key The name of the property to set.
429 * @param Function value A function returning the value to set.
430 * @cat DOM/Attributes
432 attr: function( key, value, type ) {
433 // Check to see if we're setting style values
434 return typeof key != "string" || value != undefined ?
435 this.each(function(){
436 // See if we're setting a hash of styles
437 if ( value == undefined )
438 // Set all the styles
439 for ( var prop in key )
441 type ? this.style : this,
442 prop, jQuery.prop(this, prop, key[prop], type)
445 // See if we're setting a single key/value style
448 type ? this.style : this,
449 key, jQuery.prop(this, key, value, type)
453 // Look for the case where we're accessing a style value
454 jQuery[ type || "attr" ]( this[0], key );
458 * Access a style property on the first matched element.
459 * This method makes it easy to retrieve a style property value
460 * from the first matched element.
462 * @example $("p").css("color");
463 * @before <p style="color:red;">Test Paragraph.</p>
465 * @desc Retrieves the color style of the first paragraph
467 * @example $("p").css("font-weight");
468 * @before <p style="font-weight: bold;">Test Paragraph.</p>
470 * @desc Retrieves the font-weight style of the first paragraph.
474 * @param String name The name of the property to access.
479 * Set a key/value object as style properties to all matched elements.
481 * This serves as the best way to set a large number of style properties
482 * on all matched elements.
484 * @example $("p").css({ color: "red", background: "blue" });
485 * @before <p>Test Paragraph.</p>
486 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
487 * @desc Sets color and background styles to all p elements.
491 * @param Map properties Key/value pairs to set as style properties.
496 * Set a single style property to a value, on all matched elements.
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
505 * @param String key The name of the property to set.
506 * @param Object value The value to set the property to.
509 css: function( key, value ) {
510 return this.attr( key, value, "curCSS" );
514 * Get the text contents of all matched elements. The result is
515 * a string that contains the combined text contents of all matched
516 * elements. This method works on both HTML and XML documents.
518 * @example $("p").text();
519 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
520 * @result Test Paragraph.Paraparagraph
521 * @desc Gets the concatenated text of all paragraphs
525 * @cat DOM/Attributes
529 * Set the text contents of all matched elements.
531 * Similar to html(), but escapes HTML (replace "<" and ">" with their
534 * @example $("p").text("<b>Some</b> new text.");
535 * @before <p>Test Paragraph.</p>
536 * @result <p><b>Some</b> new text.</p>
537 * @desc Sets the text of all paragraphs.
539 * @example $("p").text("<b>Some</b> new text.", true);
540 * @before <p>Test Paragraph.</p>
541 * @result <p>Some new text.</p>
542 * @desc Sets the text of all paragraphs.
546 * @param String val The text value to set the contents of the element to.
547 * @cat DOM/Attributes
550 var type = this.length && this[0].innerText == undefined ?
551 "textContent" : "innerText";
553 return e == undefined ?
554 this.length && this[0][ type ] :
555 this.each(function(){ this[ type ] = e; });
559 * Wrap all matched elements with a structure of other elements.
560 * This wrapping process is most useful for injecting additional
561 * stucture into a document, without ruining the original semantic
562 * qualities of a document.
564 * This works by going through the first element
565 * provided (which is generated, on the fly, from the provided HTML)
566 * and finds the deepest ancestor element within its
567 * structure - it is that element that will en-wrap everything else.
569 * This does not work with elements that contain text. Any necessary text
570 * must be added after the wrapping is done.
572 * @example $("p").wrap("<div class='wrap'></div>");
573 * @before <p>Test Paragraph.</p>
574 * @result <div class='wrap'><p>Test Paragraph.</p></div>
578 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
579 * @cat DOM/Manipulation
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 and finding the deepest ancestor element within its
590 * structure - it is that element that will en-wrap everything else.
592 * This does not work with elements that contain text. Any necessary text
593 * must be added after the wrapping is done.
595 * @example $("p").wrap( document.getElementById('content') );
596 * @before <p>Test Paragraph.</p><div id="content"></div>
597 * @result <div id="content"><p>Test Paragraph.</p></div>
601 * @param Element elem A DOM element that will be wrapped around the target.
602 * @cat DOM/Manipulation
605 // The elements to wrap the target around
606 var a = jQuery.clean(arguments);
608 // Wrap each of the matched elements individually
609 return this.each(function(){
610 // Clone the structure that we're using to wrap
611 var b = a[0].cloneNode(true);
613 // Insert it before the element to be wrapped
614 this.parentNode.insertBefore( b, this );
616 // Find the deepest point in the wrap structure
617 while ( b.firstChild )
620 // Move the matched element to within the wrap structure
621 b.appendChild( this );
626 * Append content to the inside of every matched element.
628 * This operation is similar to doing an appendChild to all the
629 * specified elements, adding them into the document.
631 * @example $("p").append("<b>Hello</b>");
632 * @before <p>I would like to say: </p>
633 * @result <p>I would like to say: <b>Hello</b></p>
634 * @desc Appends some HTML to all paragraphs.
636 * @example $("p").append( $("#foo")[0] );
637 * @before <p>I would like to say: </p><b id="foo">Hello</b>
638 * @result <p>I would like to say: <b id="foo">Hello</b></p>
639 * @desc Appends an Element to all paragraphs.
641 * @example $("p").append( $("b") );
642 * @before <p>I would like to say: </p><b>Hello</b>
643 * @result <p>I would like to say: <b>Hello</b></p>
644 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
648 * @param <Content> content Content to append to the target
649 * @cat DOM/Manipulation
650 * @see prepend(<Content>)
651 * @see before(<Content>)
652 * @see after(<Content>)
655 return this.domManip(arguments, true, 1, function(a){
656 this.appendChild( a );
661 * Prepend content to the inside of every matched element.
663 * This operation is the best way to insert elements
664 * inside, at the beginning, of all matched elements.
666 * @example $("p").prepend("<b>Hello</b>");
667 * @before <p>I would like to say: </p>
668 * @result <p><b>Hello</b>I would like to say: </p>
669 * @desc Prepends some HTML to all paragraphs.
671 * @example $("p").prepend( $("#foo")[0] );
672 * @before <p>I would like to say: </p><b id="foo">Hello</b>
673 * @result <p><b id="foo">Hello</b>I would like to say: </p>
674 * @desc Prepends an Element to all paragraphs.
676 * @example $("p").prepend( $("b") );
677 * @before <p>I would like to say: </p><b>Hello</b>
678 * @result <p><b>Hello</b>I would like to say: </p>
679 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
683 * @param <Content> content Content to prepend to the target.
684 * @cat DOM/Manipulation
685 * @see append(<Content>)
686 * @see before(<Content>)
687 * @see after(<Content>)
689 prepend: function() {
690 return this.domManip(arguments, true, -1, function(a){
691 this.insertBefore( a, this.firstChild );
696 * Insert content before each of the matched elements.
698 * @example $("p").before("<b>Hello</b>");
699 * @before <p>I would like to say: </p>
700 * @result <b>Hello</b><p>I would like to say: </p>
701 * @desc Inserts some HTML before all paragraphs.
703 * @example $("p").before( $("#foo")[0] );
704 * @before <p>I would like to say: </p><b id="foo">Hello</b>
705 * @result <b id="foo">Hello</b><p>I would like to say: </p>
706 * @desc Inserts an Element before all paragraphs.
708 * @example $("p").before( $("b") );
709 * @before <p>I would like to say: </p><b>Hello</b>
710 * @result <b>Hello</b><p>I would like to say: </p>
711 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
715 * @param <Content> content Content to insert before each target.
716 * @cat DOM/Manipulation
717 * @see append(<Content>)
718 * @see prepend(<Content>)
719 * @see after(<Content>)
722 return this.domManip(arguments, false, 1, function(a){
723 this.parentNode.insertBefore( a, this );
728 * Insert content after each of the matched elements.
730 * @example $("p").after("<b>Hello</b>");
731 * @before <p>I would like to say: </p>
732 * @result <p>I would like to say: </p><b>Hello</b>
733 * @desc Inserts some HTML after all paragraphs.
735 * @example $("p").after( $("#foo")[0] );
736 * @before <b id="foo">Hello</b><p>I would like to say: </p>
737 * @result <p>I would like to say: </p><b id="foo">Hello</b>
738 * @desc Inserts an Element after all paragraphs.
740 * @example $("p").after( $("b") );
741 * @before <b>Hello</b><p>I would like to say: </p>
742 * @result <p>I would like to say: </p><b>Hello</b>
743 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
747 * @param <Content> content Content to insert after each target.
748 * @cat DOM/Manipulation
749 * @see append(<Content>)
750 * @see prepend(<Content>)
751 * @see before(<Content>)
754 return this.domManip(arguments, false, -1, function(a){
755 this.parentNode.insertBefore( a, this.nextSibling );
760 * End the most recent 'destructive' operation, reverting the list of matched elements
761 * back to its previous state. After an end operation, the list of matched elements will
762 * revert to the last state of matched elements.
764 * If there was no destructive operation before, an empty set is returned.
766 * @example $("p").find("span").end();
767 * @before <p><span>Hello</span>, how are you?</p>
768 * @result [ <p>...</p> ]
769 * @desc Selects all paragraphs, finds span elements inside these, and reverts the
770 * selection back to the paragraphs.
774 * @cat DOM/Traversing
777 return this.prevObject || jQuery([]);
781 * Searches for all elements that match the specified expression.
783 * This method is a good way to find additional descendant
784 * elements with which to process.
786 * All searching is done using a jQuery expression. The expression can be
787 * written using CSS 1-3 Selector syntax, or basic XPath.
789 * @example $("p").find("span");
790 * @before <p><span>Hello</span>, how are you?</p>
791 * @result [ <span>Hello</span> ]
792 * @desc Starts with all paragraphs and searches for descendant span
793 * elements, same as $("p span")
797 * @param String expr An expression to search with.
798 * @cat DOM/Traversing
801 return this.set( jQuery.map( this, function(a){
802 return jQuery.find(t,a);
807 * Clone matched DOM Elements and select the clones.
809 * This is useful for moving copies of the elements to another
810 * location in the DOM.
812 * @example $("b").clone().prependTo("p");
813 * @before <b>Hello</b><p>, how are you?</p>
814 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
815 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
819 * @cat DOM/Manipulation
821 clone: function(deep) {
822 return this.set( jQuery.map( this, function(a){
823 return a.cloneNode( deep != undefined ? deep : true );
828 * Removes all elements from the set of matched elements that do not
829 * match the specified expression(s). This method is used to narrow down
830 * the results of a search.
832 * Provide a String array of expressions to apply multiple filters at once.
834 * @example $("p").filter(".selected")
835 * @before <p class="selected">Hello</p><p>How are you?</p>
836 * @result [ <p class="selected">Hello</p> ]
837 * @desc Selects all paragraphs and removes those without a class "selected".
839 * @example $("p").filter([".selected", ":first"])
840 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
841 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
842 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
846 * @param String|Array<String> expression Expression(s) to search with.
847 * @cat DOM/Traversing
851 * Removes all elements from the set of matched elements that do not
852 * pass the specified filter. This method is used to narrow down
853 * the results of a search.
855 * @example $("p").filter(function(index) {
856 * return $("ol", this).length == 0;
858 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
859 * @result [ <p>How are you?</p> ]
860 * @desc Remove all elements that have a child ol element
864 * @param Function filter A function to use for filtering
865 * @cat DOM/Traversing
867 filter: function(t) {
869 t.constructor == Array &&
870 jQuery.map(this,function(a){
871 for ( var i = 0, tl = t.length; i < tl; i++ )
872 if ( jQuery.filter(t[i],[a]).r.length )
877 t.constructor == Boolean &&
878 ( t ? this.get() : [] ) ||
880 typeof t == "function" &&
881 jQuery.grep( this, function(el, index) { return t.apply(el, [index]) }) ||
883 jQuery.filter(t,this).r );
887 * Removes the specified Element from the set of matched elements. This
888 * method is used to remove a single Element from a jQuery object.
890 * @example $("p").not( $("#selected")[0] )
891 * @before <p>Hello</p><p id="selected">Hello Again</p>
892 * @result [ <p>Hello</p> ]
893 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
897 * @param Element el An element to remove from the set
898 * @cat DOM/Traversing
902 * Removes elements matching the specified expression from the set
903 * of matched elements. This method is used to remove one or more
904 * elements from a jQuery object.
906 * @example $("p").not("#selected")
907 * @before <p>Hello</p><p id="selected">Hello Again</p>
908 * @result [ <p>Hello</p> ]
909 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
913 * @param String expr An expression with which to remove matching elements
914 * @cat DOM/Traversing
917 return this.set( typeof t == "string" ?
918 jQuery.filter(t,this,true).r :
919 jQuery.grep(this,function(a){ return a != t; }) );
923 * Adds the elements matched by the expression to the jQuery object. This
924 * can be used to concatenate the result sets of two expressions.
926 * @example $("p").add("span")
927 * @before <p>Hello</p><p><span>Hello Again</span></p>
928 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
932 * @param String expr An expression whose matched elements are added
933 * @cat DOM/Traversing
937 * Adds one or more Elements to the set of matched elements.
939 * This is used to add a set of Elements to a jQuery object.
941 * @example $("p").add( document.getElementById("a") )
942 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
943 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
945 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
946 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
947 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
951 * @param Element|Array<Element> elements One or more Elements to add
952 * @cat DOM/Traversing
955 return this.set( jQuery.merge(
956 this.get(), typeof t == "string" ?
958 t.constructor == Array ? t : [t] ) );
962 * Checks the current selection against an expression and returns true,
963 * if at least one element of the selection fits the given expression.
965 * Does return false, if no element fits or the expression is not valid.
967 * filter(String) is used internally, therefore all rules that apply there
970 * @example $("input[@type='checkbox']").parent().is("form")
971 * @before <form><input type="checkbox" /></form>
973 * @desc Returns true, because the parent of the input is a form element
975 * @example $("input[@type='checkbox']").parent().is("form")
976 * @before <form><p><input type="checkbox" /></p></form>
978 * @desc Returns false, because the parent of the input is a p element
982 * @param String expr The expression with which to filter
983 * @cat DOM/Traversing
986 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
990 * Get the current value of the first matched element.
992 * @example $("input").val();
993 * @before <input type="text" value="some text"/>
994 * @result "some text"
998 * @cat DOM/Attributes
1002 * Set the value of every matched element.
1004 * @example $("input").val("test");
1005 * @before <input type="text" value="some text"/>
1006 * @result <input type="text" value="test"/>
1010 * @param String val Set the property to the specified value.
1011 * @cat DOM/Attributes
1013 val: function( val ) {
1014 return val == undefined ?
\r ( this.length ? this[0].value : null ) :
\r this.attr( "value", val );
1018 * Get the html contents of the first matched element.
1019 * This property is not available on XML documents.
1021 * @example $("div").html();
1022 * @before <div><input/></div>
1027 * @cat DOM/Attributes
1031 * Set the html contents of every matched element.
1032 * This property is not available on XML documents.
1034 * @example $("div").html("<b>new stuff</b>");
1035 * @before <div><input/></div>
1036 * @result <div><b>new stuff</b></div>
1040 * @param String val Set the html contents to the specified value.
1041 * @cat DOM/Attributes
1043 html: function( val ) {
1044 return val == undefined ?
\r ( this.length ? this[0].innerHTML : null ) :
\r this.attr( "innerHTML", val );
1051 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1052 * @param Number dir If dir<0, process args in reverse order.
1053 * @param Function fn The function doing the DOM manipulation.
1057 domManip: function(args, table, dir, fn){
1058 var clone = this.length > 1;
1059 var a = jQuery.clean(args);
1063 return this.each(function(){
1066 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1067 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1069 for ( var i = 0, al = a.length; i < al; i++ )
1070 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1077 * Extends the jQuery object itself. Can be used to add functions into
1078 * the jQuery namespace and to add plugin methods (plugins).
1080 * @example jQuery.fn.extend({
1081 * check: function() {
1082 * return this.each(function() { this.checked = true; });
1084 * uncheck: function() {
1085 * return this.each(function() { this.checked = false; });
1088 * $("input[@type=checkbox]").check();
1089 * $("input[@type=radio]").uncheck();
1090 * @desc Adds two plugin methods.
1092 * @example jQuery.extend({
1093 * min: function(a, b) { return a < b ? a : b; },
1094 * max: function(a, b) { return a > b ? a : b; }
1096 * @desc Adds two functions into the jQuery namespace
1099 * @param Object prop The object that will be merged into the jQuery object
1105 * Extend one object with one or more others, returning the original,
1106 * modified, object. This is a great utility for simple inheritance.
1108 * @example var settings = { validate: false, limit: 5, name: "foo" };
1109 * var options = { validate: true, name: "bar" };
1110 * jQuery.extend(settings, options);
1111 * @result settings == { validate: true, limit: 5, name: "bar" }
1112 * @desc Merge settings and options, modifying settings
1114 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1115 * var options = { validate: true, name: "bar" };
1116 * var settings = jQuery.extend({}, defaults, options);
1117 * @result settings == { validate: true, limit: 5, name: "bar" }
1118 * @desc Merge defaults and options, without modifying the defaults
1121 * @param Object target The object to extend
1122 * @param Object prop1 The object that will be merged into the first.
1123 * @param Object propN (optional) More objects to merge into the first
1127 jQuery.extend = jQuery.fn.extend = function() {
1128 // copy reference to target object
1129 var target = arguments[0],
1132 // extend jQuery itself if only one argument is passed
1133 if ( arguments.length == 1 ) {
1138 while (prop = arguments[a++])
1139 // Extend the base object
1140 for ( var i in prop ) target[i] = prop[i];
1142 // Return the modified object
1148 * Run this function to give control of the $ variable back
1149 * to whichever library first implemented it. This helps to make
1150 * sure that jQuery doesn't conflict with the $ object
1151 * of other libraries.
1153 * By using this function, you will only be able to access jQuery
1154 * using the 'jQuery' variable. For example, where you used to do
1155 * $("div p"), you now must do jQuery("div p").
1157 * @example jQuery.noConflict();
1158 * // Do something with jQuery
1159 * jQuery("div p").hide();
1160 * // Do something with another library's $()
1161 * $("content").style.display = 'none';
1162 * @desc Maps the original object that was referenced by $ back to $
1164 * @example jQuery.noConflict();
1167 * // more code using $ as alias to jQuery
1170 * // other code using $ as an alias to the other library
1171 * @desc Reverts the $ alias and then creates and executes a
1172 * function to provide the $ as a jQuery alias inside the functions
1173 * scope. Inside the function the original $ object is not available.
1174 * This works well for most plugins that don't rely on any other library.
1177 * @name $.noConflict
1181 noConflict: function() {
1187 * A generic iterator function, which can be used to seemlessly
1188 * iterate over both objects and arrays. This function is not the same
1189 * as $().each() - which is used to iterate, exclusively, over a jQuery
1190 * object. This function can be used to iterate over anything.
1192 * The callback has two arguments:the key (objects) or index (arrays) as first
1193 * the first, and the value as the second.
1195 * @example $.each( [0,1,2], function(i, n){
1196 * alert( "Item #" + i + ": " + n );
1198 * @desc This is an example of iterating over the items in an array,
1199 * accessing both the current item and its index.
1201 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1202 * alert( "Name: " + i + ", Value: " + n );
1205 * @desc This is an example of iterating over the properties in an
1206 * Object, accessing both the current item and its key.
1209 * @param Object obj The object, or array, to iterate over.
1210 * @param Function fn The function that will be executed on every object.
1214 // args is for internal usage only
1215 each: function( obj, fn, args ) {
1216 if ( obj.length == undefined )
1217 for ( var i in obj )
1218 fn.apply( obj[i], args || [i, obj[i]] );
1220 for ( var i = 0, ol = obj.length; i < ol; i++ )
1221 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1225 prop: function(elem, key, value){
1226 // Handle executable functions
1227 return value.constructor == Function &&
1228 value.call( elem ) || value;
1232 add: function( elem, c ){
1233 jQuery.each( c.split(/\s+/), function(i, cur){
1234 if ( !jQuery.className.has( elem.className, cur ) )
1235 elem.className += ( elem.className ? " " : "" ) + cur;
1238 remove: function( elem, c ){
1239 elem.className = c ?
1240 jQuery.grep( elem.className.split(/\s+/), function(cur){
1241 return !jQuery.className.has( c, cur );
1244 has: function( classes, c ){
1245 return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
1250 * Swap in/out style options.
1253 swap: function(e,o,f) {
1254 for ( var i in o ) {
1255 e.style["old"+i] = e.style[i];
1260 e.style[i] = e.style["old"+i];
1263 css: function(e,p) {
1264 if ( p == "height" || p == "width" ) {
1265 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1267 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1268 old["padding" + d[i]] = 0;
1269 old["border" + d[i] + "Width"] = 0;
1272 jQuery.swap( e, old, function() {
1273 if (jQuery.css(e,"display") != "none") {
1274 oHeight = e.offsetHeight;
1275 oWidth = e.offsetWidth;
1277 e = jQuery(e.cloneNode(true))
1278 .find(":radio").removeAttr("checked").end()
1280 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1281 }).appendTo(e.parentNode)[0];
1283 var parPos = jQuery.css(e.parentNode,"position");
1284 if ( parPos == "" || parPos == "static" )
1285 e.parentNode.style.position = "relative";
1287 oHeight = e.clientHeight;
1288 oWidth = e.clientWidth;
1290 if ( parPos == "" || parPos == "static" )
1291 e.parentNode.style.position = "static";
1293 e.parentNode.removeChild(e);
1297 return p == "height" ? oHeight : oWidth;
1300 return jQuery.curCSS( e, p );
1303 curCSS: function(elem, prop, force) {
1306 if (prop == 'opacity' && jQuery.browser.msie)
1307 return jQuery.attr(elem.style, 'opacity');
1309 if (prop == "float" || prop == "cssFloat")
1310 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1312 if (!force && elem.style[prop]) {
1314 ret = elem.style[prop];
1316 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1318 if (prop == "cssFloat" || prop == "styleFloat")
1321 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1322 var cur = document.defaultView.getComputedStyle(elem, null);
1325 ret = cur.getPropertyValue(prop);
1326 else if ( prop == 'display' )
1329 jQuery.swap(elem, { display: 'block' }, function() {
1330 var c = document.defaultView.getComputedStyle(this, '');
1331 ret = c && c.getPropertyValue(prop) || '';
1334 } else if (elem.currentStyle) {
1336 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1337 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1344 clean: function(a) {
1346 for ( var i = 0, al = a.length; i < al; i++ ) {
1348 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
1349 // Trim whitespace, otherwise indexOf won't work as expected
1350 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6),
1351 div = document.createElement("div"), wrap = [0,"",""];
1353 if ( s.substring(0,4) == "<opt" ) // option or optgroup
1354 wrap = [1, "<select>", "</select>"];
1355 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" )
1356 wrap = [1, "<table>", "</table>"];
1357 else if ( s3 == "<tr" )
1358 wrap = [2, "<table><tbody>", "</tbody></table>"];
1359 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above
1360 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1362 // Go to html and back, then peel off extra wrappers
1363 div.innerHTML = wrap[1] + s + wrap[2];
1364 while ( wrap[0]-- ) div = div.firstChild;
1366 // Remove IE's autoinserted <tbody> from table fragments
1367 if ( jQuery.browser.msie ) {
1369 // String was a <table>, *may* have spurious <tbody>
1370 if ( s6 == "<table" && s.indexOf("<tbody") < 0 )
1371 tb = div.firstChild && div.firstChild.childNodes;
1372 // String was a bare <thead> or <tfoot>
1373 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1374 tb = div.childNodes;
1376 for ( var n = tb.length-1; n >= 0 ; --n )
1377 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1378 tb[n].parentNode.removeChild(tb[n]);
1382 arg = div.childNodes;
1386 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1387 for ( var n = 0, argl = arg.length; n < argl; n++ ) // Handles Array, jQuery, DOM NodeList collections
1390 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1396 attr: function(elem, name, value){
1399 "class": "className",
1400 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1401 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1402 innerHTML: "innerHTML",
1403 className: "className",
1405 disabled: "disabled",
1407 readonly: "readOnly",
1408 selected: "selected"
1411 // IE actually uses filters for opacity ... elem is actually elem.style
1412 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1413 // IE has trouble with opacity if it does not have layout
1414 // Force it by setting the zoom level
1417 // Set the alpha filter to set the opacity
1418 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1419 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1421 } else if ( name == "opacity" && jQuery.browser.msie ) {
1422 return elem.filter ?
1423 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1426 // Mozilla doesn't play well with opacity 1
1427 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1430 // Certain attributes only work when accessed via the old DOM 0 way
1432 if ( value != undefined ) elem[fix[name]] = value;
1433 return elem[fix[name]];
1435 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1436 return elem.getAttributeNode(name).nodeValue;
1438 // IE elem.getAttribute passes even for style
1439 } else if ( elem.tagName ) {
1440 if ( value != undefined ) elem.setAttribute( name, value );
1441 return elem.getAttribute( name );
1444 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1445 if ( value != undefined ) elem[name] = value;
1451 * Remove the whitespace from the beginning and end of a string.
1453 * @example $.trim(" hello, how are you? ");
1454 * @result "hello, how are you?"
1458 * @param String str The string to trim.
1462 return t.replace(/^\s+|\s+$/g, "");
1465 makeArray: function( a ) {
1468 if ( a.constructor != Array ) {
1469 for ( var i = 0, al = a.length; i < al; i++ )
1477 inArray: function( b, a ) {
1478 for ( var i = 0, al = a.length; i < al; i++ )
1485 * Merge two arrays together, removing all duplicates.
1487 * The new array is: All the results from the first array, followed
1488 * by the unique results from the second array.
1490 * @example $.merge( [0,1,2], [2,3,4] )
1491 * @result [0,1,2,3,4]
1492 * @desc Merges two arrays, removing the duplicate 2
1494 * @example $.merge( [3,2,1], [4,3,2] )
1496 * @desc Merges two arrays, removing the duplicates 3 and 2
1500 * @param Array first The first array to merge.
1501 * @param Array second The second array to merge.
1504 merge: function(first, second) {
1505 var r = [].slice.call( first, 0 );
1507 // Now check for duplicates between the two arrays
1508 // and only add the unique items
1509 for ( var i = 0, sl = second.length; i < sl; i++ ) {
1510 // Check for duplicates
1511 if ( jQuery.inArray( second[i], r ) == -1 )
1512 // The item is unique, add it
1513 first.push( second[i] );
1520 * Filter items out of an array, by using a filter function.
1522 * The specified function will be passed two arguments: The
1523 * current array item and the index of the item in the array. The
1524 * function must return 'true' to keep the item in the array,
1525 * false to remove it.
1527 * @example $.grep( [0,1,2], function(i){
1534 * @param Array array The Array to find items in.
1535 * @param Function fn The function to process each item against.
1536 * @param Boolean inv Invert the selection - select the opposite of the function.
1539 grep: function(elems, fn, inv) {
1540 // If a string is passed in for the function, make a function
1541 // for it (a handy shortcut)
1542 if ( typeof fn == "string" )
1543 fn = new Function("a","i","return " + fn);
1547 // Go through the array, only saving the items
1548 // that pass the validator function
1549 for ( var i = 0, el = elems.length; i < el; i++ )
1550 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1551 result.push( elems[i] );
1557 * Translate all items in an array to another array of items.
1559 * The translation function that is provided to this method is
1560 * called for each item in the array and is passed one argument:
1561 * The item to be translated.
1563 * The function can then return the translated value, 'null'
1564 * (to remove the item), or an array of values - which will
1565 * be flattened into the full array.
1567 * @example $.map( [0,1,2], function(i){
1571 * @desc Maps the original array to a new one and adds 4 to each value.
1573 * @example $.map( [0,1,2], function(i){
1574 * return i > 0 ? i + 1 : null;
1577 * @desc Maps the original array to a new one and adds 1 to each
1578 * value if it is bigger then zero, otherwise it's removed-
1580 * @example $.map( [0,1,2], function(i){
1581 * return [ i, i + 1 ];
1583 * @result [0, 1, 1, 2, 2, 3]
1584 * @desc Maps the original array to a new one, each element is added
1585 * with it's original value and the value plus one.
1589 * @param Array array The Array to translate.
1590 * @param Function fn The function to process each item against.
1593 map: function(elems, fn) {
1594 // If a string is passed in for the function, make a function
1595 // for it (a handy shortcut)
1596 if ( typeof fn == "string" )
1597 fn = new Function("a","return " + fn);
1599 var result = [], r = [];
1601 // Go through the array, translating each of the items to their
1602 // new value (or values).
1603 for ( var i = 0, el = elems.length; i < el; i++ ) {
1604 var val = fn(elems[i],i);
1606 if ( val !== null && val != undefined ) {
1607 if ( val.constructor != Array ) val = [val];
1608 result = result.concat( val );
1612 var r = result.length ? [ result[0] ] : [];
1614 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1615 for ( var j = 0; j < i; j++ )
1616 if ( result[i] == r[j] )
1619 r.push( result[i] );
1627 * Contains flags for the useragent, read from navigator.userAgent.
1628 * Available flags are: safari, opera, msie, mozilla
1630 * This property is available before the DOM is ready, therefore you can
1631 * use it to add ready events only for certain browsers.
1633 * There are situations where object detections is not reliable enough, in that
1634 * cases it makes sense to use browser detection. Simply try to avoid both!
1636 * A combination of browser and object detection yields quite reliable results.
1638 * @example $.browser.msie
1639 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1641 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1642 * @desc Alerts "this is safari!" only for safari browsers
1651 * Wheather the W3C compliant box model is being used.
1659 var b = navigator.userAgent.toLowerCase();
1661 // Figure out what browser is being used
1663 safari: /webkit/.test(b),
1664 opera: /opera/.test(b),
1665 msie: /msie/.test(b) && !/opera/.test(b),
1666 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1669 // Check to see if the W3C box model is being used
1670 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1674 * Get a set of elements containing the unique parents of the matched
1677 * Can be filtered with an optional expressions.
1679 * @example $("p").parent()
1680 * @before <div><p>Hello</p><p>Hello</p></div>
1681 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1682 * @desc Find the parent element of each paragraph.
1684 * @example $("p").parent(".selected")
1685 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1686 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1687 * @desc Find the parent element of each paragraph with a class "selected".
1691 * @param String expr (optional) An expression to filter the parents with
1692 * @cat DOM/Traversing
1696 * Get a set of elements containing the unique ancestors of the matched
1697 * set of elements (except for the root element).
1699 * Can be filtered with an optional expressions.
1701 * @example $("span").parents()
1702 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1703 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1704 * @desc Find all parent elements of each span.
1706 * @example $("span").parents("p")
1707 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1708 * @result [ <p><span>Hello</span></p> ]
1709 * @desc Find all parent elements of each span that is a paragraph.
1713 * @param String expr (optional) An expression to filter the ancestors with
1714 * @cat DOM/Traversing
1718 * Get a set of elements containing the unique next siblings of each of the
1719 * matched set of elements.
1721 * It only returns the very next sibling, not all next siblings.
1723 * Can be filtered with an optional expressions.
1725 * @example $("p").next()
1726 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1727 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1728 * @desc Find the very next sibling of each paragraph.
1730 * @example $("p").next(".selected")
1731 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1732 * @result [ <p class="selected">Hello Again</p> ]
1733 * @desc Find the very next sibling of each paragraph that has a class "selected".
1737 * @param String expr (optional) An expression to filter the next Elements with
1738 * @cat DOM/Traversing
1742 * Get a set of elements containing the unique previous siblings of each of the
1743 * matched set of elements.
1745 * Can be filtered with an optional expressions.
1747 * It only returns the immediately previous sibling, not all previous siblings.
1749 * @example $("p").prev()
1750 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1751 * @result [ <div><span>Hello Again</span></div> ]
1752 * @desc Find the very previous sibling of each paragraph.
1754 * @example $("p").prev(".selected")
1755 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1756 * @result [ <div><span>Hello</span></div> ]
1757 * @desc Find the very previous sibling of each paragraph that has a class "selected".
1761 * @param String expr (optional) An expression to filter the previous Elements with
1762 * @cat DOM/Traversing
1766 * Get a set of elements containing all of the unique siblings of each of the
1767 * matched set of elements.
1769 * Can be filtered with an optional expressions.
1771 * @example $("div").siblings()
1772 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1773 * @result [ <p>Hello</p>, <p>And Again</p> ]
1774 * @desc Find all siblings of each div.
1776 * @example $("div").siblings(".selected")
1777 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1778 * @result [ <p class="selected">Hello Again</p> ]
1779 * @desc Find all siblings with a class "selected" of each div.
1783 * @param String expr (optional) An expression to filter the sibling Elements with
1784 * @cat DOM/Traversing
1788 * Get a set of elements containing all of the unique children of each of the
1789 * matched set of elements.
1791 * Can be filtered with an optional expressions.
1793 * @example $("div").children()
1794 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1795 * @result [ <span>Hello Again</span> ]
1796 * @desc Find all children of each div.
1798 * @example $("div").children(".selected")
1799 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1800 * @result [ <p class="selected">Hello Again</p> ]
1801 * @desc Find all children with a class "selected" of each div.
1805 * @param String expr (optional) An expression to filter the child Elements with
1806 * @cat DOM/Traversing
1809 parent: "a.parentNode",
1810 parents: jQuery.parents,
1811 next: "jQuery.nth(a,1,'nextSibling')",
1812 prev: "jQuery.nth(a,1,'previousSibling')",
1813 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1814 children: "jQuery.sibling(a.firstChild)"
1816 jQuery.fn[ i ] = function(a) {
1817 var ret = jQuery.map(this,n);
1818 if ( a && typeof a == "string" )
1819 ret = jQuery.filter(a,ret).r;
1820 return this.set( ret );
1825 * Append all of the matched elements to another, specified, set of elements.
1826 * This operation is, essentially, the reverse of doing a regular
1827 * $(A).append(B), in that instead of appending B to A, you're appending
1830 * @example $("p").appendTo("#foo");
1831 * @before <p>I would like to say: </p><div id="foo"></div>
1832 * @result <div id="foo"><p>I would like to say: </p></div>
1833 * @desc Appends all paragraphs to the element with the ID "foo"
1837 * @param String expr A jQuery expression of elements to match.
1838 * @cat DOM/Manipulation
1842 * Prepend all of the matched elements to another, specified, set of elements.
1843 * This operation is, essentially, the reverse of doing a regular
1844 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1847 * @example $("p").prependTo("#foo");
1848 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1849 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1850 * @desc Prepends all paragraphs to the element with the ID "foo"
1854 * @param String expr A jQuery expression of elements to match.
1855 * @cat DOM/Manipulation
1859 * Insert all of the matched elements before another, specified, set of elements.
1860 * This operation is, essentially, the reverse of doing a regular
1861 * $(A).before(B), in that instead of inserting B before A, you're inserting
1864 * @example $("p").insertBefore("#foo");
1865 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1866 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1867 * @desc Same as $("#foo").before("p")
1869 * @name insertBefore
1871 * @param String expr A jQuery expression of elements to match.
1872 * @cat DOM/Manipulation
1876 * Insert all of the matched elements after another, specified, set of elements.
1877 * This operation is, essentially, the reverse of doing a regular
1878 * $(A).after(B), in that instead of inserting B after A, you're inserting
1881 * @example $("p").insertAfter("#foo");
1882 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1883 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1884 * @desc Same as $("#foo").after("p")
1888 * @param String expr A jQuery expression of elements to match.
1889 * @cat DOM/Manipulation
1894 prependTo: "prepend",
1895 insertBefore: "before",
1896 insertAfter: "after"
1898 jQuery.fn[ i ] = function(){
1900 return this.each(function(){
1901 for ( var j = 0, al = a.length; j < al; j++ )
1902 jQuery(a[j])[n]( this );
1908 * Remove an attribute from each of the matched elements.
1910 * @example $("input").removeAttr("disabled")
1911 * @before <input disabled="disabled"/>
1916 * @param String name The name of the attribute to remove.
1917 * @cat DOM/Attributes
1921 * Displays each of the set of matched elements if they are hidden.
1923 * @example $("p").show()
1924 * @before <p style="display: none">Hello</p>
1925 * @result [ <p style="display: block">Hello</p> ]
1933 * Hides each of the set of matched elements if they are shown.
1935 * @example $("p").hide()
1936 * @before <p>Hello</p>
1937 * @result [ <p style="display: none">Hello</p> ]
1939 * var pass = true, div = $("div");
1940 * div.hide().each(function(){
1941 * if ( this.style.display != "none" ) pass = false;
1943 * ok( pass, "Hide" );
1951 * Toggles each of the set of matched elements. If they are shown,
1952 * toggle makes them hidden. If they are hidden, toggle
1955 * @example $("p").toggle()
1956 * @before <p>Hello</p><p style="display: none">Hello Again</p>
1957 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
1965 * Adds the specified class to each of the set of matched elements.
1967 * @example $("p").addClass("selected")
1968 * @before <p>Hello</p>
1969 * @result [ <p class="selected">Hello</p> ]
1973 * @param String class A CSS class to add to the elements
1974 * @cat DOM/Attributes
1975 * @see removeClass(String)
1979 * Removes all or the specified class from the set of matched elements.
1981 * @example $("p").removeClass()
1982 * @before <p class="selected">Hello</p>
1983 * @result [ <p>Hello</p> ]
1985 * @example $("p").removeClass("selected")
1986 * @before <p class="selected first">Hello</p>
1987 * @result [ <p class="first">Hello</p> ]
1991 * @param String class (optional) A CSS class to remove from the elements
1992 * @cat DOM/Attributes
1993 * @see addClass(String)
1997 * Adds the specified class if it is not present, removes it if it is
2000 * @example $("p").toggleClass("selected")
2001 * @before <p>Hello</p><p class="selected">Hello Again</p>
2002 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2006 * @param String class A CSS class with which to toggle the elements
2007 * @cat DOM/Attributes
2011 * Removes all matched elements from the DOM. This does NOT remove them from the
2012 * jQuery object, allowing you to use the matched elements further.
2014 * Can be filtered with an optional expressions.
2016 * @example $("p").remove();
2017 * @before <p>Hello</p> how are <p>you?</p>
2020 * @example $("p").remove(".hello");
2021 * @before <p class="hello">Hello</p> how are <p>you?</p>
2022 * @result how are <p>you?</p>
2026 * @param String expr (optional) A jQuery expression to filter elements by.
2027 * @cat DOM/Manipulation
2031 * Removes all child nodes from the set of matched elements.
2033 * @example $("p").empty()
2034 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2035 * @result [ <p></p> ]
2039 * @cat DOM/Manipulation
2043 removeAttr: function( key ) {
2044 jQuery.attr( this, key, "" );
2045 this.removeAttribute( key );
2048 this.style.display = this.oldblock ? this.oldblock : "";
2049 if ( jQuery.css(this,"display") == "none" )
2050 this.style.display = "block";
2053 this.oldblock = this.oldblock || jQuery.css(this,"display");
2054 if ( this.oldblock == "none" )
2055 this.oldblock = "block";
2056 this.style.display = "none";
2059 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2061 addClass: function(c){
2062 jQuery.className.add(this,c);
2064 removeClass: function(c){
2065 jQuery.className.remove(this,c);
2067 toggleClass: function( c ){
2068 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2070 remove: function(a){
2071 if ( !a || jQuery.filter( a, [this] ).r )
2072 this.parentNode.removeChild( this );
2075 while ( this.firstChild )
2076 this.removeChild( this.firstChild );
2079 jQuery.fn[ i ] = function() {
2080 return this.each( n, arguments );
2085 * Reduce the set of matched elements to a single element.
2086 * The position of the element in the set of matched elements
2087 * starts at 0 and goes to length - 1.
2089 * @example $("p").eq(1)
2090 * @before <p>This is just a test.</p><p>So is this</p>
2091 * @result [ <p>So is this</p> ]
2095 * @param Number pos The index of the element that you wish to limit to.
2100 * Reduce the set of matched elements to all elements before a given position.
2101 * The position of the element in the set of matched elements
2102 * starts at 0 and goes to length - 1.
2104 * @example $("p").lt(1)
2105 * @before <p>This is just a test.</p><p>So is this</p>
2106 * @result [ <p>This is just a test.</p> ]
2110 * @param Number pos Reduce the set to all elements below this position.
2115 * Reduce the set of matched elements to all elements after a given position.
2116 * The position of the element in the set of matched elements
2117 * starts at 0 and goes to length - 1.
2119 * @example $("p").gt(0)
2120 * @before <p>This is just a test.</p><p>So is this</p>
2121 * @result [ <p>So is this</p> ]
2125 * @param Number pos Reduce the set to all elements after this position.
2130 * Filter the set of elements to those that contain the specified text.
2132 * @example $("p").contains("test")
2133 * @before <p>This is just a test.</p><p>So is this</p>
2134 * @result [ <p>This is just a test.</p> ]
2138 * @param String str The string that will be contained within the text of an element.
2139 * @cat DOM/Traversing
2141 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2142 jQuery.fn[ n ] = function(num,fn) {
2143 return this.filter( ":" + n + "(" + num + ")", fn );