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, $() looks for DOM elements within the context of the
80 * current HTML document.
82 * @example $("div > p")
83 * @desc Finds all p elements that are children of a div element.
84 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
85 * @result [ <p>two</p> ]
87 * @example $("input:radio", document.forms[0])
88 * @desc Searches for all inputs of type radio within the first form in the document
90 * @example $("div", xml.responseXML)
91 * @desc This finds all div elements within the specified XML document.
94 * @param String expr An expression to search with
95 * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
99 * @see $(Element<Array>)
103 * Create DOM elements on-the-fly from the provided String of raw HTML.
105 * @example $("<div><p>Hello</p></div>").appendTo("#body")
106 * @desc Creates a div element (and all of its contents) dynamically,
107 * and appends it to the element with the ID of body. Internally, an
108 * element is created and it's innerHTML property set to the given markup.
109 * It is therefore both quite flexible and limited.
112 * @param String html A string of HTML to create on the fly.
115 * @see appendTo(String)
119 * Wrap jQuery functionality around a single or multiple DOM Element(s).
121 * This function also accepts XML Documents and Window objects
122 * as valid arguments (even though they are not DOM Elements).
124 * @example $(document.body).background( "black" );
125 * @desc Sets the background color of the page to black.
127 * @example $( myForm.elements ).hide()
128 * @desc Hides all the input elements within a form
131 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
137 * A shorthand for $(document).ready(), allowing you to bind a function
138 * to be executed when the DOM document has finished loading. This function
139 * behaves just like $(document).ready(), in that it should be used to wrap
140 * all of the other $() operations on your page. While this function is,
141 * technically, chainable - there really isn't much use for chaining against it.
142 * You can have as many $(document).ready events on your page as you like.
144 * See ready(Function) for details about the ready event.
146 * @example $(function(){
147 * // Document is ready
149 * @desc Executes the function when the DOM is ready to be used.
151 * @example jQuery(function($) {
152 * // Your code using failsafe $ alias here...
154 * @desc Uses both the shortcut for $(document).ready() and the argument
155 * to write failsafe jQuery code using the $ alias, without relying on the
159 * @param Function fn The function to execute when the DOM is ready.
162 * @see ready(Function)
165 jQuery.fn = jQuery.prototype = {
167 * The current version of jQuery.
178 * The number of elements currently matched.
180 * @example $("img").length;
181 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
191 * The number of elements currently matched.
193 * @example $("img").size();
194 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
208 * Access all matched elements. This serves as a backwards-compatible
209 * way of accessing all matched elements (other than the jQuery object
210 * itself, which is, in fact, an array of elements).
212 * @example $("img").get();
213 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
214 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
215 * @desc Selects all images in the document and returns the DOM Elements as an Array
218 * @type Array<Element>
223 * Access a single matched element. num is used to access the
224 * Nth element matched.
226 * @example $("img").get(0);
227 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
228 * @result [ <img src="test1.jpg"/> ]
229 * @desc Selects all images in the document and returns the first one
233 * @param Number num Access the element in the Nth position.
236 get: function( num ) {
237 return num == undefined ?
239 // Return a 'clean' array
240 jQuery.makeArray( this ) :
242 // Return just the object
247 * Set the jQuery object to an array of elements, while maintaining
250 * @example $("img").pushStack([ document.body ]);
251 * @result $("img").pushStack() == [ document.body ]
256 * @param Elements elems An array of elements
259 pushStack: function( a ) {
261 ret.prevObject = this;
266 * Set the jQuery object to an array of elements. This operation is
267 * completely destructive - be sure to use .pushStack() if you wish to maintain
270 * @example $("img").setArray([ document.body ]);
271 * @result $("img").setArray() == [ document.body ]
276 * @param Elements elems An array of elements
279 setArray: function( a ) {
281 [].push.apply( this, a );
286 * Execute a function within the context of every matched element.
287 * This means that every time the passed-in function is executed
288 * (which is once for every element matched) the 'this' keyword
289 * points to the specific element.
291 * Additionally, the function, when executed, is passed a single
292 * argument representing the position of the element in the matched
295 * @example $("img").each(function(i){
296 * this.src = "test" + i + ".jpg";
298 * @before <img/><img/>
299 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
300 * @desc Iterates over two images and sets their src property
304 * @param Function fn A function to execute
307 each: function( fn, args ) {
308 return jQuery.each( this, fn, args );
312 * Searches every matched element for the object and returns
313 * the index of the element, if found, starting with zero.
314 * Returns -1 if the object wasn't found.
316 * @example $("*").index( $('#foobar')[0] )
317 * @before <div id="foobar"><b></b><span id="foo"></span></div>
319 * @desc Returns the index for the element with ID foobar
321 * @example $("*").index( $('#foo')[0] )
322 * @before <div id="foobar"><b></b><span id="foo"></span></div>
324 * @desc Returns the index for the element with ID foo within another element
326 * @example $("*").index( $('#bar')[0] )
327 * @before <div id="foobar"><b></b><span id="foo"></span></div>
329 * @desc Returns -1, as there is no element with ID bar
333 * @param Element subject Object to search for
336 index: function( obj ) {
338 this.each(function(i){
339 if ( this == obj ) pos = i;
345 * Access a property on the first matched element.
346 * This method makes it easy to retrieve a property value
347 * from the first matched element.
349 * @example $("img").attr("src");
350 * @before <img src="test.jpg"/>
352 * @desc Returns the src attribute from the first image in the document.
356 * @param String name The name of the property to access.
357 * @cat DOM/Attributes
361 * Set a key/value object as properties to all matched elements.
363 * This serves as the best way to set a large number of properties
364 * on all matched elements.
366 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
368 * @result <img src="test.jpg" alt="Test Image"/>
369 * @desc Sets src and alt attributes to all images.
373 * @param Map properties Key/value pairs to set as object properties.
374 * @cat DOM/Attributes
378 * Set a single property to a value, on all matched elements.
380 * Can compute values provided as ${formula}, see second example.
382 * Note that you can't set the name property of input elements in IE.
383 * Use $(html) or .append(html) or .html(html) to create elements
384 * on the fly including the name property.
386 * @example $("img").attr("src","test.jpg");
388 * @result <img src="test.jpg"/>
389 * @desc Sets src attribute to all images.
391 * @example $("img").attr("title", "${this.src}");
392 * @before <img src="test.jpg" />
393 * @result <img src="test.jpg" title="test.jpg" />
394 * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
398 * @param String key The name of the property to set.
399 * @param Object value The value to set the property to.
400 * @cat DOM/Attributes
404 * Set a single property to a computed value, on all matched elements.
406 * Instead of a value, a function is provided, that computes the value.
408 * @example $("img").attr("title", function() { return this.src });
409 * @before <img src="test.jpg" />
410 * @result <img src="test.jpg" title="test.jpg" />
411 * @desc Sets title attribute from src attribute.
413 * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
414 * @before <img title="pic" /><img title="pic" /><img title="pic" />
415 * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
416 * @desc Enumerate title attribute.
420 * @param String key The name of the property to set.
421 * @param Function value A function returning the value to set.
422 * Scope: Current element, argument: Index of current element
423 * @cat DOM/Attributes
425 attr: function( key, value, type ) {
428 // Look for the case where we're accessing a style value
429 if ( key.constructor == String )
430 if ( value == undefined )
431 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
437 // Check to see if we're setting style values
438 return this.each(function(index){
439 // Set all the styles
440 for ( var prop in obj )
442 type ? this.style : this,
443 prop, jQuery.prop(this, obj[prop], type, index, prop)
449 * Access a style property on the first matched element.
450 * This method makes it easy to retrieve a style property value
451 * from the first matched element.
453 * @example $("p").css("color");
454 * @before <p style="color:red;">Test Paragraph.</p>
456 * @desc Retrieves the color style of the first paragraph
458 * @example $("p").css("font-weight");
459 * @before <p style="font-weight: bold;">Test Paragraph.</p>
461 * @desc Retrieves the font-weight style of the first paragraph.
465 * @param String name The name of the property to access.
470 * Set a key/value object as style properties to all matched elements.
472 * This serves as the best way to set a large number of style properties
473 * on all matched elements.
475 * @example $("p").css({ color: "red", background: "blue" });
476 * @before <p>Test Paragraph.</p>
477 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
478 * @desc Sets color and background styles to all p elements.
482 * @param Map properties Key/value pairs to set as style properties.
487 * Set a single style property to a value, on all matched elements.
488 * If a number is provided, it is automatically converted into a pixel value.
490 * @example $("p").css("color","red");
491 * @before <p>Test Paragraph.</p>
492 * @result <p style="color:red;">Test Paragraph.</p>
493 * @desc Changes the color of all paragraphs to red
495 * @example $("p").css("left",30);
496 * @before <p>Test Paragraph.</p>
497 * @result <p style="left:30px;">Test Paragraph.</p>
498 * @desc Changes the left of all paragraphs to "30px"
502 * @param String key The name of the property to set.
503 * @param String|Number value The value to set the property to.
506 css: function( key, value ) {
507 return this.attr( key, value, "curCSS" );
511 * Get the text contents of all matched elements. The result is
512 * a string that contains the combined text contents of all matched
513 * elements. This method works on both HTML and XML documents.
515 * @example $("p").text();
516 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
517 * @result Test Paragraph.Paraparagraph
518 * @desc Gets the concatenated text of all paragraphs
522 * @cat DOM/Attributes
526 * Set the text contents of all matched elements.
528 * Similar to html(), but escapes HTML (replace "<" and ">" with their
531 * @example $("p").text("<b>Some</b> new text.");
532 * @before <p>Test Paragraph.</p>
533 * @result <p><b>Some</b> new text.</p>
534 * @desc Sets the text of all paragraphs.
536 * @example $("p").text("<b>Some</b> new text.", true);
537 * @before <p>Test Paragraph.</p>
538 * @result <p>Some new text.</p>
539 * @desc Sets the text of all paragraphs.
543 * @param String val The text value to set the contents of the element to.
544 * @cat DOM/Attributes
547 if ( typeof e == "string" )
548 return this.empty().append( document.createTextNode( e ) );
551 jQuery.each( e || this, function(){
552 jQuery.each( this.childNodes, function(){
553 if ( this.nodeType != 8 )
554 t += this.nodeType != 1 ?
555 this.nodeValue : jQuery.fn.text([ this ]);
562 * Wrap all matched elements with a structure of other elements.
563 * This wrapping process is most useful for injecting additional
564 * stucture into a document, without ruining the original semantic
565 * qualities of a document.
567 * This works by going through the first element
568 * provided (which is generated, on the fly, from the provided HTML)
569 * and finds the deepest ancestor element within its
570 * structure - it is that element that will en-wrap everything else.
572 * This does not work with elements that contain text. Any necessary text
573 * must be added after the wrapping is done.
575 * @example $("p").wrap("<div class='wrap'></div>");
576 * @before <p>Test Paragraph.</p>
577 * @result <div class='wrap'><p>Test Paragraph.</p></div>
581 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
582 * @cat DOM/Manipulation
586 * Wrap all matched elements with a structure of other elements.
587 * This wrapping process is most useful for injecting additional
588 * stucture into a document, without ruining the original semantic
589 * qualities of a document.
591 * This works by going through the first element
592 * provided and finding the deepest ancestor element within its
593 * structure - it is that element that will en-wrap everything else.
595 * This does not work with elements that contain text. Any necessary text
596 * must be added after the wrapping is done.
598 * @example $("p").wrap( document.getElementById('content') );
599 * @before <p>Test Paragraph.</p><div id="content"></div>
600 * @result <div id="content"><p>Test Paragraph.</p></div>
604 * @param Element elem A DOM element that will be wrapped around the target.
605 * @cat DOM/Manipulation
608 // The elements to wrap the target around
609 var a = jQuery.clean(arguments);
611 // Wrap each of the matched elements individually
612 return this.each(function(){
613 // Clone the structure that we're using to wrap
614 var b = a[0].cloneNode(true);
616 // Insert it before the element to be wrapped
617 this.parentNode.insertBefore( b, this );
619 // Find the deepest point in the wrap structure
620 while ( b.firstChild )
623 // Move the matched element to within the wrap structure
624 b.appendChild( this );
629 * Append content to the inside of every matched element.
631 * This operation is similar to doing an appendChild to all the
632 * specified elements, adding them into the document.
634 * @example $("p").append("<b>Hello</b>");
635 * @before <p>I would like to say: </p>
636 * @result <p>I would like to say: <b>Hello</b></p>
637 * @desc Appends some HTML to all paragraphs.
639 * @example $("p").append( $("#foo")[0] );
640 * @before <p>I would like to say: </p><b id="foo">Hello</b>
641 * @result <p>I would like to say: <b id="foo">Hello</b></p>
642 * @desc Appends an Element to all paragraphs.
644 * @example $("p").append( $("b") );
645 * @before <p>I would like to say: </p><b>Hello</b>
646 * @result <p>I would like to say: <b>Hello</b></p>
647 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
651 * @param <Content> content Content to append to the target
652 * @cat DOM/Manipulation
653 * @see prepend(<Content>)
654 * @see before(<Content>)
655 * @see after(<Content>)
658 return this.domManip(arguments, true, 1, function(a){
659 this.appendChild( a );
664 * Prepend content to the inside of every matched element.
666 * This operation is the best way to insert elements
667 * inside, at the beginning, of all matched elements.
669 * @example $("p").prepend("<b>Hello</b>");
670 * @before <p>I would like to say: </p>
671 * @result <p><b>Hello</b>I would like to say: </p>
672 * @desc Prepends some HTML to all paragraphs.
674 * @example $("p").prepend( $("#foo")[0] );
675 * @before <p>I would like to say: </p><b id="foo">Hello</b>
676 * @result <p><b id="foo">Hello</b>I would like to say: </p>
677 * @desc Prepends an Element to all paragraphs.
679 * @example $("p").prepend( $("b") );
680 * @before <p>I would like to say: </p><b>Hello</b>
681 * @result <p><b>Hello</b>I would like to say: </p>
682 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
686 * @param <Content> content Content to prepend to the target.
687 * @cat DOM/Manipulation
688 * @see append(<Content>)
689 * @see before(<Content>)
690 * @see after(<Content>)
692 prepend: function() {
693 return this.domManip(arguments, true, -1, function(a){
694 this.insertBefore( a, this.firstChild );
699 * Insert content before each of the matched elements.
701 * @example $("p").before("<b>Hello</b>");
702 * @before <p>I would like to say: </p>
703 * @result <b>Hello</b><p>I would like to say: </p>
704 * @desc Inserts some HTML before all paragraphs.
706 * @example $("p").before( $("#foo")[0] );
707 * @before <p>I would like to say: </p><b id="foo">Hello</b>
708 * @result <b id="foo">Hello</b><p>I would like to say: </p>
709 * @desc Inserts an Element before all paragraphs.
711 * @example $("p").before( $("b") );
712 * @before <p>I would like to say: </p><b>Hello</b>
713 * @result <b>Hello</b><p>I would like to say: </p>
714 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
718 * @param <Content> content Content to insert before each target.
719 * @cat DOM/Manipulation
720 * @see append(<Content>)
721 * @see prepend(<Content>)
722 * @see after(<Content>)
725 return this.domManip(arguments, false, 1, function(a){
726 this.parentNode.insertBefore( a, this );
731 * Insert content after each of the matched elements.
733 * @example $("p").after("<b>Hello</b>");
734 * @before <p>I would like to say: </p>
735 * @result <p>I would like to say: </p><b>Hello</b>
736 * @desc Inserts some HTML after all paragraphs.
738 * @example $("p").after( $("#foo")[0] );
739 * @before <b id="foo">Hello</b><p>I would like to say: </p>
740 * @result <p>I would like to say: </p><b id="foo">Hello</b>
741 * @desc Inserts an Element after all paragraphs.
743 * @example $("p").after( $("b") );
744 * @before <b>Hello</b><p>I would like to say: </p>
745 * @result <p>I would like to say: </p><b>Hello</b>
746 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
750 * @param <Content> content Content to insert after each target.
751 * @cat DOM/Manipulation
752 * @see append(<Content>)
753 * @see prepend(<Content>)
754 * @see before(<Content>)
757 return this.domManip(arguments, false, -1, function(a){
758 this.parentNode.insertBefore( a, this.nextSibling );
763 * End the most recent 'destructive' operation, reverting the list of matched elements
764 * back to its previous state. After an end operation, the list of matched elements will
765 * revert to the last state of matched elements.
767 * If there was no destructive operation before, an empty set is returned.
769 * @example $("p").find("span").end();
770 * @before <p><span>Hello</span>, how are you?</p>
771 * @result [ <p>...</p> ]
772 * @desc Selects all paragraphs, finds span elements inside these, and reverts the
773 * selection back to the paragraphs.
777 * @cat DOM/Traversing
780 return this.prevObject || jQuery([]);
784 * Searches for all elements that match the specified expression.
786 * This method is a good way to find additional descendant
787 * elements with which to process.
789 * All searching is done using a jQuery expression. The expression can be
790 * written using CSS 1-3 Selector syntax, or basic XPath.
792 * @example $("p").find("span");
793 * @before <p><span>Hello</span>, how are you?</p>
794 * @result [ <span>Hello</span> ]
795 * @desc Starts with all paragraphs and searches for descendant span
796 * elements, same as $("p span")
800 * @param String expr An expression to search with.
801 * @cat DOM/Traversing
804 return this.pushStack( jQuery.map( this, function(a){
805 return jQuery.find(t,a);
810 * Clone matched DOM Elements and select the clones.
812 * This is useful for moving copies of the elements to another
813 * location in the DOM.
815 * @example $("b").clone().prependTo("p");
816 * @before <b>Hello</b><p>, how are you?</p>
817 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
818 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
822 * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
823 * @cat DOM/Manipulation
825 clone: function(deep) {
826 return this.pushStack( jQuery.map( this, function(a){
827 return a.cloneNode( deep != undefined ? deep : true );
832 * Removes all elements from the set of matched elements that do not
833 * match the specified expression(s). This method is used to narrow down
834 * the results of a search.
836 * Provide a comma-separated list of expressions to apply multiple filters at once.
838 * @example $("p").filter(".selected")
839 * @before <p class="selected">Hello</p><p>How are you?</p>
840 * @result [ <p class="selected">Hello</p> ]
841 * @desc Selects all paragraphs and removes those without a class "selected".
843 * @example $("p").filter(".selected, :first")
844 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
845 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
846 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
850 * @param String expression Expression(s) to search with.
851 * @cat DOM/Traversing
855 * Removes all elements from the set of matched elements that do not
856 * pass the specified filter. This method is used to narrow down
857 * the results of a search.
859 * @example $("p").filter(function(index) {
860 * return $("ol", this).length == 0;
862 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
863 * @result [ <p>How are you?</p> ]
864 * @desc Remove all elements that have a child ol element
868 * @param Function filter A function to use for filtering
869 * @cat DOM/Traversing
871 filter: function(t) {
872 return this.pushStack(
873 jQuery.isFunction( t ) &&
874 jQuery.grep(this, function(el, index){
875 return t.apply(el, [index])
878 jQuery.multiFilter(t,this) );
882 * Removes the specified Element from the set of matched elements. This
883 * method is used to remove a single Element from a jQuery object.
885 * @example $("p").not( $("#selected")[0] )
886 * @before <p>Hello</p><p id="selected">Hello Again</p>
887 * @result [ <p>Hello</p> ]
888 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
892 * @param Element el An element to remove from the set
893 * @cat DOM/Traversing
897 * Removes elements matching the specified expression from the set
898 * of matched elements. This method is used to remove one or more
899 * elements from a jQuery object.
901 * @example $("p").not("#selected")
902 * @before <p>Hello</p><p id="selected">Hello Again</p>
903 * @result [ <p>Hello</p> ]
904 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
908 * @param String expr An expression with which to remove matching elements
909 * @cat DOM/Traversing
913 * Removes any elements inside the array of elements from the set
914 * of matched elements. This method is used to remove one or more
915 * elements from a jQuery object.
917 * @example $("p").not( $("div p.selected") )
918 * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
919 * @result [ <p>Hello</p> ]
920 * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
924 * @param jQuery elems A set of elements to remove from the jQuery set of matched elements.
925 * @cat DOM/Traversing
928 return this.pushStack(
929 t.constructor == String &&
930 jQuery.multiFilter(t, this, true) ||
932 jQuery.grep(this, function(a) {
933 return ( t.constructor == Array || t.jquery )
934 ? jQuery.inArray( a, t ) < 0
941 * Adds more elements, matched by the given expression,
942 * to the set of matched elements.
944 * @example $("p").add("span")
945 * @before <p>Hello</p><span>Hello Again</span>
946 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
950 * @param String expr An expression whose matched elements are added
951 * @cat DOM/Traversing
955 * Adds more elements, created on the fly, to the set of
958 * @example $("p").add("<span>Again</span>")
959 * @before <p>Hello</p>
960 * @result [ <p>Hello</p>, <span>Again</span> ]
964 * @param String html A string of HTML to create on the fly.
965 * @cat DOM/Traversing
969 * Adds one or more Elements to the set of matched elements.
971 * @example $("p").add( document.getElementById("a") )
972 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
973 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
975 * @example $("p").add( document.forms[0].elements )
976 * @before <p>Hello</p><p><form><input/><button/></form>
977 * @result [ <p>Hello</p>, <input/>, <button/> ]
981 * @param Element|Array<Element> elements One or more Elements to add
982 * @cat DOM/Traversing
985 return this.pushStack( jQuery.merge(
987 t.constructor == String ?
989 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
995 * Checks the current selection against an expression and returns true,
996 * if at least one element of the selection fits the given expression.
998 * Does return false, if no element fits or the expression is not valid.
1000 * filter(String) is used internally, therefore all rules that apply there
1003 * @example $("input[@type='checkbox']").parent().is("form")
1004 * @before <form><input type="checkbox" /></form>
1006 * @desc Returns true, because the parent of the input is a form element
1008 * @example $("input[@type='checkbox']").parent().is("form")
1009 * @before <form><p><input type="checkbox" /></p></form>
1011 * @desc Returns false, because the parent of the input is a p element
1015 * @param String expr The expression with which to filter
1016 * @cat DOM/Traversing
1018 is: function(expr) {
1019 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1023 * Get the current value of the first matched element.
1025 * @example $("input").val();
1026 * @before <input type="text" value="some text"/>
1027 * @result "some text"
1031 * @cat DOM/Attributes
1035 * Set the value of every matched element.
1037 * @example $("input").val("test");
1038 * @before <input type="text" value="some text"/>
1039 * @result <input type="text" value="test"/>
1043 * @param String val Set the property to the specified value.
1044 * @cat DOM/Attributes
1046 val: function( val ) {
1047 return val == undefined ?
1048 ( this.length ? this[0].value : null ) :
1049 this.attr( "value", val );
1053 * Get the html contents of the first matched element.
1054 * This property is not available on XML documents.
1056 * @example $("div").html();
1057 * @before <div><input/></div>
1062 * @cat DOM/Attributes
1066 * Set the html contents of every matched element.
1067 * This property is not available on XML documents.
1069 * @example $("div").html("<b>new stuff</b>");
1070 * @before <div><input/></div>
1071 * @result <div><b>new stuff</b></div>
1075 * @param String val Set the html contents to the specified value.
1076 * @cat DOM/Attributes
1078 html: function( val ) {
1079 return val == undefined ?
1080 ( this.length ? this[0].innerHTML : null ) :
1081 this.empty().append( val );
1088 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1089 * @param Number dir If dir<0, process args in reverse order.
1090 * @param Function fn The function doing the DOM manipulation.
1094 domManip: function(args, table, dir, fn){
1095 var clone = this.length > 1;
1096 var a = jQuery.clean(args);
1100 return this.each(function(){
1103 if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
1104 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1106 jQuery.each( a, function(){
1107 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
1115 * Extends the jQuery object itself. Can be used to add functions into
1116 * the jQuery namespace and to add plugin methods (plugins).
1118 * @example jQuery.fn.extend({
1119 * check: function() {
1120 * return this.each(function() { this.checked = true; });
1122 * uncheck: function() {
1123 * return this.each(function() { this.checked = false; });
1126 * $("input[@type=checkbox]").check();
1127 * $("input[@type=radio]").uncheck();
1128 * @desc Adds two plugin methods.
1130 * @example jQuery.extend({
1131 * min: function(a, b) { return a < b ? a : b; },
1132 * max: function(a, b) { return a > b ? a : b; }
1134 * @desc Adds two functions into the jQuery namespace
1137 * @param Object prop The object that will be merged into the jQuery object
1143 * Extend one object with one or more others, returning the original,
1144 * modified, object. This is a great utility for simple inheritance.
1146 * @example var settings = { validate: false, limit: 5, name: "foo" };
1147 * var options = { validate: true, name: "bar" };
1148 * jQuery.extend(settings, options);
1149 * @result settings == { validate: true, limit: 5, name: "bar" }
1150 * @desc Merge settings and options, modifying settings
1152 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1153 * var options = { validate: true, name: "bar" };
1154 * var settings = jQuery.extend({}, defaults, options);
1155 * @result settings == { validate: true, limit: 5, name: "bar" }
1156 * @desc Merge defaults and options, without modifying the defaults
1159 * @param Object target The object to extend
1160 * @param Object prop1 The object that will be merged into the first.
1161 * @param Object propN (optional) More objects to merge into the first
1165 jQuery.extend = jQuery.fn.extend = function() {
1166 // copy reference to target object
1167 var target = arguments[0],
1170 // extend jQuery itself if only one argument is passed
1171 if ( arguments.length == 1 ) {
1176 while (prop = arguments[a++])
1177 // Extend the base object
1178 for ( var i in prop ) target[i] = prop[i];
1180 // Return the modified object
1186 * Run this function to give control of the $ variable back
1187 * to whichever library first implemented it. This helps to make
1188 * sure that jQuery doesn't conflict with the $ object
1189 * of other libraries.
1191 * By using this function, you will only be able to access jQuery
1192 * using the 'jQuery' variable. For example, where you used to do
1193 * $("div p"), you now must do jQuery("div p").
1195 * @example jQuery.noConflict();
1196 * // Do something with jQuery
1197 * jQuery("div p").hide();
1198 * // Do something with another library's $()
1199 * $("content").style.display = 'none';
1200 * @desc Maps the original object that was referenced by $ back to $
1202 * @example jQuery.noConflict();
1205 * // more code using $ as alias to jQuery
1208 * // other code using $ as an alias to the other library
1209 * @desc Reverts the $ alias and then creates and executes a
1210 * function to provide the $ as a jQuery alias inside the functions
1211 * scope. Inside the function the original $ object is not available.
1212 * This works well for most plugins that don't rely on any other library.
1215 * @name $.noConflict
1219 noConflict: function() {
1225 // This may seem like some crazy code, but trust me when I say that this
1226 // is the only cross-browser way to do this. --John
1227 isFunction: function( fn ) {
1228 return !!fn && typeof fn != "string" &&
1229 typeof fn[0] == "undefined" && /function/i.test( fn + "" );
1232 // check if an element is in a XML document
1233 isXMLDoc: function(elem) {
1234 return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
1237 nodeName: function( elem, name ) {
1238 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
1242 * A generic iterator function, which can be used to seemlessly
1243 * iterate over both objects and arrays. This function is not the same
1244 * as $().each() - which is used to iterate, exclusively, over a jQuery
1245 * object. This function can be used to iterate over anything.
1247 * The callback has two arguments:the key (objects) or index (arrays) as first
1248 * the first, and the value as the second.
1250 * @example $.each( [0,1,2], function(i, n){
1251 * alert( "Item #" + i + ": " + n );
1253 * @desc This is an example of iterating over the items in an array,
1254 * accessing both the current item and its index.
1256 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1257 * alert( "Name: " + i + ", Value: " + n );
1260 * @desc This is an example of iterating over the properties in an
1261 * Object, accessing both the current item and its key.
1264 * @param Object obj The object, or array, to iterate over.
1265 * @param Function fn The function that will be executed on every object.
1269 // args is for internal usage only
1270 each: function( obj, fn, args ) {
1271 if ( obj.length == undefined )
1272 for ( var i in obj )
1273 fn.apply( obj[i], args || [i, obj[i]] );
1275 for ( var i = 0, ol = obj.length; i < ol; i++ )
1276 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1280 prop: function(elem, value, type, index, prop){
1281 // Handle executable functions
1282 if ( jQuery.isFunction( value ) )
1283 value = value.call( elem, [index] );
1285 // exclude the following css properties to add px
1286 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
1288 // Handle passing in a number to a CSS property
1289 return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
1295 // internal only, use addClass("class")
1296 add: function( elem, c ){
1297 jQuery.each( c.split(/\s+/), function(i, cur){
1298 if ( !jQuery.className.has( elem.className, cur ) )
1299 elem.className += ( elem.className ? " " : "" ) + cur;
1303 // internal only, use removeClass("class")
1304 remove: function( elem, c ){
1305 elem.className = c ?
1306 jQuery.grep( elem.className.split(/\s+/), function(cur){
1307 return !jQuery.className.has( c, cur );
1311 // internal only, use is(".class")
1312 has: function( t, c ) {
1313 t = t.className || t;
1314 return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
1319 * Swap in/out style options.
1322 swap: function(e,o,f) {
1323 for ( var i in o ) {
1324 e.style["old"+i] = e.style[i];
1329 e.style[i] = e.style["old"+i];
1332 css: function(e,p) {
1333 if ( p == "height" || p == "width" ) {
1334 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1336 jQuery.each( d, function(){
1337 old["padding" + this] = 0;
1338 old["border" + this + "Width"] = 0;
1341 jQuery.swap( e, old, function() {
1342 if (jQuery.css(e,"display") != "none") {
1343 oHeight = e.offsetHeight;
1344 oWidth = e.offsetWidth;
1346 e = jQuery(e.cloneNode(true))
1347 .find(":radio").removeAttr("checked").end()
1349 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1350 }).appendTo(e.parentNode)[0];
1352 var parPos = jQuery.css(e.parentNode,"position");
1353 if ( parPos == "" || parPos == "static" )
1354 e.parentNode.style.position = "relative";
1356 oHeight = e.clientHeight;
1357 oWidth = e.clientWidth;
1359 if ( parPos == "" || parPos == "static" )
1360 e.parentNode.style.position = "static";
1362 e.parentNode.removeChild(e);
1366 return p == "height" ? oHeight : oWidth;
1369 return jQuery.curCSS( e, p );
1372 curCSS: function(elem, prop, force) {
1375 if (prop == "opacity" && jQuery.browser.msie)
1376 return jQuery.attr(elem.style, "opacity");
1378 if (prop == "float" || prop == "cssFloat")
1379 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1381 if (!force && elem.style[prop])
1382 ret = elem.style[prop];
1384 else if (document.defaultView && document.defaultView.getComputedStyle) {
1386 if (prop == "cssFloat" || prop == "styleFloat")
1389 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1390 var cur = document.defaultView.getComputedStyle(elem, null);
1393 ret = cur.getPropertyValue(prop);
1394 else if ( prop == "display" )
1397 jQuery.swap(elem, { display: "block" }, function() {
1398 var c = document.defaultView.getComputedStyle(this, "");
1399 ret = c && c.getPropertyValue(prop) || "";
1402 } else if (elem.currentStyle) {
1404 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1405 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1412 clean: function(a) {
1415 jQuery.each( a, function(i,arg){
1418 if ( arg.constructor == Number )
1419 arg = arg.toString();
1421 // Convert html string into DOM nodes
1422 if ( typeof arg == "string" ) {
1423 // Trim whitespace, otherwise indexOf won't work as expected
1424 var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
1427 // option or optgroup
1428 !s.indexOf("<opt") &&
1429 [1, "<select>", "</select>"] ||
1431 (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
1432 [1, "<table>", "</table>"] ||
1434 !s.indexOf("<tr") &&
1435 [2, "<table><tbody>", "</tbody></table>"] ||
1437 // <thead> matched above
1438 (!s.indexOf("<td") || !s.indexOf("<th")) &&
1439 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1443 // Go to html and back, then peel off extra wrappers
1444 div.innerHTML = wrap[1] + s + wrap[2];
1446 // Move to the right depth
1448 div = div.firstChild;
1450 // Remove IE's autoinserted <tbody> from table fragments
1451 if ( jQuery.browser.msie ) {
1453 // String was a <table>, *may* have spurious <tbody>
1454 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
1455 tb = div.firstChild && div.firstChild.childNodes;
1457 // String was a bare <thead> or <tfoot>
1458 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1459 tb = div.childNodes;
1461 for ( var n = tb.length-1; n >= 0 ; --n )
1462 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
1463 tb[n].parentNode.removeChild(tb[n]);
1467 arg = div.childNodes;
1470 if ( arg.length === 0 )
1473 if ( arg[0] == undefined || (jQuery.browser.msie && jQuery.nodeName(arg,"form")) )
1476 r = jQuery.merge( r, arg );
1483 attr: function(elem, name, value){
1484 var fix = jQuery.isXMLDoc(elem) ? {} : {
1486 "class": "className",
1487 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1488 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1489 innerHTML: "innerHTML",
1490 className: "className",
1492 disabled: "disabled",
1494 readonly: "readOnly",
1495 selected: "selected"
1498 // IE actually uses filters for opacity ... elem is actually elem.style
1499 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1500 // IE has trouble with opacity if it does not have layout
1501 // Force it by setting the zoom level
1504 // Set the alpha filter to set the opacity
1505 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1506 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1508 } else if ( name == "opacity" && jQuery.browser.msie )
1509 return elem.filter ?
1510 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1512 // Mozilla doesn't play well with opacity 1
1513 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1517 // Certain attributes only work when accessed via the old DOM 0 way
1519 if ( value != undefined ) elem[fix[name]] = value;
1520 return elem[fix[name]];
1522 } else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
1523 return elem.getAttributeNode(name).nodeValue;
1525 // IE elem.getAttribute passes even for style
1526 else if ( elem.tagName ) {
1527 if ( value != undefined ) elem.setAttribute( name, value );
1528 if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) )
1529 return elem.getAttribute( name, 2 );
1530 return elem.getAttribute( name );
1532 // elem is actually elem.style ... set the style
1534 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1535 if ( value != undefined ) elem[name] = value;
1541 * Remove the whitespace from the beginning and end of a string.
1543 * @example $.trim(" hello, how are you? ");
1544 * @result "hello, how are you?"
1548 * @param String str The string to trim.
1552 return t.replace(/^\s+|\s+$/g, "");
1555 makeArray: function( a ) {
1558 if ( a.constructor != Array )
1559 for ( var i = 0, al = a.length; i < al; i++ )
1567 inArray: function( b, a ) {
1568 for ( var i = 0, al = a.length; i < al; i++ )
1575 * Merge two arrays together, removing all duplicates.
1577 * The result is the altered first argument with
1578 * the unique elements from the second array added.
1580 * @example $.merge( [0,1,2], [2,3,4] )
1581 * @result [0,1,2,3,4]
1582 * @desc Merges two arrays, removing the duplicate 2
1584 * @example var array = [3,2,1];
1585 * $.merge( array, [4,3,2] )
1586 * @result array == [3,2,1,4]
1587 * @desc Merges two arrays, removing the duplicates 3 and 2
1591 * @param Array first The first array to merge, the unique elements of second added.
1592 * @param Array second The second array to merge into the first, unaltered.
1595 merge: function(first, second) {
1596 var r = [].slice.call( first, 0 );
1598 // Now check for duplicates between the two arrays
1599 // and only add the unique items
1600 for ( var i = 0, sl = second.length; i < sl; i++ )
1601 // Check for duplicates
1602 if ( jQuery.inArray( second[i], r ) == -1 )
1603 // The item is unique, add it
1604 first.push( second[i] );
1610 * Filter items out of an array, by using a filter function.
1612 * The specified function will be passed two arguments: The
1613 * current array item and the index of the item in the array. The
1614 * function must return 'true' to keep the item in the array,
1615 * false to remove it.
1617 * @example $.grep( [0,1,2], function(i){
1624 * @param Array array The Array to find items in.
1625 * @param Function fn The function to process each item against.
1626 * @param Boolean inv Invert the selection - select the opposite of the function.
1629 grep: function(elems, fn, inv) {
1630 // If a string is passed in for the function, make a function
1631 // for it (a handy shortcut)
1632 if ( typeof fn == "string" )
1633 fn = new Function("a","i","return " + fn);
1637 // Go through the array, only saving the items
1638 // that pass the validator function
1639 for ( var i = 0, el = elems.length; i < el; i++ )
1640 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1641 result.push( elems[i] );
1647 * Translate all items in an array to another array of items.
1649 * The translation function that is provided to this method is
1650 * called for each item in the array and is passed one argument:
1651 * The item to be translated.
1653 * The function can then return the translated value, 'null'
1654 * (to remove the item), or an array of values - which will
1655 * be flattened into the full array.
1657 * @example $.map( [0,1,2], function(i){
1661 * @desc Maps the original array to a new one and adds 4 to each value.
1663 * @example $.map( [0,1,2], function(i){
1664 * return i > 0 ? i + 1 : null;
1667 * @desc Maps the original array to a new one and adds 1 to each
1668 * value if it is bigger then zero, otherwise it's removed-
1670 * @example $.map( [0,1,2], function(i){
1671 * return [ i, i + 1 ];
1673 * @result [0, 1, 1, 2, 2, 3]
1674 * @desc Maps the original array to a new one, each element is added
1675 * with it's original value and the value plus one.
1679 * @param Array array The Array to translate.
1680 * @param Function fn The function to process each item against.
1683 map: function(elems, fn) {
1684 // If a string is passed in for the function, make a function
1685 // for it (a handy shortcut)
1686 if ( typeof fn == "string" )
1687 fn = new Function("a","return " + fn);
1689 var result = [], r = [];
1691 // Go through the array, translating each of the items to their
1692 // new value (or values).
1693 for ( var i = 0, el = elems.length; i < el; i++ ) {
1694 var val = fn(elems[i],i);
1696 if ( val !== null && val != undefined ) {
1697 if ( val.constructor != Array ) val = [val];
1698 result = result.concat( val );
1702 var r = result.length ? [ result[0] ] : [];
1704 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1705 for ( var j = 0; j < i; j++ )
1706 if ( result[i] == r[j] )
1709 r.push( result[i] );
1717 * Contains flags for the useragent, read from navigator.userAgent.
1718 * Available flags are: safari, opera, msie, mozilla
1720 * This property is available before the DOM is ready, therefore you can
1721 * use it to add ready events only for certain browsers.
1723 * There are situations where object detections is not reliable enough, in that
1724 * cases it makes sense to use browser detection. Simply try to avoid both!
1726 * A combination of browser and object detection yields quite reliable results.
1728 * @example $.browser.msie
1729 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1731 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1732 * @desc Alerts "this is safari!" only for safari browsers
1741 * Whether the W3C compliant box model is being used.
1749 var b = navigator.userAgent.toLowerCase();
1751 // Figure out what browser is being used
1753 safari: /webkit/.test(b),
1754 opera: /opera/.test(b),
1755 msie: /msie/.test(b) && !/opera/.test(b),
1756 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1759 // Check to see if the W3C box model is being used
1760 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1764 * Get a set of elements containing the unique parents of the matched
1767 * Can be filtered with an optional expressions.
1769 * @example $("p").parent()
1770 * @before <div><p>Hello</p><p>Hello</p></div>
1771 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1772 * @desc Find the parent element of each paragraph.
1774 * @example $("p").parent(".selected")
1775 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1776 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1777 * @desc Find the parent element of each paragraph with a class "selected".
1781 * @param String expr (optional) An expression to filter the parents with
1782 * @cat DOM/Traversing
1786 * Get a set of elements containing the unique ancestors of the matched
1787 * set of elements (except for the root element).
1789 * Can be filtered with an optional expressions.
1791 * @example $("span").parents()
1792 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1793 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1794 * @desc Find all parent elements of each span.
1796 * @example $("span").parents("p")
1797 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1798 * @result [ <p><span>Hello</span></p> ]
1799 * @desc Find all parent elements of each span that is a paragraph.
1803 * @param String expr (optional) An expression to filter the ancestors with
1804 * @cat DOM/Traversing
1808 * Get a set of elements containing the unique next siblings of each of the
1809 * matched set of elements.
1811 * It only returns the very next sibling, not all next siblings.
1813 * Can be filtered with an optional expressions.
1815 * @example $("p").next()
1816 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1817 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1818 * @desc Find the very next sibling of each paragraph.
1820 * @example $("p").next(".selected")
1821 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1822 * @result [ <p class="selected">Hello Again</p> ]
1823 * @desc Find the very next sibling of each paragraph that has a class "selected".
1827 * @param String expr (optional) An expression to filter the next Elements with
1828 * @cat DOM/Traversing
1832 * Get a set of elements containing the unique previous siblings of each of the
1833 * matched set of elements.
1835 * Can be filtered with an optional expressions.
1837 * It only returns the immediately previous sibling, not all previous siblings.
1839 * @example $("p").prev()
1840 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1841 * @result [ <div><span>Hello Again</span></div> ]
1842 * @desc Find the very previous sibling of each paragraph.
1844 * @example $("p").prev(".selected")
1845 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1846 * @result [ <div><span>Hello</span></div> ]
1847 * @desc Find the very previous sibling of each paragraph that has a class "selected".
1851 * @param String expr (optional) An expression to filter the previous Elements with
1852 * @cat DOM/Traversing
1856 * Get a set of elements containing all of the unique siblings of each of the
1857 * matched set of elements.
1859 * Can be filtered with an optional expressions.
1861 * @example $("div").siblings()
1862 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1863 * @result [ <p>Hello</p>, <p>And Again</p> ]
1864 * @desc Find all siblings of each div.
1866 * @example $("div").siblings(".selected")
1867 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1868 * @result [ <p class="selected">Hello Again</p> ]
1869 * @desc Find all siblings with a class "selected" of each div.
1873 * @param String expr (optional) An expression to filter the sibling Elements with
1874 * @cat DOM/Traversing
1878 * Get a set of elements containing all of the unique children of each of the
1879 * matched set of elements.
1881 * Can be filtered with an optional expressions.
1883 * @example $("div").children()
1884 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1885 * @result [ <span>Hello Again</span> ]
1886 * @desc Find all children of each div.
1888 * @example $("div").children(".selected")
1889 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1890 * @result [ <p class="selected">Hello Again</p> ]
1891 * @desc Find all children with a class "selected" of each div.
1895 * @param String expr (optional) An expression to filter the child Elements with
1896 * @cat DOM/Traversing
1899 parent: "a.parentNode",
1900 parents: "jQuery.parents(a)",
1901 next: "jQuery.nth(a,2,'nextSibling')",
1902 prev: "jQuery.nth(a,2,'previousSibling')",
1903 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1904 children: "jQuery.sibling(a.firstChild)"
1906 jQuery.fn[ i ] = function(a) {
1907 var ret = jQuery.map(this,n);
1908 if ( a && typeof a == "string" )
1909 ret = jQuery.multiFilter(a,ret);
1910 return this.pushStack( ret );
1915 * Append all of the matched elements to another, specified, set of elements.
1916 * This operation is, essentially, the reverse of doing a regular
1917 * $(A).append(B), in that instead of appending B to A, you're appending
1920 * @example $("p").appendTo("#foo");
1921 * @before <p>I would like to say: </p><div id="foo"></div>
1922 * @result <div id="foo"><p>I would like to say: </p></div>
1923 * @desc Appends all paragraphs to the element with the ID "foo"
1927 * @param <Content> content Content to append to the selected element to.
1928 * @cat DOM/Manipulation
1929 * @see append(<Content>)
1933 * Prepend all of the matched elements to another, specified, set of elements.
1934 * This operation is, essentially, the reverse of doing a regular
1935 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1938 * @example $("p").prependTo("#foo");
1939 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1940 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1941 * @desc Prepends all paragraphs to the element with the ID "foo"
1945 * @param <Content> content Content to prepend to the selected element to.
1946 * @cat DOM/Manipulation
1947 * @see prepend(<Content>)
1951 * Insert all of the matched elements before another, specified, set of elements.
1952 * This operation is, essentially, the reverse of doing a regular
1953 * $(A).before(B), in that instead of inserting B before A, you're inserting
1956 * @example $("p").insertBefore("#foo");
1957 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1958 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1959 * @desc Same as $("#foo").before("p")
1961 * @name insertBefore
1963 * @param <Content> content Content to insert the selected element before.
1964 * @cat DOM/Manipulation
1965 * @see before(<Content>)
1969 * Insert all of the matched elements after another, specified, set of elements.
1970 * This operation is, essentially, the reverse of doing a regular
1971 * $(A).after(B), in that instead of inserting B after A, you're inserting
1974 * @example $("p").insertAfter("#foo");
1975 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1976 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1977 * @desc Same as $("#foo").after("p")
1981 * @param <Content> content Content to insert the selected element after.
1982 * @cat DOM/Manipulation
1983 * @see after(<Content>)
1988 prependTo: "prepend",
1989 insertBefore: "before",
1990 insertAfter: "after"
1992 jQuery.fn[ i ] = function(){
1994 return this.each(function(){
1995 for ( var j = 0, al = a.length; j < al; j++ )
1996 jQuery(a[j])[n]( this );
2002 * Remove an attribute from each of the matched elements.
2004 * @example $("input").removeAttr("disabled")
2005 * @before <input disabled="disabled"/>
2010 * @param String name The name of the attribute to remove.
2011 * @cat DOM/Attributes
2015 * Adds the specified class(es) to each of the set of matched elements.
2017 * @example $("p").addClass("selected")
2018 * @before <p>Hello</p>
2019 * @result [ <p class="selected">Hello</p> ]
2021 * @example $("p").addClass("selected highlight")
2022 * @before <p>Hello</p>
2023 * @result [ <p class="selected highlight">Hello</p> ]
2027 * @param String class One or more CSS classes to add to the elements
2028 * @cat DOM/Attributes
2029 * @see removeClass(String)
2033 * Removes all or the specified class(es) from the set of matched elements.
2035 * @example $("p").removeClass()
2036 * @before <p class="selected">Hello</p>
2037 * @result [ <p>Hello</p> ]
2039 * @example $("p").removeClass("selected")
2040 * @before <p class="selected first">Hello</p>
2041 * @result [ <p class="first">Hello</p> ]
2043 * @example $("p").removeClass("selected highlight")
2044 * @before <p class="highlight selected first">Hello</p>
2045 * @result [ <p class="first">Hello</p> ]
2049 * @param String class (optional) One or more CSS classes to remove from the elements
2050 * @cat DOM/Attributes
2051 * @see addClass(String)
2055 * Adds the specified class if it is not present, removes it if it is
2058 * @example $("p").toggleClass("selected")
2059 * @before <p>Hello</p><p class="selected">Hello Again</p>
2060 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2064 * @param String class A CSS class with which to toggle the elements
2065 * @cat DOM/Attributes
2069 * Removes all matched elements from the DOM. This does NOT remove them from the
2070 * jQuery object, allowing you to use the matched elements further.
2072 * Can be filtered with an optional expressions.
2074 * @example $("p").remove();
2075 * @before <p>Hello</p> how are <p>you?</p>
2078 * @example $("p").remove(".hello");
2079 * @before <p class="hello">Hello</p> how are <p>you?</p>
2080 * @result how are <p>you?</p>
2084 * @param String expr (optional) A jQuery expression to filter elements by.
2085 * @cat DOM/Manipulation
2089 * Removes all child nodes from the set of matched elements.
2091 * @example $("p").empty()
2092 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2093 * @result [ <p></p> ]
2097 * @cat DOM/Manipulation
2101 removeAttr: function( key ) {
2102 jQuery.attr( this, key, "" );
2103 this.removeAttribute( key );
2105 addClass: function(c){
2106 jQuery.className.add(this,c);
2108 removeClass: function(c){
2109 jQuery.className.remove(this,c);
2111 toggleClass: function( c ){
2112 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2114 remove: function(a){
2115 if ( !a || jQuery.filter( a, [this] ).r.length )
2116 this.parentNode.removeChild( this );
2119 while ( this.firstChild )
2120 this.removeChild( this.firstChild );
2123 jQuery.fn[ i ] = function() {
2124 return this.each( n, arguments );
2129 * Reduce the set of matched elements to a single element.
2130 * The position of the element in the set of matched elements
2131 * starts at 0 and goes to length - 1.
2133 * @example $("p").eq(1)
2134 * @before <p>This is just a test.</p><p>So is this</p>
2135 * @result [ <p>So is this</p> ]
2139 * @param Number pos The index of the element that you wish to limit to.
2144 * Reduce the set of matched elements to all elements before a given position.
2145 * The position of the element in the set of matched elements
2146 * starts at 0 and goes to length - 1.
2148 * @example $("p").lt(1)
2149 * @before <p>This is just a test.</p><p>So is this</p>
2150 * @result [ <p>This is just a test.</p> ]
2154 * @param Number pos Reduce the set to all elements below this position.
2159 * Reduce the set of matched elements to all elements after a given position.
2160 * The position of the element in the set of matched elements
2161 * starts at 0 and goes to length - 1.
2163 * @example $("p").gt(0)
2164 * @before <p>This is just a test.</p><p>So is this</p>
2165 * @result [ <p>So is this</p> ]
2169 * @param Number pos Reduce the set to all elements after this position.
2174 * Filter the set of elements to those that contain the specified text.
2176 * @example $("p").contains("test")
2177 * @before <p>This is just a test.</p><p>So is this</p>
2178 * @result [ <p>This is just a test.</p> ]
2182 * @param String str The string that will be contained within the text of an element.
2183 * @cat DOM/Traversing
2185 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2186 jQuery.fn[ n ] = function(num,fn) {
2187 return this.filter( ":" + n + "(" + num + ")", fn );
2192 * Get the current computed, pixel, width of the first matched element.
2194 * @example $("p").width();
2195 * @before <p>This is just a test.</p>
2204 * Set the CSS width of every matched element. If no explicit unit
2205 * was specified (like 'em' or '%') then "px" is added to the width.
2207 * @example $("p").width(20);
2208 * @before <p>This is just a test.</p>
2209 * @result <p style="width:20px;">This is just a test.</p>
2211 * @example $("p").width("20em");
2212 * @before <p>This is just a test.</p>
2213 * @result <p style="width:20em;">This is just a test.</p>
2217 * @param String|Number val Set the CSS property to the specified value.
2222 * Get the current computed, pixel, height of the first matched element.
2224 * @example $("p").height();
2225 * @before <p>This is just a test.</p>
2234 * Set the CSS width of every matched element. If no explicit unit
2235 * was specified (like 'em' or '%') then "px" is added to the width.
2237 * @example $("p").height(20);
2238 * @before <p>This is just a test.</p>
2239 * @result <p style="height:20px;">This is just a test.</p>
2241 * @example $("p").height("20em");
2242 * @before <p>This is just a test.</p>
2243 * @result <p style="height:20em;">This is just a test.</p>
2247 * @param String|Number val Set the CSS property to the specified value.
2251 jQuery.each( [ "height", "width" ], function(i,n){
2252 jQuery.fn[ n ] = function(h) {
2253 return h == undefined ?
2254 ( this.length ? jQuery.css( this[0], n ) : null ) :
2255 this.css( n, h.constructor == String ? h : h + "px" );