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.
13 * Create a new jQuery Object
18 * @param String|Function|Element|Array<Element>|jQuery a selector
19 * @param jQuery|Element|Array<Element> c context
23 // Map over jQuery in case of overwrite
24 if ( typeof jQuery != "undefined" )
27 var jQuery = window.jQuery = function(a,c) {
28 // If the context is global, return a new object
29 if ( window == this || !this.init )
30 return new jQuery(a,c);
32 return this.init(a,c);
35 // Map over the $ in case of overwrite
36 if ( typeof $ != "undefined" )
39 // Map the jQuery namespace to the '$' one
42 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
45 * This function accepts a string containing a CSS or
46 * basic XPath selector which is then used to match a set of elements.
48 * The core functionality of jQuery centers around this function.
49 * Everything in jQuery is based upon this, or uses this in some way.
50 * The most basic use of this function is to pass in an expression
51 * (usually consisting of CSS or XPath), which then finds all matching
54 * By default, if no context is specified, $() looks for DOM elements within the context of the
55 * current HTML document. If you do specify a context, such as a DOM
56 * element or jQuery object, the expression will be matched against
57 * the contents of that context.
59 * See [[DOM/Traversing/Selectors]] for the allowed CSS/XPath syntax for expressions.
61 * @example $("div > p")
62 * @desc Finds all p elements that are children of a div element.
63 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
64 * @result [ <p>two</p> ]
66 * @example $("input:radio", document.forms[0])
67 * @desc Searches for all inputs of type radio within the first form in the document
69 * @example $("div", xml.responseXML)
70 * @desc This finds all div elements within the specified XML document.
73 * @param String expr An expression to search with
74 * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
78 * @see $(Element<Array>)
82 * Create DOM elements on-the-fly from the provided String of raw HTML.
84 * @example $("<div><p>Hello</p></div>").appendTo("body")
85 * @desc Creates a div element (and all of its contents) dynamically,
86 * and appends it to the body element. Internally, an
87 * element is created and its innerHTML property set to the given markup.
88 * It is therefore both quite flexible and limited.
91 * @param String html A string of HTML to create on the fly.
94 * @see appendTo(String)
98 * Wrap jQuery functionality around a single or multiple DOM Element(s).
100 * This function also accepts XML Documents and Window objects
101 * as valid arguments (even though they are not DOM Elements).
103 * @example $(document.body).css( "background", "black" );
104 * @desc Sets the background color of the page to black.
106 * @example $( myForm.elements ).hide()
107 * @desc Hides all the input elements within a form
110 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
116 * A shorthand for $(document).ready(), allowing you to bind a function
117 * to be executed when the DOM document has finished loading. This function
118 * behaves just like $(document).ready(), in that it should be used to wrap
119 * other $() operations on your page that depend on the DOM being ready to be
120 * operated on. While this function is, technically, chainable - there really
121 * isn't much use for chaining against it.
123 * You can have as many $(document).ready events on your page as you like.
125 * See ready(Function) for details about the ready event.
127 * @example $(function(){
128 * // Document is ready
130 * @desc Executes the function when the DOM is ready to be used.
132 * @example jQuery(function($) {
133 * // Your code using failsafe $ alias here...
135 * @desc Uses both the shortcut for $(document).ready() and the argument
136 * to write failsafe jQuery code using the $ alias, without relying on the
140 * @param Function fn The function to execute when the DOM is ready.
143 * @see ready(Function)
146 jQuery.fn = jQuery.prototype = {
148 * Initialize a new jQuery object
152 * @param String|Function|Element|Array<Element>|jQuery a selector
153 * @param jQuery|Element|Array<Element> c context
156 init: function(a,c) {
157 // Make sure that a selection was provided
160 // Handle HTML strings
161 if ( typeof a == "string" ) {
162 var m = quickExpr.exec(a);
163 if ( m && (m[1] || !c) ) {
164 // HANDLE: $(html) -> $(array)
166 a = jQuery.clean( [ m[1] ], c );
170 var tmp = document.getElementById( m[3] );
172 // Handle the case where IE and Opera return items
173 // by name instead of ID
174 if ( tmp.id != m[3] )
175 return jQuery().find( a );
187 return new jQuery( c ).find( a );
189 // HANDLE: $(function)
190 // Shortcut for document ready
191 } else if ( jQuery.isFunction(a) )
192 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
194 return this.setArray(
196 a.constructor == Array && a ||
198 // HANDLE: $(arraylike)
199 // Watch for when an array-like object is passed as the selector
200 (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
207 * The current version of jQuery.
218 * The number of elements currently matched. The size function will return the same value.
220 * @example $("img").length;
221 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
231 * Get the number of elements currently matched. This returns the same
232 * number as the 'length' property of the jQuery object.
234 * @example $("img").size();
235 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
249 * Access all matched DOM elements. This serves as a backwards-compatible
250 * way of accessing all matched elements (other than the jQuery object
251 * itself, which is, in fact, an array of elements).
253 * It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions.
255 * @example $("img").get();
256 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
257 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
258 * @desc Selects all images in the document and returns the DOM Elements as an Array
261 * @type Array<Element>
266 * Access a single matched DOM element at a specified index in the matched set.
267 * This allows you to extract the actual DOM element and operate on it
268 * directly without necessarily using jQuery functionality on it.
270 * @example $("img").get(0);
271 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
272 * @result <img src="test1.jpg"/>
273 * @desc Selects all images in the document and returns the first one
277 * @param Number num Access the element in the Nth position.
280 get: function( num ) {
281 return num == undefined ?
283 // Return a 'clean' array
284 jQuery.makeArray( this ) :
286 // Return just the object
291 * Set the jQuery object to an array of elements, while maintaining
294 * @example $("img").pushStack([ document.body ]);
295 * @result $("img").pushStack() == [ document.body ]
300 * @param Elements elems An array of elements
303 pushStack: function( a ) {
305 ret.prevObject = this;
310 * Set the jQuery object to an array of elements. This operation is
311 * completely destructive - be sure to use .pushStack() if you wish to maintain
314 * @example $("img").setArray([ document.body ]);
315 * @result $("img").setArray() == [ document.body ]
320 * @param Elements elems An array of elements
323 setArray: function( a ) {
325 Array.prototype.push.apply( this, a );
330 * Execute a function within the context of every matched element.
331 * This means that every time the passed-in function is executed
332 * (which is once for every element matched) the 'this' keyword
333 * points to the specific DOM element.
335 * Additionally, the function, when executed, is passed a single
336 * argument representing the position of the element in the matched
337 * set (integer, zero-index).
339 * @example $("img").each(function(i){
340 * this.src = "test" + i + ".jpg";
342 * @before <img/><img/>
343 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
344 * @desc Iterates over two images and sets their src property
348 * @param Function fn A function to execute
351 each: function( fn, args ) {
352 return jQuery.each( this, fn, args );
356 * Searches every matched element for the object and returns
357 * the index of the element, if found, starting with zero.
358 * Returns -1 if the object wasn't found.
360 * @example $("*").index( $('#foobar')[0] )
361 * @before <div id="foobar"><b></b><span id="foo"></span></div>
363 * @desc Returns the index for the element with ID foobar
365 * @example $("*").index( $('#foo')[0] )
366 * @before <div id="foobar"><b></b><span id="foo"></span></div>
368 * @desc Returns the index for the element with ID foo within another element
370 * @example $("*").index( $('#bar')[0] )
371 * @before <div id="foobar"><b></b><span id="foo"></span></div>
373 * @desc Returns -1, as there is no element with ID bar
377 * @param Element subject Object to search for
380 index: function( obj ) {
382 this.each(function(i){
383 if ( this == obj ) pos = i;
389 * Access a property on the first matched element.
390 * This method makes it easy to retrieve a property value
391 * from the first matched element.
393 * If the element does not have an attribute with such a
394 * name, undefined is returned.
396 * @example $("img").attr("src");
397 * @before <img src="test.jpg"/>
399 * @desc Returns the src attribute from the first image in the document.
403 * @param String name The name of the property to access.
404 * @cat DOM/Attributes
408 * Set a key/value object as properties to all matched elements.
410 * This serves as the best way to set a large number of properties
411 * on all matched elements.
413 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
415 * @result <img src="test.jpg" alt="Test Image"/>
416 * @desc Sets src and alt attributes to all images.
420 * @param Map properties Key/value pairs to set as object properties.
421 * @cat DOM/Attributes
425 * Set a single property to a value, on all matched elements.
427 * Note that you can't set the name property of input elements in IE.
428 * Use $(html) or .append(html) or .html(html) to create elements
429 * on the fly including the name property.
431 * @example $("img").attr("src","test.jpg");
433 * @result <img src="test.jpg"/>
434 * @desc Sets src attribute to all images.
438 * @param String key The name of the property to set.
439 * @param Object value The value to set the property to.
440 * @cat DOM/Attributes
444 * Set a single property to a computed value, on all matched elements.
446 * Instead of supplying a string value as described
447 * [[DOM/Attributes#attr.28_key.2C_value_.29|above]],
448 * a function is provided that computes the value.
450 * @example $("img").attr("title", function() { return this.src });
451 * @before <img src="test.jpg" />
452 * @result <img src="test.jpg" title="test.jpg" />
453 * @desc Sets title attribute from src attribute.
455 * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
456 * @before <img title="pic" /><img title="pic" /><img title="pic" />
457 * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
458 * @desc Enumerate title attribute.
462 * @param String key The name of the property to set.
463 * @param Function value A function returning the value to set.
464 * Scope: Current element, argument: Index of current element
465 * @cat DOM/Attributes
467 attr: function( key, value, type ) {
470 // Look for the case where we're accessing a style value
471 if ( key.constructor == String )
472 if ( value == undefined )
473 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
479 // Check to see if we're setting style values
480 return this.each(function(index){
481 // Set all the styles
482 for ( var prop in obj )
484 type ? this.style : this,
485 prop, jQuery.prop(this, obj[prop], type, index, prop)
491 * Access a style property on the first matched element.
492 * This method makes it easy to retrieve a style property value
493 * from the first matched element.
495 * @example $("p").css("color");
496 * @before <p style="color:red;">Test Paragraph.</p>
498 * @desc Retrieves the color style of the first paragraph
500 * @example $("p").css("font-weight");
501 * @before <p style="font-weight: bold;">Test Paragraph.</p>
503 * @desc Retrieves the font-weight style of the first paragraph.
507 * @param String name The name of the property to access.
512 * Set a key/value object as style properties to all matched elements.
514 * This serves as the best way to set a large number of style properties
515 * on all matched elements.
517 * @example $("p").css({ color: "red", background: "blue" });
518 * @before <p>Test Paragraph.</p>
519 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
520 * @desc Sets color and background styles to all p elements.
524 * @param Map properties Key/value pairs to set as style properties.
529 * Set a single style property to a value, on all matched elements.
530 * If a number is provided, it is automatically converted into a pixel value.
532 * @example $("p").css("color","red");
533 * @before <p>Test Paragraph.</p>
534 * @result <p style="color:red;">Test Paragraph.</p>
535 * @desc Changes the color of all paragraphs to red
537 * @example $("p").css("left",30);
538 * @before <p>Test Paragraph.</p>
539 * @result <p style="left:30px;">Test Paragraph.</p>
540 * @desc Changes the left of all paragraphs to "30px"
544 * @param String key The name of the property to set.
545 * @param String|Number value The value to set the property to.
548 css: function( key, value ) {
549 return this.attr( key, value, "curCSS" );
553 * Get the text contents of all matched elements. The result is
554 * a string that contains the combined text contents of all matched
555 * elements. This method works on both HTML and XML documents.
557 * @example $("p").text();
558 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
559 * @result Test Paragraph.Paraparagraph
560 * @desc Gets the concatenated text of all paragraphs
564 * @cat DOM/Attributes
568 * Set the text contents of all matched elements.
570 * Similar to html(), but escapes HTML (replace "<" and ">" with their
573 * @example $("p").text("<b>Some</b> new text.");
574 * @before <p>Test Paragraph.</p>
575 * @result <p><b>Some</b> new text.</p>
576 * @desc Sets the text of all paragraphs.
578 * @example $("p").text("<b>Some</b> new text.", true);
579 * @before <p>Test Paragraph.</p>
580 * @result <p>Some new text.</p>
581 * @desc Sets the text of all paragraphs.
585 * @param String val The text value to set the contents of the element to.
586 * @cat DOM/Attributes
589 if ( typeof e != "object" && e != null )
590 return this.empty().append( document.createTextNode( e ) );
593 jQuery.each( e || this, function(){
594 jQuery.each( this.childNodes, function(){
595 if ( this.nodeType != 8 )
596 t += this.nodeType != 1 ?
597 this.nodeValue : jQuery.fn.text([ this ]);
604 * Wrap all matched elements with a structure of other elements.
605 * This wrapping process is most useful for injecting additional
606 * stucture into a document, without ruining the original semantic
607 * qualities of a document.
609 * This works by going through the first element
610 * provided (which is generated, on the fly, from the provided HTML)
611 * and finds the deepest ancestor element within its
612 * structure - it is that element that will en-wrap everything else.
614 * This does not work with elements that contain text. Any necessary text
615 * must be added after the wrapping is done.
617 * @example $("p").wrap("<div class='wrap'></div>");
618 * @before <p>Test Paragraph.</p>
619 * @result <div class='wrap'><p>Test Paragraph.</p></div>
623 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
624 * @cat DOM/Manipulation
628 * Wrap all matched elements with a structure of other elements.
629 * This wrapping process is most useful for injecting additional
630 * stucture into a document, without ruining the original semantic
631 * qualities of a document.
633 * This works by going through the first element
634 * provided and finding the deepest ancestor element within its
635 * structure - it is that element that will en-wrap everything else.
637 * This does not work with elements that contain text. Any necessary text
638 * must be added after the wrapping is done.
640 * @example $("p").wrap( document.getElementById('content') );
641 * @before <p>Test Paragraph.</p><div id="content"></div>
642 * @result <div id="content"><p>Test Paragraph.</p></div>
646 * @param Element elem A DOM element that will be wrapped around the target.
647 * @cat DOM/Manipulation
649 wrapAll: function(html) {
651 // The elements to wrap the target around
652 jQuery(html, this[0].ownerDocument)
654 .insertBefore(this[0])
657 while ( elem.firstChild )
658 elem = elem.firstChild;
666 wrapInner: function(html) {
667 return this.each(function(){
668 jQuery(this).contents().wrapAll(html);
672 wrap: function(html) {
673 return this.each(function(){
674 jQuery(this).wrapAll(html);
679 * Append content to the inside of every matched element.
681 * This operation is similar to doing an appendChild to all the
682 * specified elements, adding them into the document.
684 * @example $("p").append("<b>Hello</b>");
685 * @before <p>I would like to say: </p>
686 * @result <p>I would like to say: <b>Hello</b></p>
687 * @desc Appends some HTML to all paragraphs.
689 * @example $("p").append( $("#foo")[0] );
690 * @before <p>I would like to say: </p><b id="foo">Hello</b>
691 * @result <p>I would like to say: <b id="foo">Hello</b></p>
692 * @desc Appends an Element to all paragraphs.
694 * @example $("p").append( $("b") );
695 * @before <p>I would like to say: </p><b>Hello</b>
696 * @result <p>I would like to say: <b>Hello</b></p>
697 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
701 * @param <Content> content Content to append to the target
702 * @cat DOM/Manipulation
703 * @see prepend(<Content>)
704 * @see before(<Content>)
705 * @see after(<Content>)
708 return this.domManip(arguments, true, 1, function(a){
709 this.appendChild( a );
714 * Prepend content to the inside of every matched element.
716 * This operation is the best way to insert elements
717 * inside, at the beginning, of all matched elements.
719 * @example $("p").prepend("<b>Hello</b>");
720 * @before <p>I would like to say: </p>
721 * @result <p><b>Hello</b>I would like to say: </p>
722 * @desc Prepends some HTML to all paragraphs.
724 * @example $("p").prepend( $("#foo")[0] );
725 * @before <p>I would like to say: </p><b id="foo">Hello</b>
726 * @result <p><b id="foo">Hello</b>I would like to say: </p>
727 * @desc Prepends an Element to all paragraphs.
729 * @example $("p").prepend( $("b") );
730 * @before <p>I would like to say: </p><b>Hello</b>
731 * @result <p><b>Hello</b>I would like to say: </p>
732 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
736 * @param <Content> content Content to prepend to the target.
737 * @cat DOM/Manipulation
738 * @see append(<Content>)
739 * @see before(<Content>)
740 * @see after(<Content>)
742 prepend: function() {
743 return this.domManip(arguments, true, -1, function(a){
744 this.insertBefore( a, this.firstChild );
749 * Insert content before each of the matched elements.
751 * @example $("p").before("<b>Hello</b>");
752 * @before <p>I would like to say: </p>
753 * @result <b>Hello</b><p>I would like to say: </p>
754 * @desc Inserts some HTML before all paragraphs.
756 * @example $("p").before( $("#foo")[0] );
757 * @before <p>I would like to say: </p><b id="foo">Hello</b>
758 * @result <b id="foo">Hello</b><p>I would like to say: </p>
759 * @desc Inserts an Element before all paragraphs.
761 * @example $("p").before( $("b") );
762 * @before <p>I would like to say: </p><b>Hello</b>
763 * @result <b>Hello</b><p>I would like to say: </p>
764 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
768 * @param <Content> content Content to insert before each target.
769 * @cat DOM/Manipulation
770 * @see append(<Content>)
771 * @see prepend(<Content>)
772 * @see after(<Content>)
775 return this.domManip(arguments, false, 1, function(a){
776 this.parentNode.insertBefore( a, this );
781 * Insert content after each of the matched elements.
783 * @example $("p").after("<b>Hello</b>");
784 * @before <p>I would like to say: </p>
785 * @result <p>I would like to say: </p><b>Hello</b>
786 * @desc Inserts some HTML after all paragraphs.
788 * @example $("p").after( $("#foo")[0] );
789 * @before <b id="foo">Hello</b><p>I would like to say: </p>
790 * @result <p>I would like to say: </p><b id="foo">Hello</b>
791 * @desc Inserts an Element after all paragraphs.
793 * @example $("p").after( $("b") );
794 * @before <b>Hello</b><p>I would like to say: </p>
795 * @result <p>I would like to say: </p><b>Hello</b>
796 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
800 * @param <Content> content Content to insert after each target.
801 * @cat DOM/Manipulation
802 * @see append(<Content>)
803 * @see prepend(<Content>)
804 * @see before(<Content>)
807 return this.domManip(arguments, false, -1, function(a){
808 this.parentNode.insertBefore( a, this.nextSibling );
813 * Revert the most recent 'destructive' operation, changing the set of matched elements
814 * to its previous state (right before the destructive operation).
816 * If there was no destructive operation before, an empty set is returned.
818 * A 'destructive' operation is any operation that changes the set of
819 * matched jQuery elements. These functions are: <code>add</code>,
820 * <code>children</code>, <code>clone</code>, <code>filter</code>,
821 * <code>find</code>, <code>not</code>, <code>next</code>,
822 * <code>parent</code>, <code>parents</code>, <code>prev</code> and <code>siblings</code>.
824 * @example $("p").find("span").end();
825 * @before <p><span>Hello</span>, how are you?</p>
826 * @result [ <p>...</p> ]
827 * @desc Selects all paragraphs, finds span elements inside these, and reverts the
828 * selection back to the paragraphs.
832 * @cat DOM/Traversing
835 return this.prevObject || jQuery([]);
839 * Searches for all elements that match the specified expression.
841 * This method is a good way to find additional descendant
842 * elements with which to process.
844 * All searching is done using a jQuery expression. The expression can be
845 * written using CSS 1-3 Selector syntax, or basic XPath.
847 * @example $("p").find("span");
848 * @before <p><span>Hello</span>, how are you?</p>
849 * @result [ <span>Hello</span> ]
850 * @desc Starts with all paragraphs and searches for descendant span
851 * elements, same as $("p span")
855 * @param String expr An expression to search with.
856 * @cat DOM/Traversing
859 var data = jQuery.map(this, function(a){ return jQuery.find(t,a); });
860 return this.pushStack( /[^+>] [^+>]/.test( t ) || t.indexOf("..") > -1 ?
861 jQuery.unique( data ) : data );
865 * Clone matched DOM Elements and select the clones.
867 * This is useful for moving copies of the elements to another
868 * location in the DOM.
870 * @example $("b").clone().prependTo("p");
871 * @before <b>Hello</b><p>, how are you?</p>
872 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
873 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
877 * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
878 * @cat DOM/Manipulation
880 clone: function(deep) {
881 deep = deep != undefined ? deep : true;
882 var $this = this.add(this.find("*"));
883 if (jQuery.browser.msie) {
884 // Need to remove events on the element and its descendants
885 $this.each(function() {
887 for (var type in this.$events)
888 this._$events[type] = jQuery.extend({},this.$events[type]);
893 var r = this.pushStack( jQuery.map( this, function(a){
894 return a.cloneNode( deep );
897 if (jQuery.browser.msie) {
898 $this.each(function() {
899 // Add the events back to the original and its descendants
900 var events = this._$events;
901 for (var type in events)
902 for (var handler in events[type])
903 jQuery.event.add(this, type, events[type][handler], events[type][handler].data);
904 this._$events = null;
908 // copy form values over
910 var inputs = r.add(r.find('*')).filter('select,input[@type=checkbox]');
911 $this.filter('select,input[@type=checkbox]').each(function(i) {
912 if (this.selectedIndex)
913 inputs[i].selectedIndex = this.selectedIndex;
915 inputs[i].checked = true;
919 // Return the cloned set
924 * Removes all elements from the set of matched elements that do not
925 * match the specified expression(s). This method is used to narrow down
926 * the results of a search.
928 * Provide a comma-separated list of expressions to apply multiple filters at once.
930 * @example $("p").filter(".selected")
931 * @before <p class="selected">Hello</p><p>How are you?</p>
932 * @result [ <p class="selected">Hello</p> ]
933 * @desc Selects all paragraphs and removes those without a class "selected".
935 * @example $("p").filter(".selected, :first")
936 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
937 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
938 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
942 * @param String expression Expression(s) to search with.
943 * @cat DOM/Traversing
947 * Removes all elements from the set of matched elements that do not
948 * pass the specified filter. This method is used to narrow down
949 * the results of a search.
951 * @example $("p").filter(function(index) {
952 * return $("ol", this).length == 0;
954 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
955 * @result [ <p>How are you?</p> ]
956 * @desc Remove all elements that have a child ol element
960 * @param Function filter A function to use for filtering
961 * @cat DOM/Traversing
963 filter: function(t) {
964 return this.pushStack(
965 jQuery.isFunction( t ) &&
966 jQuery.grep(this, function(el, index){
967 return t.apply(el, [index]);
970 jQuery.multiFilter(t,this) );
974 * Removes the specified Element from the set of matched elements. This
975 * method is used to remove a single Element from a jQuery object.
977 * @example $("p").not( $("#selected")[0] )
978 * @before <p>Hello</p><p id="selected">Hello Again</p>
979 * @result [ <p>Hello</p> ]
980 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
984 * @param Element el An element to remove from the set
985 * @cat DOM/Traversing
989 * Removes elements matching the specified expression from the set
990 * of matched elements. This method is used to remove one or more
991 * elements from a jQuery object.
993 * @example $("p").not("#selected")
994 * @before <p>Hello</p><p id="selected">Hello Again</p>
995 * @result [ <p>Hello</p> ]
996 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
1000 * @param String expr An expression with which to remove matching elements
1001 * @cat DOM/Traversing
1005 * Removes any elements inside the array of elements from the set
1006 * of matched elements. This method is used to remove one or more
1007 * elements from a jQuery object.
1009 * Please note: the expression cannot use a reference to the
1010 * element name. See the two examples below.
1012 * @example $("p").not( $("div p.selected") )
1013 * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
1014 * @result [ <p>Hello</p> ]
1015 * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
1019 * @param jQuery elems A set of elements to remove from the jQuery set of matched elements.
1020 * @cat DOM/Traversing
1023 return this.pushStack(
1024 t.constructor == String &&
1025 jQuery.multiFilter(t, this, true) ||
1027 jQuery.grep(this, function(a) {
1028 return ( t.constructor == Array || t.jquery )
1029 ? jQuery.inArray( a, t ) < 0
1036 * Adds more elements, matched by the given expression,
1037 * to the set of matched elements.
1039 * @example $("p").add("span")
1040 * @before (HTML) <p>Hello</p><span>Hello Again</span>
1041 * @result (jQuery object matching 2 elements) [ <p>Hello</p>, <span>Hello Again</span> ]
1042 * @desc Compare the above result to the result of <code>$('p')</code>,
1043 * which would just result in <code><nowiki>[ <p>Hello</p> ]</nowiki></code>.
1044 * Using add(), matched elements of <code>$('span')</code> are simply
1045 * added to the returned jQuery-object.
1049 * @param String expr An expression whose matched elements are added
1050 * @cat DOM/Traversing
1054 * Adds more elements, created on the fly, to the set of
1057 * @example $("p").add("<span>Again</span>")
1058 * @before <p>Hello</p>
1059 * @result [ <p>Hello</p>, <span>Again</span> ]
1063 * @param String html A string of HTML to create on the fly.
1064 * @cat DOM/Traversing
1068 * Adds one or more Elements to the set of matched elements.
1070 * @example $("p").add( document.getElementById("a") )
1071 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1072 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1074 * @example $("p").add( document.forms[0].elements )
1075 * @before <p>Hello</p><p><form><input/><button/></form>
1076 * @result [ <p>Hello</p>, <input/>, <button/> ]
1080 * @param Element|Array<Element> elements One or more Elements to add
1081 * @cat DOM/Traversing
1084 return this.pushStack( jQuery.merge(
1086 t.constructor == String ?
1088 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
1094 * Checks the current selection against an expression and returns true,
1095 * if at least one element of the selection fits the given expression.
1097 * Does return false, if no element fits or the expression is not valid.
1099 * filter(String) is used internally, therefore all rules that apply there
1102 * @example $("input[@type='checkbox']").parent().is("form")
1103 * @before <form><input type="checkbox" /></form>
1105 * @desc Returns true, because the parent of the input is a form element
1107 * @example $("input[@type='checkbox']").parent().is("form")
1108 * @before <form><p><input type="checkbox" /></p></form>
1110 * @desc Returns false, because the parent of the input is a p element
1114 * @param String expr The expression with which to filter
1115 * @cat DOM/Traversing
1117 is: function(expr) {
1118 return expr ? jQuery.multiFilter(expr,this).length > 0 : false;
1122 * Get the content of the value attribute of the first matched element.
1124 * Use caution when relying on this function to check the value of
1125 * multiple-select elements and checkboxes in a form. While it will
1126 * still work as intended, it may not accurately represent the value
1127 * the server will receive because these elements may send an array
1128 * of values. For more robust handling of field values, see the
1129 * [http://www.malsup.com/jquery/form/#fields fieldValue function of the Form Plugin].
1131 * @example $("input").val();
1132 * @before <input type="text" value="some text"/>
1133 * @result "some text"
1137 * @cat DOM/Attributes
1141 * Set the value attribute of every matched element.
1143 * @example $("input").val("test");
1144 * @before <input type="text" value="some text"/>
1145 * @result <input type="text" value="test"/>
1149 * @param String val Set the property to the specified value.
1150 * @cat DOM/Attributes
1152 val: function( val ) {
1153 return val == undefined ?
1154 ( this.length ? this[0].value : null ) :
1155 this.attr( "value", val );
1159 * Get the html contents of the first matched element.
1160 * This property is not available on XML documents.
1162 * @example $("div").html();
1163 * @before <div><input/></div>
1168 * @cat DOM/Attributes
1172 * Set the html contents of every matched element.
1173 * This property is not available on XML documents.
1175 * @example $("div").html("<b>new stuff</b>");
1176 * @before <div><input/></div>
1177 * @result <div><b>new stuff</b></div>
1181 * @param String val Set the html contents to the specified value.
1182 * @cat DOM/Attributes
1184 html: function( val ) {
1185 return val == undefined ?
1186 ( this.length ? this[0].innerHTML : null ) :
1187 this.empty().append( val );
1190 replaceWith: function( val ) {
1191 return this.after( val ).remove();
1195 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
1199 return this.pushStack(jQuery.map( this, function(elem,i){
1200 return fn.call( elem, i, elem );
1208 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1209 * @param Number dir If dir<0, process args in reverse order.
1210 * @param Function fn The function doing the DOM manipulation.
1214 domManip: function(args, table, dir, fn){
1215 var clone = this.length > 1, a;
1217 return this.each(function(){
1219 a = jQuery.clean(args, this.ownerDocument);
1226 if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
1227 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1229 jQuery.each( a, function(){
1230 if ( jQuery.nodeName(this, "script") ) {
1232 jQuery.ajax({ url: this.src, async: false, dataType: "script" });
1234 jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
1236 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
1243 * Extends the jQuery object itself. Can be used to add functions into
1244 * the jQuery namespace and to [[Plugins/Authoring|add plugin methods]] (plugins).
1246 * @example jQuery.fn.extend({
1247 * check: function() {
1248 * return this.each(function() { this.checked = true; });
1250 * uncheck: function() {
1251 * return this.each(function() { this.checked = false; });
1254 * $("input[@type=checkbox]").check();
1255 * $("input[@type=radio]").uncheck();
1256 * @desc Adds two plugin methods.
1258 * @example jQuery.extend({
1259 * min: function(a, b) { return a < b ? a : b; },
1260 * max: function(a, b) { return a > b ? a : b; }
1262 * @desc Adds two functions into the jQuery namespace
1265 * @param Object prop The object that will be merged into the jQuery object
1271 * Extend one object with one or more others, returning the original,
1272 * modified, object. This is a great utility for simple inheritance.
1274 * @example var settings = { validate: false, limit: 5, name: "foo" };
1275 * var options = { validate: true, name: "bar" };
1276 * jQuery.extend(settings, options);
1277 * @result settings == { validate: true, limit: 5, name: "bar" }
1278 * @desc Merge settings and options, modifying settings
1280 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1281 * var options = { validate: true, name: "bar" };
1282 * var settings = jQuery.extend({}, defaults, options);
1283 * @result settings == { validate: true, limit: 5, name: "bar" }
1284 * @desc Merge defaults and options, without modifying the defaults
1287 * @param Object target The object to extend
1288 * @param Object prop1 The object that will be merged into the first.
1289 * @param Object propN (optional) More objects to merge into the first
1293 jQuery.extend = jQuery.fn.extend = function() {
1294 // copy reference to target object
1295 var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;
1297 // Handle a deep copy situation
1298 if ( target.constructor == Boolean ) {
1300 target = arguments[1] || {};
1303 // extend jQuery itself if only one argument is passed
1311 for ( ; a < al; a++ )
1312 // Only deal with non-null/undefined values
1313 if ( (prop = arguments[a]) != null )
1314 // Extend the base object
1315 for ( var i in prop ) {
1316 // Prevent never-ending loop
1317 if ( target == prop[i] )
1320 // Recurse if we're merging object values
1321 if ( deep && typeof prop[i] == 'object' && target[i] )
1322 jQuery.extend( target[i], prop[i] );
1324 // Don't bring in undefined values
1325 else if ( prop[i] != undefined )
1326 target[i] = prop[i];
1329 // Return the modified object
1335 * Run this function to give control of the $ variable back
1336 * to whichever library first implemented it. This helps to make
1337 * sure that jQuery doesn't conflict with the $ object
1338 * of other libraries.
1340 * By using this function, you will only be able to access jQuery
1341 * using the 'jQuery' variable. For example, where you used to do
1342 * $("div p"), you now must do jQuery("div p").
1344 * @example jQuery.noConflict();
1345 * // Do something with jQuery
1346 * jQuery("div p").hide();
1347 * // Do something with another library's $()
1348 * $("content").style.display = 'none';
1349 * @desc Maps the original object that was referenced by $ back to $
1351 * @example jQuery.noConflict();
1354 * // more code using $ as alias to jQuery
1357 * // other code using $ as an alias to the other library
1358 * @desc Reverts the $ alias and then creates and executes a
1359 * function to provide the $ as a jQuery alias inside the functions
1360 * scope. Inside the function the original $ object is not available.
1361 * This works well for most plugins that don't rely on any other library.
1364 * @name $.noConflict
1368 noConflict: function(deep) {
1371 window.jQuery = _jQuery;
1375 // This may seem like some crazy code, but trust me when I say that this
1376 // is the only cross-browser way to do this. --John
1377 isFunction: function( fn ) {
1378 return !!fn && typeof fn != "string" && !fn.nodeName &&
1379 fn.constructor != Array && /function/i.test( fn + "" );
1382 // check if an element is in a XML document
1383 isXMLDoc: function(elem) {
1384 return elem.documentElement && !elem.body ||
1385 elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
1388 // Evalulates a script in a global context
1389 // Evaluates Async. in Safari 2 :-(
1390 globalEval: function( data ) {
1391 data = jQuery.trim( data );
1393 if ( window.execScript )
1394 window.execScript( data );
1395 else if ( jQuery.browser.safari )
1396 // safari doesn't provide a synchronous global eval
1397 window.setTimeout( data, 0 );
1399 eval.call( window, data );
1403 nodeName: function( elem, name ) {
1404 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
1408 * A generic iterator function, which can be used to seamlessly
1409 * iterate over both objects and arrays. This function is not the same
1410 * as $().each() - which is used to iterate, exclusively, over a jQuery
1411 * object. This function can be used to iterate over anything.
1413 * The callback has two arguments:the key (objects) or index (arrays) as first
1414 * the first, and the value as the second.
1416 * @example $.each( [0,1,2], function(i, n){
1417 * alert( "Item #" + i + ": " + n );
1419 * @desc This is an example of iterating over the items in an array,
1420 * accessing both the current item and its index.
1422 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1423 * alert( "Name: " + i + ", Value: " + n );
1426 * @desc This is an example of iterating over the properties in an
1427 * Object, accessing both the current item and its key.
1430 * @param Object obj The object, or array, to iterate over.
1431 * @param Function fn The function that will be executed on every object.
1435 // args is for internal usage only
1436 each: function( obj, fn, args ) {
1438 if ( obj.length == undefined )
1439 for ( var i in obj )
1440 fn.apply( obj[i], args );
1442 for ( var i = 0, ol = obj.length; i < ol; i++ )
1443 if ( fn.apply( obj[i], args ) === false ) break;
1445 // A special, fast, case for the most common use of each
1447 if ( obj.length == undefined )
1448 for ( var i in obj )
1449 fn.call( obj[i], i, obj[i] );
1451 for ( var i = 0, ol = obj.length, val = obj[0];
1452 i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){}
1458 prop: function(elem, value, type, index, prop){
1459 // Handle executable functions
1460 if ( jQuery.isFunction( value ) )
1461 value = value.call( elem, [index] );
1463 // exclude the following css properties to add px
1464 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
1466 // Handle passing in a number to a CSS property
1467 return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
1473 // internal only, use addClass("class")
1474 add: function( elem, c ){
1475 jQuery.each( (c || "").split(/\s+/), function(i, cur){
1476 if ( !jQuery.className.has( elem.className, cur ) )
1477 elem.className += ( elem.className ? " " : "" ) + cur;
1481 // internal only, use removeClass("class")
1482 remove: function( elem, c ){
1483 elem.className = c != undefined ?
1484 jQuery.grep( elem.className.split(/\s+/), function(cur){
1485 return !jQuery.className.has( c, cur );
1489 // internal only, use is(".class")
1490 has: function( t, c ) {
1491 return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1;
1496 * Swap in/out style options.
1499 swap: function(e,o,f) {
1500 for ( var i in o ) {
1501 e.style["old"+i] = e.style[i];
1506 e.style[i] = e.style["old"+i];
1509 css: function(e,p) {
1510 if ( p == "height" || p == "width" ) {
1511 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1513 jQuery.each( d, function(){
1514 old["padding" + this] = 0;
1515 old["border" + this + "Width"] = 0;
1518 jQuery.swap( e, old, function() {
1519 if ( jQuery(e).is(':visible') ) {
1520 oHeight = e.offsetHeight;
1521 oWidth = e.offsetWidth;
1523 e = jQuery(e.cloneNode(true))
1524 .find(":radio").removeAttr("checked").end()
1526 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1527 }).appendTo(e.parentNode)[0];
1529 var parPos = jQuery.css(e.parentNode,"position") || "static";
1530 if ( parPos == "static" )
1531 e.parentNode.style.position = "relative";
1533 oHeight = e.clientHeight;
1534 oWidth = e.clientWidth;
1536 if ( parPos == "static" )
1537 e.parentNode.style.position = "static";
1539 e.parentNode.removeChild(e);
1543 return p == "height" ? oHeight : oWidth;
1546 return jQuery.curCSS( e, p );
1549 curCSS: function(elem, prop, force) {
1550 var ret, stack = [], swap = [];
1552 // A helper method for determining if an element's values are broken
1554 if ( !jQuery.browser.safari )
1557 var ret = document.defaultView.getComputedStyle(a,null);
1558 return !ret || ret.getPropertyValue("color") == "";
1561 if (prop == "opacity" && jQuery.browser.msie) {
1562 ret = jQuery.attr(elem.style, "opacity");
1563 return ret == "" ? "1" : ret;
1566 if (prop.match(/float/i))
1569 if (!force && elem.style[prop])
1570 ret = elem.style[prop];
1572 else if (document.defaultView && document.defaultView.getComputedStyle) {
1574 if (prop.match(/float/i))
1577 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1578 var cur = document.defaultView.getComputedStyle(elem, null);
1580 if ( cur && !color(elem) )
1581 ret = cur.getPropertyValue(prop);
1583 // If the element isn't reporting its values properly in Safari
1584 // then some display: none elements are involved
1586 // Locate all of the parent display: none elements
1587 for ( var a = elem; a && color(a); a = a.parentNode )
1590 // Go through and make them visible, but in reverse
1591 // (It would be better if we knew the exact display type that they had)
1592 for ( a = 0; a < stack.length; a++ )
1593 if ( color(stack[a]) ) {
1594 swap[a] = stack[a].style.display;
1595 stack[a].style.display = "block";
1598 // Since we flip the display style, we have to handle that
1599 // one special, otherwise get the value
1600 ret = prop == "display" && swap[stack.length-1] != null ?
1602 document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop) || "";
1604 // Finally, revert the display styles back
1605 for ( a = 0; a < swap.length; a++ )
1606 if ( swap[a] != null )
1607 stack[a].style.display = swap[a];
1610 if ( prop == "opacity" && ret == "" )
1613 } else if (elem.currentStyle) {
1614 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1615 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1621 clean: function(a, doc) {
1623 doc = doc || document;
1625 jQuery.each( a, function(i,arg){
1628 if ( arg.constructor == Number )
1629 arg = arg.toString();
1631 // Convert html string into DOM nodes
1632 if ( typeof arg == "string" ) {
1633 // Trim whitespace, otherwise indexOf won't work as expected
1634 var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = [];
1637 // option or optgroup
1638 !s.indexOf("<opt") &&
1639 [1, "<select>", "</select>"] ||
1641 !s.indexOf("<leg") &&
1642 [1, "<fieldset>", "</fieldset>"] ||
1644 s.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
1645 [1, "<table>", "</table>"] ||
1647 !s.indexOf("<tr") &&
1648 [2, "<table><tbody>", "</tbody></table>"] ||
1650 // <thead> matched above
1651 (!s.indexOf("<td") || !s.indexOf("<th")) &&
1652 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1654 !s.indexOf("<col") &&
1655 [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"] ||
1657 // IE can't serialize <link> and <script> tags normally
1658 jQuery.browser.msie &&
1659 [1, "div<div>", "</div>"] ||
1663 // Go to html and back, then peel off extra wrappers
1664 div.innerHTML = wrap[1] + arg + wrap[2];
1666 // Move to the right depth
1668 div = div.lastChild;
1670 // Remove IE's autoinserted <tbody> from table fragments
1671 if ( jQuery.browser.msie ) {
1673 // String was a <table>, *may* have spurious <tbody>
1674 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
1675 tb = div.firstChild && div.firstChild.childNodes;
1677 // String was a bare <thead> or <tfoot>
1678 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1679 tb = div.childNodes;
1681 for ( var n = tb.length-1; n >= 0 ; --n )
1682 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
1683 tb[n].parentNode.removeChild(tb[n]);
1685 // IE completely kills leading whitespace when innerHTML is used
1686 if ( /^\s/.test(arg) )
1687 div.insertBefore( doc.createTextNode( arg.match(/^\s*/)[0] ), div.firstChild );
1691 arg = jQuery.makeArray( div.childNodes );
1694 if ( 0 === arg.length && (!jQuery.nodeName(arg, "form") && !jQuery.nodeName(arg, "select")) )
1697 if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options )
1700 r = jQuery.merge( r, arg );
1707 attr: function(elem, name, value){
1708 var fix = jQuery.isXMLDoc(elem) ? {} : jQuery.props;
1710 // Safari mis-reports the default selected property of a hidden option
1711 // Accessing the parent's selectedIndex property fixes it
1712 if ( name == "selected" && jQuery.browser.safari )
1713 elem.parentNode.selectedIndex;
1715 // Certain attributes only work when accessed via the old DOM 0 way
1717 if ( value != undefined ) elem[fix[name]] = value;
1718 return elem[fix[name]];
1719 } else if ( jQuery.browser.msie && name == "style" )
1720 return jQuery.attr( elem.style, "cssText", value );
1722 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
1723 return elem.getAttributeNode(name).nodeValue;
1725 // IE elem.getAttribute passes even for style
1726 else if ( elem.tagName ) {
1728 if ( value != undefined ) elem.setAttribute( name, value );
1729 if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) )
1730 return elem.getAttribute( name, 2 );
1731 return elem.getAttribute( name );
1733 // elem is actually elem.style ... set the style
1735 // IE actually uses filters for opacity
1736 if ( name == "opacity" && jQuery.browser.msie ) {
1737 if ( value != undefined ) {
1738 // IE has trouble with opacity if it does not have layout
1739 // Force it by setting the zoom level
1742 // Set the alpha filter to set the opacity
1743 elem.filter = (elem.filter || "").replace(/alpha\([^)]*\)/,"") +
1744 (parseFloat(value).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1747 return elem.filter ?
1748 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : "";
1750 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1751 if ( value != undefined ) elem[name] = value;
1757 * Remove the whitespace from the beginning and end of a string.
1759 * @example $.trim(" hello, how are you? ");
1760 * @result "hello, how are you?"
1764 * @param String str The string to trim.
1768 return (t||"").replace(/^\s+|\s+$/g, "");
1771 makeArray: function( a ) {
1774 // Need to use typeof to fight Safari childNodes crashes
1775 if ( typeof a != "array" )
1776 for ( var i = 0, al = a.length; i < al; i++ )
1784 inArray: function( b, a ) {
1785 for ( var i = 0, al = a.length; i < al; i++ )
1792 * Merge two arrays together by concatenating them.
1794 * @example $.merge( [0,1,2], [2,3,4] )
1795 * @result [0,1,2,2,3,4]
1796 * @desc Merges two arrays.
1800 * @param Array first The first array to merge, the elements of second are added.
1801 * @param Array second The second array to append to the first, unaltered.
1804 merge: function(first, second) {
1805 // We have to loop this way because IE & Opera overwrite the length
1806 // expando of getElementsByTagName
1808 // Also, we need to make sure that the correct elements are being returned
1809 // (IE returns comment nodes in a '*' query)
1810 if ( jQuery.browser.msie ) {
1811 for ( var i = 0; second[i]; i++ )
1812 if ( second[i].nodeType != 8 )
1813 first.push(second[i]);
1815 for ( var i = 0; second[i]; i++ )
1816 first.push(second[i]);
1822 * Reduce an array (of jQuery objects only) to its unique elements.
1824 * @example $.unique( [x1, x2, x3, x2, x3] )
1825 * @result [x1, x2, x3]
1826 * @desc Reduces the arrays of jQuery objects to unique elements by removing the duplicates of x2 and x3
1830 * @param Array array The array to reduce to its unique jQuery objects.
1833 unique: function(first) {
1834 var r = [], num = jQuery.mergeNum++;
1837 for ( var i = 0, fl = first.length; i < fl; i++ )
1838 if ( num != first[i].mergeNum ) {
1839 first[i].mergeNum = num;
1852 * Filter items out of an array, by using a filter function.
1854 * The specified function will be passed two arguments: The
1855 * current array item and the index of the item in the array. The
1856 * function must return 'true' to keep the item in the array,
1857 * false to remove it.
1859 * @example $.grep( [0,1,2], function(i){
1866 * @param Array array The Array to find items in.
1867 * @param Function fn The function to process each item against.
1868 * @param Boolean inv Invert the selection - select the opposite of the function.
1871 grep: function(elems, fn, inv) {
1872 // If a string is passed in for the function, make a function
1873 // for it (a handy shortcut)
1874 if ( typeof fn == "string" )
1875 fn = eval("false||function(a,i){return " + fn + "}");
1879 // Go through the array, only saving the items
1880 // that pass the validator function
1881 for ( var i = 0, el = elems.length; i < el; i++ )
1882 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1883 result.push( elems[i] );
1889 * Translate all items in an array to another array of items.
1891 * The translation function that is provided to this method is
1892 * called for each item in the array and is passed one argument:
1893 * The item to be translated.
1895 * The function can then return the translated value, 'null'
1896 * (to remove the item), or an array of values - which will
1897 * be flattened into the full array.
1899 * @example $.map( [0,1,2], function(i){
1903 * @desc Maps the original array to a new one and adds 4 to each value.
1905 * @example $.map( [0,1,2], function(i){
1906 * return i > 0 ? i + 1 : null;
1909 * @desc Maps the original array to a new one and adds 1 to each
1910 * value if it is bigger then zero, otherwise it's removed-
1912 * @example $.map( [0,1,2], function(i){
1913 * return [ i, i + 1 ];
1915 * @result [0, 1, 1, 2, 2, 3]
1916 * @desc Maps the original array to a new one, each element is added
1917 * with it's original value and the value plus one.
1921 * @param Array array The Array to translate.
1922 * @param Function fn The function to process each item against.
1925 map: function(elems, fn) {
1926 // If a string is passed in for the function, make a function
1927 // for it (a handy shortcut)
1928 if ( typeof fn == "string" )
1929 fn = eval("false||function(a){return " + fn + "}");
1933 // Go through the array, translating each of the items to their
1934 // new value (or values).
1935 for ( var i = 0, el = elems.length; i < el; i++ ) {
1936 var val = fn(elems[i],i);
1938 if ( val !== null && val != undefined ) {
1939 if ( val.constructor != Array ) val = [val];
1940 result = result.concat( val );
1949 * Contains flags for the useragent, read from navigator.userAgent.
1950 * Available flags are: safari, opera, msie, mozilla
1952 * This property is available before the DOM is ready, therefore you can
1953 * use it to add ready events only for certain browsers.
1955 * There are situations where object detections is not reliable enough, in that
1956 * cases it makes sense to use browser detection. Simply try to avoid both!
1958 * A combination of browser and object detection yields quite reliable results.
1960 * @example $.browser.msie
1961 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1963 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1964 * @desc Alerts "this is safari!" only for safari browsers
1973 * Whether the W3C compliant box model is being used.
1980 var userAgent = navigator.userAgent.toLowerCase();
1982 // Figure out what browser is being used
1984 version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
1985 safari: /webkit/.test(userAgent),
1986 opera: /opera/.test(userAgent),
1987 msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
1988 mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
1991 var styleFloat = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1994 // Check to see if the W3C box model is being used
1995 boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
1997 styleFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
2001 "class": "className",
2002 "float": styleFloat,
2003 cssFloat: styleFloat,
2004 styleFloat: styleFloat,
2005 innerHTML: "innerHTML",
2006 className: "className",
2008 disabled: "disabled",
2010 readonly: "readOnly",
2011 selected: "selected",
2012 maxlength: "maxLength"
2017 * Get a set of elements containing the unique parents of the matched
2020 * You may use an optional expression to filter the set of parent elements that will match.
2022 * @example $("p").parent()
2023 * @before <div><p>Hello</p><p>Hello</p></div>
2024 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2025 * @desc Find the parent element of each paragraph.
2027 * @example $("p").parent(".selected")
2028 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2029 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2030 * @desc Find the parent element of each paragraph with a class "selected".
2034 * @param String expr (optional) An expression to filter the parents with
2035 * @cat DOM/Traversing
2039 * Get a set of elements containing the unique ancestors of the matched
2040 * set of elements (except for the root element).
2042 * The matched elements can be filtered with an optional expression.
2044 * @example $("span").parents()
2045 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2046 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2047 * @desc Find all parent elements of each span.
2049 * @example $("span").parents("p")
2050 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2051 * @result [ <p><span>Hello</span></p> ]
2052 * @desc Find all parent elements of each span that is a paragraph.
2056 * @param String expr (optional) An expression to filter the ancestors with
2057 * @cat DOM/Traversing
2061 * Get a set of elements containing the unique next siblings of each of the
2062 * matched set of elements.
2064 * It only returns the very next sibling for each element, not all
2067 * You may provide an optional expression to filter the match.
2069 * @example $("p").next()
2070 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2071 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2072 * @desc Find the very next sibling of each paragraph.
2074 * @example $("p").next(".selected")
2075 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2076 * @result [ <p class="selected">Hello Again</p> ]
2077 * @desc Find the very next sibling of each paragraph that has a class "selected".
2081 * @param String expr (optional) An expression to filter the next Elements with
2082 * @cat DOM/Traversing
2086 * Get a set of elements containing the unique previous siblings of each of the
2087 * matched set of elements.
2089 * Use an optional expression to filter the matched set.
2091 * Only the immediately previous sibling is returned, not all previous siblings.
2093 * @example $("p").prev()
2094 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2095 * @result [ <div><span>Hello Again</span></div> ]
2096 * @desc Find the very previous sibling of each paragraph.
2098 * @example $("p").prev(".selected")
2099 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2100 * @result [ <div><span>Hello</span></div> ]
2101 * @desc Find the very previous sibling of each paragraph that has a class "selected".
2105 * @param String expr (optional) An expression to filter the previous Elements with
2106 * @cat DOM/Traversing
2110 * Get a set of elements containing all of the unique siblings of each of the
2111 * matched set of elements.
2113 * Can be filtered with an optional expressions.
2115 * @example $("div").siblings()
2116 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2117 * @result [ <p>Hello</p>, <p>And Again</p> ]
2118 * @desc Find all siblings of each div.
2120 * @example $("div").siblings(".selected")
2121 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2122 * @result [ <p class="selected">Hello Again</p> ]
2123 * @desc Find all siblings with a class "selected" of each div.
2127 * @param String expr (optional) An expression to filter the sibling Elements with
2128 * @cat DOM/Traversing
2132 * Get a set of elements containing all of the unique children of each of the
2133 * matched set of elements.
2135 * This set can be filtered with an optional expression that will cause
2136 * only elements matching the selector to be collected.
2138 * @example $("div").children()
2139 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2140 * @result [ <span>Hello Again</span> ]
2141 * @desc Find all children of each div.
2143 * @example $("div").children(".selected")
2144 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2145 * @result [ <p class="selected">Hello Again</p> ]
2146 * @desc Find all children with a class "selected" of each div.
2150 * @param String expr (optional) An expression to filter the child Elements with
2151 * @cat DOM/Traversing
2154 parent: "a.parentNode",
2155 parents: "jQuery.parents(a)",
2156 next: "jQuery.nth(a,2,'nextSibling')",
2157 prev: "jQuery.nth(a,2,'previousSibling')",
2158 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
2159 children: "jQuery.sibling(a.firstChild)",
2160 contents: "jQuery.nodeName(a,'iframe')?a.contentDocument||a.contentWindow.document:jQuery.makeArray(a.childNodes)"
2162 jQuery.fn[ i ] = function(a) {
2163 var ret = jQuery.map(this,n);
2164 if ( a && typeof a == "string" )
2165 ret = jQuery.multiFilter(a,ret);
2166 return this.pushStack( jQuery.unique(ret) );
2171 * Append all of the matched elements to another, specified, set of elements.
2172 * This operation is, essentially, the reverse of doing a regular
2173 * $(A).append(B), in that instead of appending B to A, you're appending
2176 * @example $("p").appendTo("#foo");
2177 * @before <p>I would like to say: </p><div id="foo"></div>
2178 * @result <div id="foo"><p>I would like to say: </p></div>
2179 * @desc Appends all paragraphs to the element with the ID "foo"
2183 * @param <Content> content Content to append to the selected element to.
2184 * @cat DOM/Manipulation
2185 * @see append(<Content>)
2189 * Prepend all of the matched elements to another, specified, set of elements.
2190 * This operation is, essentially, the reverse of doing a regular
2191 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2194 * @example $("p").prependTo("#foo");
2195 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2196 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2197 * @desc Prepends all paragraphs to the element with the ID "foo"
2201 * @param <Content> content Content to prepend to the selected element to.
2202 * @cat DOM/Manipulation
2203 * @see prepend(<Content>)
2207 * Insert all of the matched elements before another, specified, set of elements.
2208 * This operation is, essentially, the reverse of doing a regular
2209 * $(A).before(B), in that instead of inserting B before A, you're inserting
2212 * @example $("p").insertBefore("#foo");
2213 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2214 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2215 * @desc Same as $("#foo").before("p")
2217 * @name insertBefore
2219 * @param <Content> content Content to insert the selected element before.
2220 * @cat DOM/Manipulation
2221 * @see before(<Content>)
2225 * Insert all of the matched elements after another, specified, set of elements.
2226 * This operation is, essentially, the reverse of doing a regular
2227 * $(A).after(B), in that instead of inserting B after A, you're inserting
2230 * @example $("p").insertAfter("#foo");
2231 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2232 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2233 * @desc Same as $("#foo").after("p")
2237 * @param <Content> content Content to insert the selected element after.
2238 * @cat DOM/Manipulation
2239 * @see after(<Content>)
2244 prependTo: "prepend",
2245 insertBefore: "before",
2246 insertAfter: "after",
2247 replaceAll: "replaceWith"
2249 jQuery.fn[ i ] = function(){
2251 return this.each(function(){
2252 for ( var j = 0, al = a.length; j < al; j++ )
2253 jQuery(a[j])[n]( this );
2259 * Remove an attribute from each of the matched elements.
2261 * @example $("input").removeAttr("disabled")
2262 * @before <input disabled="disabled"/>
2267 * @param String name The name of the attribute to remove.
2268 * @cat DOM/Attributes
2272 * Adds the specified class(es) to each of the set of matched elements.
2274 * @example $("p").addClass("selected")
2275 * @before <p>Hello</p>
2276 * @result [ <p class="selected">Hello</p> ]
2278 * @example $("p").addClass("selected highlight")
2279 * @before <p>Hello</p>
2280 * @result [ <p class="selected highlight">Hello</p> ]
2284 * @param String class One or more CSS classes to add to the elements
2285 * @cat DOM/Attributes
2286 * @see removeClass(String)
2290 * Removes all or the specified class(es) from the set of matched elements.
2292 * @example $("p").removeClass()
2293 * @before <p class="selected">Hello</p>
2294 * @result [ <p>Hello</p> ]
2296 * @example $("p").removeClass("selected")
2297 * @before <p class="selected first">Hello</p>
2298 * @result [ <p class="first">Hello</p> ]
2300 * @example $("p").removeClass("selected highlight")
2301 * @before <p class="highlight selected first">Hello</p>
2302 * @result [ <p class="first">Hello</p> ]
2306 * @param String class (optional) One or more CSS classes to remove from the elements
2307 * @cat DOM/Attributes
2308 * @see addClass(String)
2312 * Adds the specified class if it is not present, removes it if it is
2315 * @example $("p").toggleClass("selected")
2316 * @before <p>Hello</p><p class="selected">Hello Again</p>
2317 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2321 * @param String class A CSS class with which to toggle the elements
2322 * @cat DOM/Attributes
2326 * Removes all matched elements from the DOM. This does NOT remove them from the
2327 * jQuery object, allowing you to use the matched elements further.
2329 * Can be filtered with an optional expressions.
2331 * @example $("p").remove();
2332 * @before <p>Hello</p> how are <p>you?</p>
2335 * @example $("p").remove(".hello");
2336 * @before <p class="hello">Hello</p> how are <p>you?</p>
2337 * @result how are <p>you?</p>
2341 * @param String expr (optional) A jQuery expression to filter elements by.
2342 * @cat DOM/Manipulation
2346 * Removes all child nodes from the set of matched elements.
2348 * @example $("p").empty()
2349 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2350 * @result [ <p></p> ]
2354 * @cat DOM/Manipulation
2358 removeAttr: function( key ) {
2359 jQuery.attr( this, key, "" );
2360 this.removeAttribute( key );
2362 addClass: function(c){
2363 jQuery.className.add(this,c);
2365 removeClass: function(c){
2366 jQuery.className.remove(this,c);
2368 toggleClass: function( c ){
2369 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2371 remove: function(a){
2372 if ( !a || jQuery.filter( a, [this] ).r.length )
2373 this.parentNode.removeChild( this );
2376 while ( this.firstChild )
2377 this.removeChild( this.firstChild );
2380 jQuery.fn[ i ] = function() {
2381 return this.each( n, arguments );
2386 * Reduce the set of matched elements to a single element.
2387 * The position of the element in the set of matched elements
2388 * starts at 0 and goes to length - 1.
2390 * @example $("p").eq(1)
2391 * @before <p>This is just a test.</p><p>So is this</p>
2392 * @result [ <p>So is this</p> ]
2396 * @param Number pos The index of the element that you wish to limit to.
2401 * Reduce the set of matched elements to all elements before a given position.
2402 * The position of the element in the set of matched elements
2403 * starts at 0 and goes to length - 1.
2405 * @example $("p").lt(1)
2406 * @before <p>This is just a test.</p><p>So is this</p>
2407 * @result [ <p>This is just a test.</p> ]
2411 * @param Number pos Reduce the set to all elements below this position.
2416 * Reduce the set of matched elements to all elements after a given position.
2417 * The position of the element in the set of matched elements
2418 * starts at 0 and goes to length - 1.
2420 * @example $("p").gt(0)
2421 * @before <p>This is just a test.</p><p>So is this</p>
2422 * @result [ <p>So is this</p> ]
2426 * @param Number pos Reduce the set to all elements after this position.
2431 * Filter the set of elements to those that contain the specified text.
2433 * @example $("p").contains("test")
2434 * @before <p>This is just a test.</p><p>So is this</p>
2435 * @result [ <p>This is just a test.</p> ]
2439 * @param String str The string that will be contained within the text of an element.
2440 * @cat DOM/Traversing
2443 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2444 jQuery.fn[ n ] = function(num,fn) {
2445 return this.filter( ":" + n + "(" + num + ")", fn );
2450 * Get the current computed, pixel, width of the first matched element.
2452 * @example $("p").width();
2453 * @before <p>This is just a test.</p>
2462 * Set the CSS width of every matched element. If no explicit unit
2463 * was specified (like 'em' or '%') then "px" is added to the width.
2465 * @example $("p").width(20);
2466 * @before <p>This is just a test.</p>
2467 * @result <p style="width:20px;">This is just a test.</p>
2469 * @example $("p").width("20em");
2470 * @before <p>This is just a test.</p>
2471 * @result <p style="width:20em;">This is just a test.</p>
2475 * @param String|Number val Set the CSS property to the specified value.
2480 * Get the current computed, pixel, height of the first matched element.
2482 * @example $("p").height();
2483 * @before <p>This is just a test.</p>
2492 * Set the CSS height of every matched element. If no explicit unit
2493 * was specified (like 'em' or '%') then "px" is added to the width.
2495 * @example $("p").height(20);
2496 * @before <p>This is just a test.</p>
2497 * @result <p style="height:20px;">This is just a test.</p>
2499 * @example $("p").height("20em");
2500 * @before <p>This is just a test.</p>
2501 * @result <p style="height:20em;">This is just a test.</p>
2505 * @param String|Number val Set the CSS property to the specified value.
2509 jQuery.each( [ "height", "width" ], function(i,n){
2510 jQuery.fn[ n ] = function(h) {
2511 return h == undefined ?
2512 ( this.length ? jQuery.css( this[0], n ) : null ) :
2513 this.css( n, h.constructor == String ? h : h + "px" );