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 // Make sure that a selection was provided
29 // Shortcut for document ready
30 // Safari reports typeof on DOM NodeLists as a function
31 if ( typeof a == "function" && !a.nodeType && a[0] == undefined )
32 return jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
34 // Watch for when a jQuery object is passed as the selector
36 return jQuery( jQuery.makeArray( a ) );
38 // Watch for when a jQuery object is passed at the context
40 return jQuery( c ).find(a);
42 // If the context is global, return a new object
44 return new jQuery(a,c);
46 // Handle HTML strings
47 if ( typeof a == "string" ) {
48 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
49 if ( m ) a = jQuery.clean( [ m[1] ] );
52 // Watch for when an array is passed in
53 return this.setArray( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?
54 // Assume that it is an array of DOM Elements
55 jQuery.makeArray( a ) :
57 // Find the matching elements and save them for later
58 jQuery.find( a, c ) );
61 // Map over the $ in case of overwrite
62 if ( typeof $ != "undefined" )
65 // Map the jQuery namespace to the '$' one
69 * This function accepts a string containing a CSS or
70 * basic XPath selector which is then used to match a set of elements.
72 * The core functionality of jQuery centers around this function.
73 * Everything in jQuery is based upon this, or uses this in some way.
74 * The most basic use of this function is to pass in an expression
75 * (usually consisting of CSS or XPath), which then finds all matching
78 * By default, $() looks for DOM elements within the context of the
79 * current HTML document.
81 * @example $("div > p")
82 * @desc Finds all p elements that are children of a div element.
83 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
84 * @result [ <p>two</p> ]
86 * @example $("input:radio", document.forms[0])
87 * @desc Searches for all inputs of type radio within the first form in the document
89 * @example $("div", xml.responseXML)
90 * @desc This finds all div elements within the specified XML document.
93 * @param String expr An expression to search with
94 * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
98 * @see $(Element<Array>)
102 * Create DOM elements on-the-fly from the provided String of raw HTML.
104 * @example $("<div><p>Hello</p></div>").appendTo("#body")
105 * @desc Creates a div element (and all of its contents) dynamically,
106 * and appends it to the element with the ID of body. Internally, an
107 * element is created and it's innerHTML property set to the given markup.
108 * It is therefore both quite flexible and limited.
111 * @param String html A string of HTML to create on the fly.
114 * @see appendTo(String)
118 * Wrap jQuery functionality around a single or multiple DOM Element(s).
120 * This function also accepts XML Documents and Window objects
121 * as valid arguments (even though they are not DOM Elements).
123 * @example $(document).find("div > p")
124 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
125 * @result [ <p>two</p> ]
126 * @desc Same as $("div > p") because the document
128 * @example $(document.body).background( "black" );
129 * @desc Sets the background color of the page to black.
131 * @example $( myForm.elements ).hide()
132 * @desc Hides all the input elements within a form
135 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
141 * A shorthand for $(document).ready(), allowing you to bind a function
142 * to be executed when the DOM document has finished loading. This function
143 * behaves just like $(document).ready(), in that it should be used to wrap
144 * all of the other $() operations on your page. While this function is,
145 * technically, chainable - there really isn't much use for chaining against it.
146 * You can have as many $(document).ready events on your page as you like.
148 * See ready(Function) for details about the ready event.
150 * @example $(function(){
151 * // Document is ready
153 * @desc Executes the function when the DOM is ready to be used.
156 * @param Function fn The function to execute when the DOM is ready.
162 * A means of creating a cloned copy of a jQuery object. This function
163 * copies the set of matched elements from one jQuery object and creates
164 * another, new, jQuery object containing the same elements.
166 * @example var div = $("div");
167 * $( div ).find("p");
168 * @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).
171 * @param jQuery obj The jQuery object to be cloned.
176 jQuery.fn = jQuery.prototype = {
178 * The current version of jQuery.
189 * The number of elements currently matched.
191 * @example $("img").length;
192 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
202 * The number of elements currently matched.
204 * @example $("img").size();
205 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
219 * Access all matched elements. This serves as a backwards-compatible
220 * way of accessing all matched elements (other than the jQuery object
221 * itself, which is, in fact, an array of elements).
223 * @example $("img").get();
224 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
225 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
226 * @desc Selects all images in the document and returns the DOM Elements as an Array
229 * @type Array<Element>
234 * Access a single matched element. num is used to access the
235 * Nth element matched.
237 * @example $("img").get(0);
238 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
239 * @result [ <img src="test1.jpg"/> ]
240 * @desc Selects all images in the document and returns the first one
244 * @param Number num Access the element in the Nth position.
247 get: function( num ) {
248 return num == undefined ?
250 // Return a 'clean' array
251 jQuery.makeArray( this ) :
253 // Return just the object
258 * Set the jQuery object to an array of elements, while maintaining
261 * @example $("img").set([ document.body ]);
262 * @result $("img").set() == [ document.body ]
267 * @param Elements elems An array of elements
271 var ret = jQuery(this);
272 ret.prevObject = this;
273 return ret.setArray( a );
277 * Set the jQuery object to an array of elements. This operation is
278 * completely destructive - be sure to use .set() if you wish to maintain
281 * @example $("img").setArray([ document.body ]);
282 * @result $("img").setArray() == [ document.body ]
287 * @param Elements elems An array of elements
290 setArray: function( a ) {
292 [].push.apply( this, a );
297 * Execute a function within the context of every matched element.
298 * This means that every time the passed-in function is executed
299 * (which is once for every element matched) the 'this' keyword
300 * points to the specific element.
302 * Additionally, the function, when executed, is passed a single
303 * argument representing the position of the element in the matched
306 * @example $("img").each(function(i){
307 * this.src = "test" + i + ".jpg";
309 * @before <img/><img/>
310 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
311 * @desc Iterates over two images and sets their src property
315 * @param Function fn A function to execute
318 each: function( fn, args ) {
319 return jQuery.each( this, fn, args );
323 * Searches every matched element for the object and returns
324 * the index of the element, if found, starting with zero.
325 * Returns -1 if the object wasn't found.
327 * @example $("*").index( $('#foobar')[0] )
328 * @before <div id="foobar"></div><b></b><span id="foo"></span>
330 * @desc Returns the index for the element with ID foobar
332 * @example $("*").index( $('#foo'))
333 * @before <div id="foobar"></div><b></b><span id="foo"></span>
335 * @desc Returns the index for the element with ID foo
337 * @example $("*").index( $('#bar'))
338 * @before <div id="foobar"></div><b></b><span id="foo"></span>
340 * @desc Returns -1, as there is no element with ID bar
344 * @param Element subject Object to search for
347 index: function( obj ) {
349 this.each(function(i){
350 if ( this == obj ) pos = i;
356 * Access a property on the first matched element.
357 * This method makes it easy to retrieve a property value
358 * from the first matched element.
360 * @example $("img").attr("src");
361 * @before <img src="test.jpg"/>
363 * @desc Returns the src attribute from the first image in the document.
367 * @param String name The name of the property to access.
368 * @cat DOM/Attributes
372 * Set a key/value object as properties to all matched elements.
374 * This serves as the best way to set a large number of properties
375 * on all matched elements.
377 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
379 * @result <img src="test.jpg" alt="Test Image"/>
380 * @desc Sets src and alt attributes to all images.
384 * @param Map properties Key/value pairs to set as object properties.
385 * @cat DOM/Attributes
389 * Set a single property to a value, on all matched elements.
391 * Note that you can't set the name property of input elements in IE.
392 * Use $(html) or .append(html) or .html(html) to create elements
393 * on the fly including the name property.
395 * @example $("img").attr("src","test.jpg");
397 * @result <img src="test.jpg"/>
398 * @desc Sets src attribute to all images.
402 * @param String key The name of the property to set.
403 * @param Object value The value to set the property to.
404 * @cat DOM/Attributes
406 attr: function( key, value, type ) {
407 // Check to see if we're setting style values
408 return typeof key != "string" || value != undefined ?
409 this.each(function(){
410 // See if we're setting a hash of styles
411 if ( value == undefined )
412 // Set all the styles
413 for ( var prop in key )
415 type ? this.style : this,
419 // See if we're setting a single key/value style
422 type ? this.style : this,
427 // Look for the case where we're accessing a style value
428 jQuery[ type || "attr" ]( this[0], key );
432 * Access a style property on the first matched element.
433 * This method makes it easy to retrieve a style property value
434 * from the first matched element.
436 * @example $("p").css("color");
437 * @before <p style="color:red;">Test Paragraph.</p>
439 * @desc Retrieves the color style of the first paragraph
441 * @example $("p").css("font-weight");
442 * @before <p style="font-weight: bold;">Test Paragraph.</p>
444 * @desc Retrieves the font-weight style of the first paragraph.
448 * @param String name The name of the property to access.
453 * Set a key/value object as style properties to all matched elements.
455 * This serves as the best way to set a large number of style properties
456 * on all matched elements.
458 * @example $("p").css({ color: "red", background: "blue" });
459 * @before <p>Test Paragraph.</p>
460 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
461 * @desc Sets color and background styles to all p elements.
465 * @param Map properties Key/value pairs to set as style properties.
470 * Set a single style property to a value, on all matched elements.
472 * @example $("p").css("color","red");
473 * @before <p>Test Paragraph.</p>
474 * @result <p style="color:red;">Test Paragraph.</p>
475 * @desc Changes the color of all paragraphs to red
479 * @param String key The name of the property to set.
480 * @param Object value The value to set the property to.
483 css: function( key, value ) {
484 return this.attr( key, value, "curCSS" );
488 * Get the text contents of all matched elements. The result is
489 * a string that contains the combined text contents of all matched
490 * elements. This method works on both HTML and XML documents.
492 * @example $("p").text();
493 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
494 * @result Test Paragraph.Paraparagraph
495 * @desc Gets the concatenated text of all paragraphs
499 * @cat DOM/Attributes
503 * Set the text contents of all matched elements. This has the same
506 * @example $("p").text("Some new text.");
507 * @before <p>Test Paragraph.</p>
508 * @result <p>Some new text.</p>
509 * @desc Sets the text of all paragraphs.
513 * @param String val The text value to set the contents of the element to.
514 * @cat DOM/Attributes
517 // A surprisingly high number of people expect the
518 // .text() method to do this, so lets do it!
519 if ( typeof e == "string" )
520 return this.html( e );
524 for ( var j = 0, el = e.length; j < el; j++ ) {
525 var r = e[j].childNodes;
526 for ( var i = 0, rl = r.length; i < rl; i++ )
527 if ( r[i].nodeType != 8 )
528 t += r[i].nodeType != 1 ?
529 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
535 * Wrap all matched elements with a structure of other elements.
536 * This wrapping process is most useful for injecting additional
537 * stucture into a document, without ruining the original semantic
538 * qualities of a document.
540 * This works by going through the first element
541 * provided (which is generated, on the fly, from the provided HTML)
542 * and finds the deepest ancestor element within its
543 * structure - it is that element that will en-wrap everything else.
545 * This does not work with elements that contain text. Any necessary text
546 * must be added after the wrapping is done.
548 * @example $("p").wrap("<div class='wrap'></div>");
549 * @before <p>Test Paragraph.</p>
550 * @result <div class='wrap'><p>Test Paragraph.</p></div>
554 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
555 * @cat DOM/Manipulation
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 and finding the deepest ancestor element within its
566 * structure - it is that element that will en-wrap everything else.
568 * This does not work with elements that contain text. Any necessary text
569 * must be added after the wrapping is done.
571 * @example $("p").wrap( document.getElementById('content') );
572 * @before <p>Test Paragraph.</p><div id="content"></div>
573 * @result <div id="content"><p>Test Paragraph.</p></div>
577 * @param Element elem A DOM element that will be wrapped around the target.
578 * @cat DOM/Manipulation
581 // The elements to wrap the target around
582 var a = jQuery.clean(arguments);
584 // Wrap each of the matched elements individually
585 return this.each(function(){
586 // Clone the structure that we're using to wrap
587 var b = a[0].cloneNode(true);
589 // Insert it before the element to be wrapped
590 this.parentNode.insertBefore( b, this );
592 // Find the deepest point in the wrap structure
593 while ( b.firstChild )
596 // Move the matched element to within the wrap structure
597 b.appendChild( this );
602 * Append content to the inside of every matched element.
604 * This operation is similar to doing an appendChild to all the
605 * specified elements, adding them into the document.
607 * @example $("p").append("<b>Hello</b>");
608 * @before <p>I would like to say: </p>
609 * @result <p>I would like to say: <b>Hello</b></p>
610 * @desc Appends some HTML to all paragraphs.
612 * @example $("p").append( $("#foo")[0] );
613 * @before <p>I would like to say: </p><b id="foo">Hello</b>
614 * @result <p>I would like to say: <b id="foo">Hello</b></p>
615 * @desc Appends an Element to all paragraphs.
617 * @example $("p").append( $("b") );
618 * @before <p>I would like to say: </p><b>Hello</b>
619 * @result <p>I would like to say: <b>Hello</b></p>
620 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
624 * @param <Content> content Content to append to the target
625 * @cat DOM/Manipulation
626 * @see prepend(<Content>)
627 * @see before(<Content>)
628 * @see after(<Content>)
631 return this.domManip(arguments, true, 1, function(a){
632 this.appendChild( a );
637 * Prepend content to the inside of every matched element.
639 * This operation is the best way to insert elements
640 * inside, at the beginning, of all matched elements.
642 * @example $("p").prepend("<b>Hello</b>");
643 * @before <p>I would like to say: </p>
644 * @result <p><b>Hello</b>I would like to say: </p>
645 * @desc Prepends some HTML to all paragraphs.
647 * @example $("p").prepend( $("#foo")[0] );
648 * @before <p>I would like to say: </p><b id="foo">Hello</b>
649 * @result <p><b id="foo">Hello</b>I would like to say: </p>
650 * @desc Prepends an Element to all paragraphs.
652 * @example $("p").prepend( $("b") );
653 * @before <p>I would like to say: </p><b>Hello</b>
654 * @result <p><b>Hello</b>I would like to say: </p>
655 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
659 * @param <Content> content Content to prepend to the target.
660 * @cat DOM/Manipulation
661 * @see append(<Content>)
662 * @see before(<Content>)
663 * @see after(<Content>)
665 prepend: function() {
666 return this.domManip(arguments, true, -1, function(a){
667 this.insertBefore( a, this.firstChild );
672 * Insert content before each of the matched elements.
674 * @example $("p").before("<b>Hello</b>");
675 * @before <p>I would like to say: </p>
676 * @result <b>Hello</b><p>I would like to say: </p>
677 * @desc Inserts some HTML before all paragraphs.
679 * @example $("p").before( $("#foo")[0] );
680 * @before <p>I would like to say: </p><b id="foo">Hello</b>
681 * @result <b id="foo">Hello</b><p>I would like to say: </p>
682 * @desc Inserts an Element before all paragraphs.
684 * @example $("p").before( $("b") );
685 * @before <p>I would like to say: </p><b>Hello</b>
686 * @result <b>Hello</b><p>I would like to say: </p>
687 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
691 * @param <Content> content Content to insert before each target.
692 * @cat DOM/Manipulation
693 * @see append(<Content>)
694 * @see prepend(<Content>)
695 * @see after(<Content>)
698 return this.domManip(arguments, false, 1, function(a){
699 this.parentNode.insertBefore( a, this );
704 * Insert content after each of the matched elements.
706 * @example $("p").after("<b>Hello</b>");
707 * @before <p>I would like to say: </p>
708 * @result <p>I would like to say: </p><b>Hello</b>
709 * @desc Inserts some HTML after all paragraphs.
711 * @example $("p").after( $("#foo")[0] );
712 * @before <b id="foo">Hello</b><p>I would like to say: </p>
713 * @result <p>I would like to say: </p><b id="foo">Hello</b>
714 * @desc Inserts an Element after all paragraphs.
716 * @example $("p").after( $("b") );
717 * @before <b>Hello</b><p>I would like to say: </p>
718 * @result <p>I would like to say: </p><b>Hello</b>
719 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
723 * @param <Content> content Content to insert after each target.
724 * @cat DOM/Manipulation
725 * @see append(<Content>)
726 * @see prepend(<Content>)
727 * @see before(<Content>)
730 return this.domManip(arguments, false, -1, function(a){
731 this.parentNode.insertBefore( a, this.nextSibling );
736 * End the most recent 'destructive' operation, reverting the list of matched elements
737 * back to its previous state. After an end operation, the list of matched elements will
738 * revert to the last state of matched elements.
740 * If there was no destructive operation before, an empty set is returned.
742 * @example $("p").find("span").end();
743 * @before <p><span>Hello</span>, how are you?</p>
744 * @result [ <p>...</p> ]
745 * desc Selects all paragraphs, finds span elements inside these, and reverts the
746 * selection back to the paragraphs.
750 * @cat DOM/Traversing
753 return this.prevObject || jQuery([]);
757 * Searches for all elements that match the specified expression.
759 * This method is a good way to find additional descendant
760 * elements with which to process.
762 * All searching is done using a jQuery expression. The expression can be
763 * written using CSS 1-3 Selector syntax, or basic XPath.
765 * @example $("p").find("span");
766 * @before <p><span>Hello</span>, how are you?</p>
767 * @result [ <span>Hello</span> ]
768 * @desc Starts with all paragraphs and searches for descendant span
769 * elements, same as $("p span")
773 * @param String expr An expression to search with.
774 * @cat DOM/Traversing
777 return this.set( jQuery.map( this, function(a){
778 return jQuery.find(t,a);
783 * Clone matched DOM Elements and select the clones.
785 * This is useful for moving copies of the elements to another
786 * location in the DOM.
788 * @example $("b").clone().prependTo("p");
789 * @before <b>Hello</b><p>, how are you?</p>
790 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
791 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
795 * @cat DOM/Manipulation
797 clone: function(deep) {
798 return this.set( jQuery.map( this, function(a){
799 return a.cloneNode( deep != undefined ? deep : true );
804 * Removes all elements from the set of matched elements that do not
805 * match the specified expression(s). This method is used to narrow down
806 * the results of a search.
808 * Provide a String array of expressions to apply multiple filters at once.
810 * @example $("p").filter(".selected")
811 * @before <p class="selected">Hello</p><p>How are you?</p>
812 * @result [ <p class="selected">Hello</p> ]
813 * @desc Selects all paragraphs and removes those without a class "selected".
815 * @example $("p").filter([".selected", ":first"])
816 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
817 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
818 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
822 * @param String|Array<String> expression Expression(s) to search with.
823 * @cat DOM/Traversing
827 * Removes all elements from the set of matched elements that do not
828 * pass the specified filter. This method is used to narrow down
829 * the results of a search.
831 * @example $("p").filter(function(index) {
832 * return $("ol", this).length == 0;
834 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
835 * @result [ <p>How are you?</p> ]
836 * @desc Remove all elements that have a child ol element
840 * @param Function filter A function to use for filtering
841 * @cat DOM/Traversing
843 filter: function(t) {
845 t.constructor == Array &&
846 jQuery.map(this,function(a){
847 for ( var i = 0, tl = t.length; i < tl; i++ )
848 if ( jQuery.filter(t[i],[a]).r.length )
853 t.constructor == Boolean &&
854 ( t ? this.get() : [] ) ||
856 typeof t == "function" &&
857 jQuery.grep( this, function(el, index) { return t.apply(el, [index]) }) ||
859 jQuery.filter(t,this).r );
863 * Removes the specified Element from the set of matched elements. This
864 * method is used to remove a single Element from a jQuery object.
866 * @example $("p").not( $("#selected")[0] )
867 * @before <p>Hello</p><p id="selected">Hello Again</p>
868 * @result [ <p>Hello</p> ]
869 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
873 * @param Element el An element to remove from the set
874 * @cat DOM/Traversing
878 * Removes elements matching the specified expression from the set
879 * of matched elements. This method is used to remove one or more
880 * elements from a jQuery object.
882 * @example $("p").not("#selected")
883 * @before <p>Hello</p><p id="selected">Hello Again</p>
884 * @result [ <p>Hello</p> ]
885 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
889 * @param String expr An expression with which to remove matching elements
890 * @cat DOM/Traversing
893 return this.set( typeof t == "string" ?
894 jQuery.filter(t,this,true).r :
895 jQuery.grep(this,function(a){ return a != t; }) );
899 * Adds the elements matched by the expression to the jQuery object. This
900 * can be used to concatenate the result sets of two expressions.
902 * @example $("p").add("span")
903 * @before <p>Hello</p><p><span>Hello Again</span></p>
904 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
908 * @param String expr An expression whose matched elements are added
909 * @cat DOM/Traversing
913 * Adds one or more Elements to the set of matched elements.
915 * This is used to add a set of Elements to a jQuery object.
917 * @example $("p").add( document.getElementById("a") )
918 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
919 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
921 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
922 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
923 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
927 * @param Element|Array<Element> elements One or more Elements to add
928 * @cat DOM/Traversing
931 return this.set( jQuery.merge(
932 this.get(), typeof t == "string" ?
934 t.constructor == Array ? t : [t] ) );
938 * Checks the current selection against an expression and returns true,
939 * if at least one element of the selection fits the given expression.
941 * Does return false, if no element fits or the expression is not valid.
943 * filter(String) is used internally, therefore all rules that apply there
946 * @example $("input[@type='checkbox']").parent().is("form")
947 * @before <form><input type="checkbox" /></form>
949 * @desc Returns true, because the parent of the input is a form element
951 * @example $("input[@type='checkbox']").parent().is("form")
952 * @before <form><p><input type="checkbox" /></p></form>
954 * @desc Returns false, because the parent of the input is a p element
958 * @param String expr The expression with which to filter
959 * @cat DOM/Traversing
962 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
966 * Get the current value of the first matched element.
968 * @example $("input").val();
969 * @before <input type="text" value="some text"/>
970 * @result "some text"
974 * @cat DOM/Attributes
978 * Set the value of every matched element.
980 * @example $("input").val("test");
981 * @before <input type="text" value="some text"/>
982 * @result <input type="text" value="test"/>
986 * @param String val Set the property to the specified value.
987 * @cat DOM/Attributes
989 val: function( val ) {
990 return val == undefined ?
\r ( this.length ? this[0].value : null ) :
\r this.attr( "value", val );
994 * Get the html contents of the first matched element.
995 * This property is not available on XML documents.
997 * @example $("div").html();
998 * @before <div><input/></div>
1003 * @cat DOM/Attributes
1007 * Set the html contents of every matched element.
1008 * This property is not available on XML documents.
1010 * @example $("div").html("<b>new stuff</b>");
1011 * @before <div><input/></div>
1012 * @result <div><b>new stuff</b></div>
1016 * @param String val Set the html contents to the specified value.
1017 * @cat DOM/Attributes
1019 html: function( val ) {
1020 return val == undefined ?
\r ( this.length ? this[0].innerHTML : null ) :
\r this.attr( "innerHTML", val );
1027 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1028 * @param Number dir If dir<0, process args in reverse order.
1029 * @param Function fn The function doing the DOM manipulation.
1033 domManip: function(args, table, dir, fn){
1034 var clone = this.length > 1;
1035 var a = jQuery.clean(args);
1039 return this.each(function(){
1042 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1043 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1045 for ( var i = 0, al = a.length; i < al; i++ )
1046 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1053 * Extends the jQuery object itself. Can be used to add functions into
1054 * the jQuery namespace and to add plugin methods (plugins).
1056 * @example jQuery.fn.extend({
1057 * check: function() {
1058 * return this.each(function() { this.checked = true; });
1060 * uncheck: function() {
1061 * return this.each(function() { this.checked = false; });
1064 * $("input[@type=checkbox]").check();
1065 * $("input[@type=radio]").uncheck();
1066 * @desc Adds two plugin methods.
1068 * @example jQuery.extend({
1069 * min: function(a, b) { return a < b ? a : b; },
1070 * max: function(a, b) { return a > b ? a : b; }
1072 * @desc Adds two functions into the jQuery namespace
1075 * @param Object prop The object that will be merged into the jQuery object
1081 * Extend one object with one or more others, returning the original,
1082 * modified, object. This is a great utility for simple inheritance.
1084 * @example var settings = { validate: false, limit: 5, name: "foo" };
1085 * var options = { validate: true, name: "bar" };
1086 * jQuery.extend(settings, options);
1087 * @result settings == { validate: true, limit: 5, name: "bar" }
1088 * @desc Merge settings and options, modifying settings
1090 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1091 * var options = { validate: true, name: "bar" };
1092 * var settings = jQuery.extend({}, defaults, options);
1093 * @result settings == { validate: true, limit: 5, name: "bar" }
1094 * @desc Merge defaults and options, without modifying the defaults
1097 * @param Object target The object to extend
1098 * @param Object prop1 The object that will be merged into the first.
1099 * @param Object propN (optional) More objects to merge into the first
1103 jQuery.extend = jQuery.fn.extend = function() {
1104 // copy reference to target object
1105 var target = arguments[0],
1108 // extend jQuery itself if only one argument is passed
1109 if ( arguments.length == 1 ) {
1114 while (prop = arguments[a++])
1115 // Extend the base object
1116 for ( var i in prop ) target[i] = prop[i];
1118 // Return the modified object
1124 * Run this function to give control of the $ variable back
1125 * to whichever library first implemented it. This helps to make
1126 * sure that jQuery doesn't conflict with the $ object
1127 * of other libraries.
1129 * By using this function, you will only be able to access jQuery
1130 * using the 'jQuery' variable. For example, where you used to do
1131 * $("div p"), you now must do jQuery("div p").
1133 * @example jQuery.noConflict();
1134 * // Do something with jQuery
1135 * jQuery("div p").hide();
1136 * // Do something with another library's $()
1137 * $("content").style.display = 'none';
1138 * @desc Maps the original object that was referenced by $ back to $
1140 * @example jQuery.noConflict();
1143 * // more code using $ as alias to jQuery
1146 * // other code using $ as an alias to the other library
1147 * @desc Reverts the $ alias and then creates and executes a
1148 * function to provide the $ as a jQuery alias inside the functions
1149 * scope. Inside the function the original $ object is not available.
1150 * This works well for most plugins that don't rely on any other library.
1153 * @name $.noConflict
1157 noConflict: function() {
1163 * A generic iterator function, which can be used to seemlessly
1164 * iterate over both objects and arrays. This function is not the same
1165 * as $().each() - which is used to iterate, exclusively, over a jQuery
1166 * object. This function can be used to iterate over anything.
1168 * The callback has two arguments:the key (objects) or index (arrays) as first
1169 * the first, and the value as the second.
1171 * @example $.each( [0,1,2], function(i, n){
1172 * alert( "Item #" + i + ": " + n );
1174 * @desc This is an example of iterating over the items in an array,
1175 * accessing both the current item and its index.
1177 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1178 * alert( "Name: " + i + ", Value: " + n );
1181 * @desc This is an example of iterating over the properties in an
1182 * Object, accessing both the current item and its key.
1185 * @param Object obj The object, or array, to iterate over.
1186 * @param Function fn The function that will be executed on every object.
1190 // args is for internal usage only
1191 each: function( obj, fn, args ) {
1192 if ( obj.length == undefined )
1193 for ( var i in obj )
1194 fn.apply( obj[i], args || [i, obj[i]] );
1196 for ( var i = 0, ol = obj.length; i < ol; i++ )
1197 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1202 add: function( elem, c ){
1203 jQuery.each( c.split(/\s+/), function(i, cur){
1204 if ( !jQuery.className.has( elem.className, cur ) )
1205 elem.className += ( elem.className ? " " : "" ) + cur;
1208 remove: function( elem, c ){
1209 elem.className = c ?
1210 jQuery.grep( elem.className.split(/\s+/), function(cur){
1211 return !jQuery.className.has( c, cur );
1214 has: function( classes, c ){
1215 return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
1220 * Swap in/out style options.
1223 swap: function(e,o,f) {
1224 for ( var i in o ) {
1225 e.style["old"+i] = e.style[i];
1230 e.style[i] = e.style["old"+i];
1233 css: function(e,p) {
1234 if ( p == "height" || p == "width" ) {
1235 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1237 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1238 old["padding" + d[i]] = 0;
1239 old["border" + d[i] + "Width"] = 0;
1242 jQuery.swap( e, old, function() {
1243 if (jQuery.css(e,"display") != "none") {
1244 oHeight = e.offsetHeight;
1245 oWidth = e.offsetWidth;
1247 e = jQuery(e.cloneNode(true))
1248 .find(":radio").removeAttr("checked").end()
1250 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1251 }).appendTo(e.parentNode)[0];
1253 var parPos = jQuery.css(e.parentNode,"position");
1254 if ( parPos == "" || parPos == "static" )
1255 e.parentNode.style.position = "relative";
1257 oHeight = e.clientHeight;
1258 oWidth = e.clientWidth;
1260 if ( parPos == "" || parPos == "static" )
1261 e.parentNode.style.position = "static";
1263 e.parentNode.removeChild(e);
1267 return p == "height" ? oHeight : oWidth;
1270 return jQuery.curCSS( e, p );
1273 curCSS: function(elem, prop, force) {
1276 if (prop == 'opacity' && jQuery.browser.msie)
1277 return jQuery.attr(elem.style, 'opacity');
1279 if (prop == "float" || prop == "cssFloat")
1280 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1282 if (!force && elem.style[prop]) {
1284 ret = elem.style[prop];
1286 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1288 if (prop == "cssFloat" || prop == "styleFloat")
1291 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1292 var cur = document.defaultView.getComputedStyle(elem, null);
1295 ret = cur.getPropertyValue(prop);
1296 else if ( prop == 'display' )
1299 jQuery.swap(elem, { display: 'block' }, function() {
1300 var c = document.defaultView.getComputedStyle(this, '');
1301 ret = c && c.getPropertyValue(prop) || '';
1304 } else if (elem.currentStyle) {
1306 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1307 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1314 clean: function(a) {
1316 for ( var i = 0, al = a.length; i < al; i++ ) {
1318 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
1319 // Trim whitespace, otherwise indexOf won't work as expected
1320 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6),
1321 div = document.createElement("div"), wrap = [0,"",""];
1323 if ( s.substring(0,4) == "<opt" ) // option or optgroup
1324 wrap = [1, "<select>", "</select>"];
1325 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" )
1326 wrap = [1, "<table>", "</table>"];
1327 else if ( s3 == "<tr" )
1328 wrap = [2, "<table><tbody>", "</tbody></table>"];
1329 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above
1330 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1332 // Go to html and back, then peel off extra wrappers
1333 div.innerHTML = wrap[1] + s + wrap[2];
1334 while ( wrap[0]-- ) div = div.firstChild;
1336 // Remove IE's autoinserted <tbody> from table fragments
1337 if ( jQuery.browser.msie ) {
1339 // String was a <table>, *may* have spurious <tbody>
1340 if ( s6 == "<table" && s.indexOf("<tbody") < 0 )
1341 tb = div.firstChild && div.firstChild.childNodes;
1342 // String was a bare <thead> or <tfoot>
1343 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1344 tb = div.childNodes;
1346 for ( var n = tb.length-1; n >= 0 ; --n )
1347 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1348 tb[n].parentNode.removeChild(tb[n]);
1352 arg = div.childNodes;
1356 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1357 for ( var n = 0, argl = arg.length; n < argl; n++ ) // Handles Array, jQuery, DOM NodeList collections
1360 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1366 attr: function(elem, name, value){
1369 "class": "className",
1370 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1371 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1372 innerHTML: "innerHTML",
1373 className: "className",
1375 disabled: "disabled",
1377 readonly: "readOnly",
1378 selected: "selected"
1381 // IE actually uses filters for opacity ... elem is actually elem.style
1382 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1383 // IE has trouble with opacity if it does not have layout
1384 // Force it by setting the zoom level
1387 // Set the alpha filter to set the opacity
1388 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1389 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1391 } else if ( name == "opacity" && jQuery.browser.msie ) {
1392 return elem.filter ?
1393 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1396 // Mozilla doesn't play well with opacity 1
1397 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1400 // Certain attributes only work when accessed via the old DOM 0 way
1402 if ( value != undefined ) elem[fix[name]] = value;
1403 return elem[fix[name]];
1405 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1406 return elem.getAttributeNode(name).nodeValue;
1408 // IE elem.getAttribute passes even for style
1409 } else if ( elem.tagName ) {
1410 if ( value != undefined ) elem.setAttribute( name, value );
1411 return elem.getAttribute( name );
1414 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1415 if ( value != undefined ) elem[name] = value;
1421 * Remove the whitespace from the beginning and end of a string.
1423 * @example $.trim(" hello, how are you? ");
1424 * @result "hello, how are you?"
1428 * @param String str The string to trim.
1432 return t.replace(/^\s+|\s+$/g, "");
1435 makeArray: function( a ) {
1438 if ( a.constructor != Array ) {
1439 for ( var i = 0, al = a.length; i < al; i++ )
1447 inArray: function( b, a ) {
1448 for ( var i = 0, al = a.length; i < al; i++ )
1455 * Merge two arrays together, removing all duplicates.
1457 * The new array is: All the results from the first array, followed
1458 * by the unique results from the second array.
1460 * @example $.merge( [0,1,2], [2,3,4] )
1461 * @result [0,1,2,3,4]
1462 * @desc Merges two arrays, removing the duplicate 2
1464 * @example $.merge( [3,2,1], [4,3,2] )
1466 * @desc Merges two arrays, removing the duplicates 3 and 2
1470 * @param Array first The first array to merge.
1471 * @param Array second The second array to merge.
1474 merge: function(first, second) {
1475 var r = [].slice.call( first, 0 );
1477 // Now check for duplicates between the two arrays
1478 // and only add the unique items
1479 for ( var i = 0, sl = second.length; i < sl; i++ ) {
1480 // Check for duplicates
1481 if ( jQuery.inArray( second[i], r ) == -1 )
1482 // The item is unique, add it
1483 first.push( second[i] );
1490 * Filter items out of an array, by using a filter function.
1492 * The specified function will be passed two arguments: The
1493 * current array item and the index of the item in the array. The
1494 * function must return 'true' to keep the item in the array,
1495 * false to remove it.
1497 * @example $.grep( [0,1,2], function(i){
1504 * @param Array array The Array to find items in.
1505 * @param Function fn The function to process each item against.
1506 * @param Boolean inv Invert the selection - select the opposite of the function.
1509 grep: function(elems, fn, inv) {
1510 // If a string is passed in for the function, make a function
1511 // for it (a handy shortcut)
1512 if ( typeof fn == "string" )
1513 fn = new Function("a","i","return " + fn);
1517 // Go through the array, only saving the items
1518 // that pass the validator function
1519 for ( var i = 0, el = elems.length; i < el; i++ )
1520 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1521 result.push( elems[i] );
1527 * Translate all items in an array to another array of items.
1529 * The translation function that is provided to this method is
1530 * called for each item in the array and is passed one argument:
1531 * The item to be translated.
1533 * The function can then return the translated value, 'null'
1534 * (to remove the item), or an array of values - which will
1535 * be flattened into the full array.
1537 * @example $.map( [0,1,2], function(i){
1541 * @desc Maps the original array to a new one and adds 4 to each value.
1543 * @example $.map( [0,1,2], function(i){
1544 * return i > 0 ? i + 1 : null;
1547 * @desc Maps the original array to a new one and adds 1 to each
1548 * value if it is bigger then zero, otherwise it's removed-
1550 * @example $.map( [0,1,2], function(i){
1551 * return [ i, i + 1 ];
1553 * @result [0, 1, 1, 2, 2, 3]
1554 * @desc Maps the original array to a new one, each element is added
1555 * with it's original value and the value plus one.
1559 * @param Array array The Array to translate.
1560 * @param Function fn The function to process each item against.
1563 map: function(elems, fn) {
1564 // If a string is passed in for the function, make a function
1565 // for it (a handy shortcut)
1566 if ( typeof fn == "string" )
1567 fn = new Function("a","return " + fn);
1569 var result = [], r = [];
1571 // Go through the array, translating each of the items to their
1572 // new value (or values).
1573 for ( var i = 0, el = elems.length; i < el; i++ ) {
1574 var val = fn(elems[i],i);
1576 if ( val !== null && val != undefined ) {
1577 if ( val.constructor != Array ) val = [val];
1578 result = result.concat( val );
1582 var r = [ result[0] ];
1584 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1585 for ( var j = 0; j < i; j++ )
1586 if ( result[i] == r[j] )
1589 r.push( result[i] );
1597 * Contains flags for the useragent, read from navigator.userAgent.
1598 * Available flags are: safari, opera, msie, mozilla
1600 * This property is available before the DOM is ready, therefore you can
1601 * use it to add ready events only for certain browsers.
1603 * There are situations where object detections is not reliable enough, in that
1604 * cases it makes sense to use browser detection. Simply try to avoid both!
1606 * A combination of browser and object detection yields quite reliable results.
1608 * @example $.browser.msie
1609 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1611 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1612 * @desc Alerts "this is safari!" only for safari browsers
1621 * Wheather the W3C compliant box model is being used.
1629 var b = navigator.userAgent.toLowerCase();
1631 // Figure out what browser is being used
1633 safari: /webkit/.test(b),
1634 opera: /opera/.test(b),
1635 msie: /msie/.test(b) && !/opera/.test(b),
1636 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1639 // Check to see if the W3C box model is being used
1640 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1644 * Get a set of elements containing the unique parents of the matched
1647 * Can be filtered with an optional expressions.
1649 * @example $("p").parent()
1650 * @before <div><p>Hello</p><p>Hello</p></div>
1651 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1652 * @desc Find the parent element of each paragraph.
1654 * @example $("p").parent(".selected")
1655 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1656 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1657 * @desc Find the parent element of each paragraph with a class "selected".
1661 * @param String expr (optional) An expression to filter the parents with
1662 * @cat DOM/Traversing
1666 * Get a set of elements containing the unique ancestors of the matched
1667 * set of elements (except for the root element).
1669 * Can be filtered with an optional expressions.
1671 * @example $("span").parents()
1672 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1673 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1674 * @desc Find all parent elements of each span.
1676 * @example $("span").parents("p")
1677 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1678 * @result [ <p><span>Hello</span></p> ]
1679 * @desc Find all parent elements of each span that is a paragraph.
1683 * @param String expr (optional) An expression to filter the ancestors with
1684 * @cat DOM/Traversing
1688 * Get a set of elements containing the unique next siblings of each of the
1689 * matched set of elements.
1691 * It only returns the very next sibling, not all next siblings.
1693 * Can be filtered with an optional expressions.
1695 * @example $("p").next()
1696 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1697 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1698 * @desc Find the very next sibling of each paragraph.
1700 * @example $("p").next(".selected")
1701 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1702 * @result [ <p class="selected">Hello Again</p> ]
1703 * @desc Find the very next sibling of each paragraph that has a class "selected".
1707 * @param String expr (optional) An expression to filter the next Elements with
1708 * @cat DOM/Traversing
1712 * Get a set of elements containing the unique previous siblings of each of the
1713 * matched set of elements.
1715 * Can be filtered with an optional expressions.
1717 * It only returns the immediately previous sibling, not all previous siblings.
1719 * @example $("p").prev()
1720 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1721 * @result [ <div><span>Hello Again</span></div> ]
1722 * @desc Find the very previous sibling of each paragraph.
1724 * @example $("p").prev(".selected")
1725 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1726 * @result [ <div><span>Hello</span></div> ]
1727 * @desc Find the very previous sibling of each paragraph that has a class "selected".
1731 * @param String expr (optional) An expression to filter the previous Elements with
1732 * @cat DOM/Traversing
1736 * Get a set of elements containing all of the unique siblings of each of the
1737 * matched set of elements.
1739 * Can be filtered with an optional expressions.
1741 * @example $("div").siblings()
1742 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1743 * @result [ <p>Hello</p>, <p>And Again</p> ]
1744 * @desc Find all siblings of each div.
1746 * @example $("div").siblings(".selected")
1747 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1748 * @result [ <p class="selected">Hello Again</p> ]
1749 * @desc Find all siblings with a class "selected" of each div.
1753 * @param String expr (optional) An expression to filter the sibling Elements with
1754 * @cat DOM/Traversing
1758 * Get a set of elements containing all of the unique children of each of the
1759 * matched set of elements.
1761 * Can be filtered with an optional expressions.
1763 * @example $("div").children()
1764 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1765 * @result [ <span>Hello Again</span> ]
1766 * @desc Find all children of each div.
1768 * @example $("div").children(".selected")
1769 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1770 * @result [ <p class="selected">Hello Again</p> ]
1771 * @desc Find all children with a class "selected" of each div.
1775 * @param String expr (optional) An expression to filter the child Elements with
1776 * @cat DOM/Traversing
1779 parent: "a.parentNode",
1780 parents: jQuery.parents,
1781 next: "jQuery.nth(a,1,'nextSibling')",
1782 prev: "jQuery.nth(a,1,'previousSibling')",
1783 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1784 children: "jQuery.sibling(a.firstChild)"
1786 jQuery.fn[ i ] = function(a) {
1787 var ret = jQuery.map(this,n);
1788 if ( a && typeof a == "string" )
1789 ret = jQuery.filter(a,ret).r;
1790 return this.set( ret );
1795 * Append all of the matched elements to another, specified, set of elements.
1796 * This operation is, essentially, the reverse of doing a regular
1797 * $(A).append(B), in that instead of appending B to A, you're appending
1800 * @example $("p").appendTo("#foo");
1801 * @before <p>I would like to say: </p><div id="foo"></div>
1802 * @result <div id="foo"><p>I would like to say: </p></div>
1803 * @desc Appends all paragraphs to the element with the ID "foo"
1807 * @param String expr A jQuery expression of elements to match.
1808 * @cat DOM/Manipulation
1812 * Prepend all of the matched elements to another, specified, set of elements.
1813 * This operation is, essentially, the reverse of doing a regular
1814 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1817 * @example $("p").prependTo("#foo");
1818 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1819 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1820 * @desc Prepends all paragraphs to the element with the ID "foo"
1824 * @param String expr A jQuery expression of elements to match.
1825 * @cat DOM/Manipulation
1829 * Insert all of the matched elements before another, specified, set of elements.
1830 * This operation is, essentially, the reverse of doing a regular
1831 * $(A).before(B), in that instead of inserting B before A, you're inserting
1834 * @example $("p").insertBefore("#foo");
1835 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1836 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1837 * @desc Same as $("#foo").before("p")
1839 * @name insertBefore
1841 * @param String expr A jQuery expression of elements to match.
1842 * @cat DOM/Manipulation
1846 * Insert all of the matched elements after another, specified, set of elements.
1847 * This operation is, essentially, the reverse of doing a regular
1848 * $(A).after(B), in that instead of inserting B after A, you're inserting
1851 * @example $("p").insertAfter("#foo");
1852 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1853 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1854 * @desc Same as $("#foo").after("p")
1858 * @param String expr A jQuery expression of elements to match.
1859 * @cat DOM/Manipulation
1864 prependTo: "prepend",
1865 insertBefore: "before",
1866 insertAfter: "after"
1868 jQuery.fn[ i ] = function(){
1870 return this.each(function(){
1871 for ( var j = 0, al = a.length; j < al; j++ )
1872 jQuery(a[j])[n]( this );
1878 * Remove an attribute from each of the matched elements.
1880 * @example $("input").removeAttr("disabled")
1881 * @before <input disabled="disabled"/>
1886 * @param String name The name of the attribute to remove.
1887 * @cat DOM/Attributes
1891 * Displays each of the set of matched elements if they are hidden.
1893 * @example $("p").show()
1894 * @before <p style="display: none">Hello</p>
1895 * @result [ <p style="display: block">Hello</p> ]
1903 * Hides each of the set of matched elements if they are shown.
1905 * @example $("p").hide()
1906 * @before <p>Hello</p>
1907 * @result [ <p style="display: none">Hello</p> ]
1909 * var pass = true, div = $("div");
1910 * div.hide().each(function(){
1911 * if ( this.style.display != "none" ) pass = false;
1913 * ok( pass, "Hide" );
1921 * Toggles each of the set of matched elements. If they are shown,
1922 * toggle makes them hidden. If they are hidden, toggle
1925 * @example $("p").toggle()
1926 * @before <p>Hello</p><p style="display: none">Hello Again</p>
1927 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
1935 * Adds the specified class to each of the set of matched elements.
1937 * @example $("p").addClass("selected")
1938 * @before <p>Hello</p>
1939 * @result [ <p class="selected">Hello</p> ]
1943 * @param String class A CSS class to add to the elements
1944 * @cat DOM/Attributes
1945 * @see removeClass(String)
1949 * Removes all or the specified class from the set of matched elements.
1951 * @example $("p").removeClass()
1952 * @before <p class="selected">Hello</p>
1953 * @result [ <p>Hello</p> ]
1955 * @example $("p").removeClass("selected")
1956 * @before <p class="selected first">Hello</p>
1957 * @result [ <p class="first">Hello</p> ]
1961 * @param String class (optional) A CSS class to remove from the elements
1962 * @cat DOM/Attributes
1963 * @see addClass(String)
1967 * Adds the specified class if it is not present, removes it if it is
1970 * @example $("p").toggleClass("selected")
1971 * @before <p>Hello</p><p class="selected">Hello Again</p>
1972 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
1976 * @param String class A CSS class with which to toggle the elements
1977 * @cat DOM/Attributes
1981 * Removes all matched elements from the DOM. This does NOT remove them from the
1982 * jQuery object, allowing you to use the matched elements further.
1984 * Can be filtered with an optional expressions.
1986 * @example $("p").remove();
1987 * @before <p>Hello</p> how are <p>you?</p>
1990 * @example $("p").remove(".hello");
1991 * @before <p class="hello">Hello</p> how are <p>you?</p>
1992 * @result how are <p>you?</p>
1996 * @param String expr (optional) A jQuery expression to filter elements by.
1997 * @cat DOM/Manipulation
2001 * Removes all child nodes from the set of matched elements.
2003 * @example $("p").empty()
2004 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2005 * @result [ <p></p> ]
2009 * @cat DOM/Manipulation
2013 removeAttr: function( key ) {
2014 jQuery.attr( this, key, "" );
2015 this.removeAttribute( key );
2018 this.style.display = this.oldblock ? this.oldblock : "";
2019 if ( jQuery.css(this,"display") == "none" )
2020 this.style.display = "block";
2023 this.oldblock = this.oldblock || jQuery.css(this,"display");
2024 if ( this.oldblock == "none" )
2025 this.oldblock = "block";
2026 this.style.display = "none";
2029 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2031 addClass: function(c){
2032 jQuery.className.add(this,c);
2034 removeClass: function(c){
2035 jQuery.className.remove(this,c);
2037 toggleClass: function( c ){
2038 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2040 remove: function(a){
2041 if ( !a || jQuery.filter( a, [this] ).r )
2042 this.parentNode.removeChild( this );
2045 while ( this.firstChild )
2046 this.removeChild( this.firstChild );
2049 jQuery.fn[ i ] = function() {
2050 return this.each( n, arguments );
2055 * Reduce the set of matched elements to a single element.
2056 * The position of the element in the set of matched elements
2057 * starts at 0 and goes to length - 1.
2059 * @example $("p").eq(1)
2060 * @before <p>This is just a test.</p><p>So is this</p>
2061 * @result [ <p>So is this</p> ]
2065 * @param Number pos The index of the element that you wish to limit to.
2070 * Reduce the set of matched elements to all elements before a given position.
2071 * The position of the element in the set of matched elements
2072 * starts at 0 and goes to length - 1.
2074 * @example $("p").lt(1)
2075 * @before <p>This is just a test.</p><p>So is this</p>
2076 * @result [ <p>This is just a test.</p> ]
2080 * @param Number pos Reduce the set to all elements below this position.
2085 * Reduce the set of matched elements to all elements after a given position.
2086 * The position of the element in the set of matched elements
2087 * starts at 0 and goes to length - 1.
2089 * @example $("p").gt(0)
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 Reduce the set to all elements after this position.
2100 * Filter the set of elements to those that contain the specified text.
2102 * @example $("p").contains("test")
2103 * @before <p>This is just a test.</p><p>So is this</p>
2104 * @result [ <p>This is just a test.</p> ]
2108 * @param String str The string that will be contained within the text of an element.
2109 * @cat DOM/Traversing
2111 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2112 jQuery.fn[ n ] = function(num,fn) {
2113 return this.filter( ":" + n + "(" + num + ")", fn );