2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
21 * @param String|Function|Element|Array<Element>|jQuery a selector
22 * @param jQuery|Element|Array<Element> c context
25 var jQuery = function(a,c) {
26 // If the context is global, return a new object
28 return new jQuery(a,c);
30 // Make sure that a selection was provided
33 // HANDLE: $(function)
34 // Shortcut for document ready
35 // Safari reports typeof on DOM NodeLists as a function
36 if ( typeof a == "function" && !a.nodeType && a[0] == undefined )
37 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
39 // Handle HTML strings
40 if ( typeof a == "string" ) {
41 // HANDLE: $(html) -> $(array)
42 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
44 a = jQuery.clean( [ m[1] ] );
48 return new jQuery( c ).find( a );
53 a.constructor == Array && a ||
55 // HANDLE: $(arraylike)
56 // Watch for when an array-like object is passed as the selector
57 (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
63 // Map over the $ in case of overwrite
64 if ( typeof $ != "undefined" )
67 // Map the jQuery namespace to the '$' one
71 * This function accepts a string containing a CSS or
72 * basic XPath selector which is then used to match a set of elements.
74 * The core functionality of jQuery centers around this function.
75 * Everything in jQuery is based upon this, or uses this in some way.
76 * The most basic use of this function is to pass in an expression
77 * (usually consisting of CSS or XPath), which then finds all matching
80 * By default, $() looks for DOM elements within the context of the
81 * current HTML document.
83 * @example $("div > p")
84 * @desc Finds all p elements that are children of a div element.
85 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
86 * @result [ <p>two</p> ]
88 * @example $("input:radio", document.forms[0])
89 * @desc Searches for all inputs of type radio within the first form in the document
91 * @example $("div", xml.responseXML)
92 * @desc This finds all div elements within the specified XML document.
95 * @param String expr An expression to search with
96 * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
100 * @see $(Element<Array>)
104 * Create DOM elements on-the-fly from the provided String of raw HTML.
106 * @example $("<div><p>Hello</p></div>").appendTo("#body")
107 * @desc Creates a div element (and all of its contents) dynamically,
108 * and appends it to the element with the ID of body. Internally, an
109 * element is created and it's innerHTML property set to the given markup.
110 * It is therefore both quite flexible and limited.
113 * @param String html A string of HTML to create on the fly.
116 * @see appendTo(String)
120 * Wrap jQuery functionality around a single or multiple DOM Element(s).
122 * This function also accepts XML Documents and Window objects
123 * as valid arguments (even though they are not DOM Elements).
125 * @example $(document).find("div > p")
126 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
127 * @result [ <p>two</p> ]
128 * @desc Same as $("div > p") because the document
130 * @example $(document.body).background( "black" );
131 * @desc Sets the background color of the page to black.
133 * @example $( myForm.elements ).hide()
134 * @desc Hides all the input elements within a form
137 * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
143 * A shorthand for $(document).ready(), allowing you to bind a function
144 * to be executed when the DOM document has finished loading. This function
145 * behaves just like $(document).ready(), in that it should be used to wrap
146 * all of the other $() operations on your page. While this function is,
147 * technically, chainable - there really isn't much use for chaining against it.
148 * You can have as many $(document).ready events on your page as you like.
150 * See ready(Function) for details about the ready event.
152 * @example $(function(){
153 * // Document is ready
155 * @desc Executes the function when the DOM is ready to be used.
157 * @example jQuery(function($) {
158 * // Your code using failsafe $ alias here...
160 * @desc Uses both the shortcut for $(document).ready() and the argument
161 * to write failsafe jQuery code using the $ alias, without relying on the
165 * @param Function fn The function to execute when the DOM is ready.
168 * @see ready(Function)
171 jQuery.fn = jQuery.prototype = {
173 * The current version of jQuery.
184 * The number of elements currently matched.
186 * @example $("img").length;
187 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
197 * The number of elements currently matched.
199 * @example $("img").size();
200 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
214 * Access all matched elements. This serves as a backwards-compatible
215 * way of accessing all matched elements (other than the jQuery object
216 * itself, which is, in fact, an array of elements).
218 * @example $("img").get();
219 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
220 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
221 * @desc Selects all images in the document and returns the DOM Elements as an Array
224 * @type Array<Element>
229 * Access a single matched element. num is used to access the
230 * Nth element matched.
232 * @example $("img").get(0);
233 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
234 * @result [ <img src="test1.jpg"/> ]
235 * @desc Selects all images in the document and returns the first one
239 * @param Number num Access the element in the Nth position.
242 get: function( num ) {
243 return num == undefined ?
245 // Return a 'clean' array
246 jQuery.makeArray( this ) :
248 // Return just the object
253 * Set the jQuery object to an array of elements, while maintaining
256 * @example $("img").pushStack([ document.body ]);
257 * @result $("img").pushStack() == [ document.body ]
262 * @param Elements elems An array of elements
265 pushStack: function( a ) {
266 var ret = jQuery(this);
267 ret.prevObject = this;
268 return ret.setArray( a );
272 * Set the jQuery object to an array of elements. This operation is
273 * completely destructive - be sure to use .pushStack() if you wish to maintain
276 * @example $("img").setArray([ document.body ]);
277 * @result $("img").setArray() == [ document.body ]
282 * @param Elements elems An array of elements
285 setArray: function( a ) {
287 [].push.apply( this, a );
292 * Execute a function within the context of every matched element.
293 * This means that every time the passed-in function is executed
294 * (which is once for every element matched) the 'this' keyword
295 * points to the specific element.
297 * Additionally, the function, when executed, is passed a single
298 * argument representing the position of the element in the matched
301 * @example $("img").each(function(i){
302 * this.src = "test" + i + ".jpg";
304 * @before <img/><img/>
305 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
306 * @desc Iterates over two images and sets their src property
310 * @param Function fn A function to execute
313 each: function( fn, args ) {
314 return jQuery.each( this, fn, args );
318 * Searches every matched element for the object and returns
319 * the index of the element, if found, starting with zero.
320 * Returns -1 if the object wasn't found.
322 * @example $("*").index( $('#foobar')[0] )
323 * @before <div id="foobar"></div><b></b><span id="foo"></span>
325 * @desc Returns the index for the element with ID foobar
327 * @example $("*").index( $('#foo'))
328 * @before <div id="foobar"></div><b></b><span id="foo"></span>
330 * @desc Returns the index for the element with ID foo
332 * @example $("*").index( $('#bar'))
333 * @before <div id="foobar"></div><b></b><span id="foo"></span>
335 * @desc Returns -1, as there is no element with ID bar
339 * @param Element subject Object to search for
342 index: function( obj ) {
344 this.each(function(i){
345 if ( this == obj ) pos = i;
351 * Access a property on the first matched element.
352 * This method makes it easy to retrieve a property value
353 * from the first matched element.
355 * @example $("img").attr("src");
356 * @before <img src="test.jpg"/>
358 * @desc Returns the src attribute from the first image in the document.
362 * @param String name The name of the property to access.
363 * @cat DOM/Attributes
367 * Set a key/value object as properties to all matched elements.
369 * This serves as the best way to set a large number of properties
370 * on all matched elements.
372 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
374 * @result <img src="test.jpg" alt="Test Image"/>
375 * @desc Sets src and alt attributes to all images.
379 * @param Map properties Key/value pairs to set as object properties.
380 * @cat DOM/Attributes
384 * Set a single property to a value, on all matched elements.
386 * Can compute values provided as ${formula}, see second example.
388 * Note that you can't set the name property of input elements in IE.
389 * Use $(html) or .append(html) or .html(html) to create elements
390 * on the fly including the name property.
392 * @example $("img").attr("src","test.jpg");
394 * @result <img src="test.jpg"/>
395 * @desc Sets src attribute to all images.
397 * @example $("img").attr("title", "${this.src}");
398 * @before <img src="test.jpg" />
399 * @result <img src="test.jpg" title="test.jpg" />
400 * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
404 * @param String key The name of the property to set.
405 * @param Object value The value to set the property to.
406 * @cat DOM/Attributes
410 * Set a single property to a computed value, on all matched elements.
412 * Instead of a value, a function is provided, that computes the value.
414 * @example $("img").attr("title", function() { return this.src });
415 * @before <img src="test.jpg" />
416 * @result <img src="test.jpg" title="test.jpg" />
417 * @desc Sets title attribute from src attribute.
421 * @param String key The name of the property to set.
422 * @param Function value A function returning the value to set.
423 * @cat DOM/Attributes
425 attr: function( key, value, type ) {
428 // Look for the case where we're accessing a style value
429 if ( key.constructor == String )
430 if ( value == undefined )
431 return jQuery[ type || "attr" ]( this[0], key );
437 // Check to see if we're setting style values
438 return this.each(function(){
439 // Set all the styles
440 for ( var prop in obj )
442 type ? this.style : this,
443 prop, jQuery.prop(this, obj[prop], type)
449 * Access a style property on the first matched element.
450 * This method makes it easy to retrieve a style property value
451 * from the first matched element.
453 * @example $("p").css("color");
454 * @before <p style="color:red;">Test Paragraph.</p>
456 * @desc Retrieves the color style of the first paragraph
458 * @example $("p").css("font-weight");
459 * @before <p style="font-weight: bold;">Test Paragraph.</p>
461 * @desc Retrieves the font-weight style of the first paragraph.
465 * @param String name The name of the property to access.
470 * Set a key/value object as style properties to all matched elements.
472 * This serves as the best way to set a large number of style properties
473 * on all matched elements.
475 * @example $("p").css({ color: "red", background: "blue" });
476 * @before <p>Test Paragraph.</p>
477 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
478 * @desc Sets color and background styles to all p elements.
482 * @param Map properties Key/value pairs to set as style properties.
487 * Set a single style property to a value, on all matched elements.
488 * If a number is provided, it is automatically converted into a pixel value.
490 * @example $("p").css("color","red");
491 * @before <p>Test Paragraph.</p>
492 * @result <p style="color:red;">Test Paragraph.</p>
493 * @desc Changes the color of all paragraphs to red
495 * @example $("p").css("left",30);
496 * @before <p>Test Paragraph.</p>
497 * @result <p style="left:30px;">Test Paragraph.</p>
498 * @desc Changes the left of all paragraphs to "30px"
502 * @param String key The name of the property to set.
503 * @param String|Number value The value to set the property to.
506 css: function( key, value ) {
507 return this.attr( key, value, "curCSS" );
511 * Get the text contents of all matched elements. The result is
512 * a string that contains the combined text contents of all matched
513 * elements. This method works on both HTML and XML documents.
515 * @example $("p").text();
516 * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
517 * @result Test Paragraph.Paraparagraph
518 * @desc Gets the concatenated text of all paragraphs
522 * @cat DOM/Attributes
526 * Set the text contents of all matched elements.
528 * Similar to html(), but escapes HTML (replace "<" and ">" with their
531 * @example $("p").text("<b>Some</b> new text.");
532 * @before <p>Test Paragraph.</p>
533 * @result <p><b>Some</b> new text.</p>
534 * @desc Sets the text of all paragraphs.
536 * @example $("p").text("<b>Some</b> new text.", true);
537 * @before <p>Test Paragraph.</p>
538 * @result <p>Some new text.</p>
539 * @desc Sets the text of all paragraphs.
543 * @param String val The text value to set the contents of the element to.
544 * @cat DOM/Attributes
547 var type = this.length && this[0].innerText == undefined ?
548 "textContent" : "innerText";
550 return e == undefined ?
551 this.length && this[0][ type ] :
552 this.each(function(){ this[ type ] = e; });
556 * Wrap all matched elements with a structure of other elements.
557 * This wrapping process is most useful for injecting additional
558 * stucture into a document, without ruining the original semantic
559 * qualities of a document.
561 * This works by going through the first element
562 * provided (which is generated, on the fly, from the provided HTML)
563 * and finds the deepest ancestor element within its
564 * structure - it is that element that will en-wrap everything else.
566 * This does not work with elements that contain text. Any necessary text
567 * must be added after the wrapping is done.
569 * @example $("p").wrap("<div class='wrap'></div>");
570 * @before <p>Test Paragraph.</p>
571 * @result <div class='wrap'><p>Test Paragraph.</p></div>
575 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
576 * @cat DOM/Manipulation
580 * Wrap all matched elements with a structure of other elements.
581 * This wrapping process is most useful for injecting additional
582 * stucture into a document, without ruining the original semantic
583 * qualities of a document.
585 * This works by going through the first element
586 * provided and finding the deepest ancestor element within its
587 * structure - it is that element that will en-wrap everything else.
589 * This does not work with elements that contain text. Any necessary text
590 * must be added after the wrapping is done.
592 * @example $("p").wrap( document.getElementById('content') );
593 * @before <p>Test Paragraph.</p><div id="content"></div>
594 * @result <div id="content"><p>Test Paragraph.</p></div>
598 * @param Element elem A DOM element that will be wrapped around the target.
599 * @cat DOM/Manipulation
602 // The elements to wrap the target around
603 var a = jQuery.clean(arguments);
605 // Wrap each of the matched elements individually
606 return this.each(function(){
607 // Clone the structure that we're using to wrap
608 var b = a[0].cloneNode(true);
610 // Insert it before the element to be wrapped
611 this.parentNode.insertBefore( b, this );
613 // Find the deepest point in the wrap structure
614 while ( b.firstChild )
617 // Move the matched element to within the wrap structure
618 b.appendChild( this );
623 * Append content to the inside of every matched element.
625 * This operation is similar to doing an appendChild to all the
626 * specified elements, adding them into the document.
628 * @example $("p").append("<b>Hello</b>");
629 * @before <p>I would like to say: </p>
630 * @result <p>I would like to say: <b>Hello</b></p>
631 * @desc Appends some HTML to all paragraphs.
633 * @example $("p").append( $("#foo")[0] );
634 * @before <p>I would like to say: </p><b id="foo">Hello</b>
635 * @result <p>I would like to say: <b id="foo">Hello</b></p>
636 * @desc Appends an Element to all paragraphs.
638 * @example $("p").append( $("b") );
639 * @before <p>I would like to say: </p><b>Hello</b>
640 * @result <p>I would like to say: <b>Hello</b></p>
641 * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
645 * @param <Content> content Content to append to the target
646 * @cat DOM/Manipulation
647 * @see prepend(<Content>)
648 * @see before(<Content>)
649 * @see after(<Content>)
652 return this.domManip(arguments, true, 1, function(a){
653 this.appendChild( a );
658 * Prepend content to the inside of every matched element.
660 * This operation is the best way to insert elements
661 * inside, at the beginning, of all matched elements.
663 * @example $("p").prepend("<b>Hello</b>");
664 * @before <p>I would like to say: </p>
665 * @result <p><b>Hello</b>I would like to say: </p>
666 * @desc Prepends some HTML to all paragraphs.
668 * @example $("p").prepend( $("#foo")[0] );
669 * @before <p>I would like to say: </p><b id="foo">Hello</b>
670 * @result <p><b id="foo">Hello</b>I would like to say: </p>
671 * @desc Prepends an Element to all paragraphs.
673 * @example $("p").prepend( $("b") );
674 * @before <p>I would like to say: </p><b>Hello</b>
675 * @result <p><b>Hello</b>I would like to say: </p>
676 * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
680 * @param <Content> content Content to prepend to the target.
681 * @cat DOM/Manipulation
682 * @see append(<Content>)
683 * @see before(<Content>)
684 * @see after(<Content>)
686 prepend: function() {
687 return this.domManip(arguments, true, -1, function(a){
688 this.insertBefore( a, this.firstChild );
693 * Insert content before each of the matched elements.
695 * @example $("p").before("<b>Hello</b>");
696 * @before <p>I would like to say: </p>
697 * @result <b>Hello</b><p>I would like to say: </p>
698 * @desc Inserts some HTML before all paragraphs.
700 * @example $("p").before( $("#foo")[0] );
701 * @before <p>I would like to say: </p><b id="foo">Hello</b>
702 * @result <b id="foo">Hello</b><p>I would like to say: </p>
703 * @desc Inserts an Element before all paragraphs.
705 * @example $("p").before( $("b") );
706 * @before <p>I would like to say: </p><b>Hello</b>
707 * @result <b>Hello</b><p>I would like to say: </p>
708 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
712 * @param <Content> content Content to insert before each target.
713 * @cat DOM/Manipulation
714 * @see append(<Content>)
715 * @see prepend(<Content>)
716 * @see after(<Content>)
719 return this.domManip(arguments, false, 1, function(a){
720 this.parentNode.insertBefore( a, this );
725 * Insert content after each of the matched elements.
727 * @example $("p").after("<b>Hello</b>");
728 * @before <p>I would like to say: </p>
729 * @result <p>I would like to say: </p><b>Hello</b>
730 * @desc Inserts some HTML after all paragraphs.
732 * @example $("p").after( $("#foo")[0] );
733 * @before <b id="foo">Hello</b><p>I would like to say: </p>
734 * @result <p>I would like to say: </p><b id="foo">Hello</b>
735 * @desc Inserts an Element after all paragraphs.
737 * @example $("p").after( $("b") );
738 * @before <b>Hello</b><p>I would like to say: </p>
739 * @result <p>I would like to say: </p><b>Hello</b>
740 * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
744 * @param <Content> content Content to insert after each target.
745 * @cat DOM/Manipulation
746 * @see append(<Content>)
747 * @see prepend(<Content>)
748 * @see before(<Content>)
751 return this.domManip(arguments, false, -1, function(a){
752 this.parentNode.insertBefore( a, this.nextSibling );
757 * End the most recent 'destructive' operation, reverting the list of matched elements
758 * back to its previous state. After an end operation, the list of matched elements will
759 * revert to the last state of matched elements.
761 * If there was no destructive operation before, an empty set is returned.
763 * @example $("p").find("span").end();
764 * @before <p><span>Hello</span>, how are you?</p>
765 * @result [ <p>...</p> ]
766 * @desc Selects all paragraphs, finds span elements inside these, and reverts the
767 * selection back to the paragraphs.
771 * @cat DOM/Traversing
774 return this.prevObject || jQuery([]);
778 * Searches for all elements that match the specified expression.
780 * This method is a good way to find additional descendant
781 * elements with which to process.
783 * All searching is done using a jQuery expression. The expression can be
784 * written using CSS 1-3 Selector syntax, or basic XPath.
786 * @example $("p").find("span");
787 * @before <p><span>Hello</span>, how are you?</p>
788 * @result [ <span>Hello</span> ]
789 * @desc Starts with all paragraphs and searches for descendant span
790 * elements, same as $("p span")
794 * @param String expr An expression to search with.
795 * @cat DOM/Traversing
798 return this.pushStack( jQuery.map( this, function(a){
799 return jQuery.find(t,a);
804 * Clone matched DOM Elements and select the clones.
806 * This is useful for moving copies of the elements to another
807 * location in the DOM.
809 * @example $("b").clone().prependTo("p");
810 * @before <b>Hello</b><p>, how are you?</p>
811 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
812 * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
816 * @cat DOM/Manipulation
818 clone: function(deep) {
819 return this.pushStack( jQuery.map( this, function(a){
820 return a.cloneNode( deep != undefined ? deep : true );
825 * Removes all elements from the set of matched elements that do not
826 * match the specified expression(s). This method is used to narrow down
827 * the results of a search.
829 * Provide a comma-separated list of expressions to apply multiple filters at once.
831 * @example $("p").filter(".selected")
832 * @before <p class="selected">Hello</p><p>How are you?</p>
833 * @result [ <p class="selected">Hello</p> ]
834 * @desc Selects all paragraphs and removes those without a class "selected".
836 * @example $("p").filter(".selected, :first")
837 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
838 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
839 * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
843 * @param String expression Expression(s) to search with.
844 * @cat DOM/Traversing
848 * Removes all elements from the set of matched elements that do not
849 * pass the specified filter. This method is used to narrow down
850 * the results of a search.
852 * @example $("p").filter(function(index) {
853 * return $("ol", this).length == 0;
855 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
856 * @result [ <p>How are you?</p> ]
857 * @desc Remove all elements that have a child ol element
861 * @param Function filter A function to use for filtering
862 * @cat DOM/Traversing
864 filter: function(t) {
865 return this.pushStack(
866 t.constructor == Function &&
867 jQuery.grep(this, function(el, index){
868 return t.apply(el, [index])
871 jQuery.multiFilter(t,this) );
875 * Removes the specified Element from the set of matched elements. This
876 * method is used to remove a single Element from a jQuery object.
878 * @example $("p").not( $("#selected")[0] )
879 * @before <p>Hello</p><p id="selected">Hello Again</p>
880 * @result [ <p>Hello</p> ]
881 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
885 * @param Element el An element to remove from the set
886 * @cat DOM/Traversing
890 * Removes elements matching the specified expression from the set
891 * of matched elements. This method is used to remove one or more
892 * elements from a jQuery object.
894 * @example $("p").not("#selected")
895 * @before <p>Hello</p><p id="selected">Hello Again</p>
896 * @result [ <p>Hello</p> ]
897 * @desc Removes the element with the ID "selected" from the set of all paragraphs.
901 * @param String expr An expression with which to remove matching elements
902 * @cat DOM/Traversing
906 * Removes any elements inside the array of elements from the set
907 * of matched elements. This method is used to remove one or more
908 * elements from a jQuery object.
910 * @example $("p").not( $("div p.selected") )
911 * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
912 * @result [ <p>Hello</p> ]
913 * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
917 * @param Array|jQuery elems A set of elements to remove from the jQuery set of matched elements.
918 * @cat DOM/Traversing
921 return this.pushStack(
922 t.constructor == String &&
923 jQuery.multiFilter(t,this,true) ||
925 jQuery.grep(this,function(a){
926 if ( t.constructor == Array || t.jquery )
927 return !jQuery.inArray( t, a );
934 * Adds the elements matched by the expression to the jQuery object. This
935 * can be used to concatenate the result sets of two expressions.
937 * @example $("p").add("span")
938 * @before <p>Hello</p><p><span>Hello Again</span></p>
939 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
943 * @param String expr An expression whose matched elements are added
944 * @cat DOM/Traversing
948 * Adds the on the fly created elements to the jQuery object.
950 * @example $("p").add("<span>Again</span>")
951 * @before <p>Hello</p>
952 * @result [ <p>Hello</p>, <span>Again</span> ]
956 * @param String html A string of HTML to create on the fly.
957 * @cat DOM/Traversing
961 * Adds one or more Elements to the set of matched elements.
963 * This is used to add a set of Elements to a jQuery object.
965 * @example $("p").add( document.getElementById("a") )
966 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
967 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
969 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
970 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
971 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
975 * @param Element|Array<Element> elements One or more Elements to add
976 * @cat DOM/Traversing
979 return this.pushStack( jQuery.merge(
981 typeof t == "string" ? jQuery(t).get() : t )
986 * Checks the current selection against an expression and returns true,
987 * if at least one element of the selection fits the given expression.
989 * Does return false, if no element fits or the expression is not valid.
991 * filter(String) is used internally, therefore all rules that apply there
994 * @example $("input[@type='checkbox']").parent().is("form")
995 * @before <form><input type="checkbox" /></form>
997 * @desc Returns true, because the parent of the input is a form element
999 * @example $("input[@type='checkbox']").parent().is("form")
1000 * @before <form><p><input type="checkbox" /></p></form>
1002 * @desc Returns false, because the parent of the input is a p element
1006 * @param String expr The expression with which to filter
1007 * @cat DOM/Traversing
1009 is: function(expr) {
1010 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1014 * Get the current value of the first matched element.
1016 * @example $("input").val();
1017 * @before <input type="text" value="some text"/>
1018 * @result "some text"
1022 * @cat DOM/Attributes
1026 * Set the value of every matched element.
1028 * @example $("input").val("test");
1029 * @before <input type="text" value="some text"/>
1030 * @result <input type="text" value="test"/>
1034 * @param String val Set the property to the specified value.
1035 * @cat DOM/Attributes
1037 val: function( val ) {
1038 return val == undefined ?
1039 ( this.length ? this[0].value : null ) :
1040 this.attr( "value", val );
1044 * Get the html contents of the first matched element.
1045 * This property is not available on XML documents.
1047 * @example $("div").html();
1048 * @before <div><input/></div>
1053 * @cat DOM/Attributes
1057 * Set the html contents of every matched element.
1058 * This property is not available on XML documents.
1060 * @example $("div").html("<b>new stuff</b>");
1061 * @before <div><input/></div>
1062 * @result <div><b>new stuff</b></div>
1066 * @param String val Set the html contents to the specified value.
1067 * @cat DOM/Attributes
1069 html: function( val ) {
1070 return val == undefined ?
1071 ( this.length ? this[0].innerHTML : null ) :
1072 this.empty().append( val );
1079 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1080 * @param Number dir If dir<0, process args in reverse order.
1081 * @param Function fn The function doing the DOM manipulation.
1085 domManip: function(args, table, dir, fn){
1086 var clone = this.length > 1;
1087 var a = jQuery.clean(args);
1091 return this.each(function(){
1094 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1095 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1097 for ( var i = 0, al = a.length; i < al; i++ )
1098 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1105 * Extends the jQuery object itself. Can be used to add functions into
1106 * the jQuery namespace and to add plugin methods (plugins).
1108 * @example jQuery.fn.extend({
1109 * check: function() {
1110 * return this.each(function() { this.checked = true; });
1112 * uncheck: function() {
1113 * return this.each(function() { this.checked = false; });
1116 * $("input[@type=checkbox]").check();
1117 * $("input[@type=radio]").uncheck();
1118 * @desc Adds two plugin methods.
1120 * @example jQuery.extend({
1121 * min: function(a, b) { return a < b ? a : b; },
1122 * max: function(a, b) { return a > b ? a : b; }
1124 * @desc Adds two functions into the jQuery namespace
1127 * @param Object prop The object that will be merged into the jQuery object
1133 * Extend one object with one or more others, returning the original,
1134 * modified, object. This is a great utility for simple inheritance.
1136 * @example var settings = { validate: false, limit: 5, name: "foo" };
1137 * var options = { validate: true, name: "bar" };
1138 * jQuery.extend(settings, options);
1139 * @result settings == { validate: true, limit: 5, name: "bar" }
1140 * @desc Merge settings and options, modifying settings
1142 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1143 * var options = { validate: true, name: "bar" };
1144 * var settings = jQuery.extend({}, defaults, options);
1145 * @result settings == { validate: true, limit: 5, name: "bar" }
1146 * @desc Merge defaults and options, without modifying the defaults
1149 * @param Object target The object to extend
1150 * @param Object prop1 The object that will be merged into the first.
1151 * @param Object propN (optional) More objects to merge into the first
1155 jQuery.extend = jQuery.fn.extend = function() {
1156 // copy reference to target object
1157 var target = arguments[0],
1160 // extend jQuery itself if only one argument is passed
1161 if ( arguments.length == 1 ) {
1166 while (prop = arguments[a++])
1167 // Extend the base object
1168 for ( var i in prop ) target[i] = prop[i];
1170 // Return the modified object
1176 * Run this function to give control of the $ variable back
1177 * to whichever library first implemented it. This helps to make
1178 * sure that jQuery doesn't conflict with the $ object
1179 * of other libraries.
1181 * By using this function, you will only be able to access jQuery
1182 * using the 'jQuery' variable. For example, where you used to do
1183 * $("div p"), you now must do jQuery("div p").
1185 * @example jQuery.noConflict();
1186 * // Do something with jQuery
1187 * jQuery("div p").hide();
1188 * // Do something with another library's $()
1189 * $("content").style.display = 'none';
1190 * @desc Maps the original object that was referenced by $ back to $
1192 * @example jQuery.noConflict();
1195 * // more code using $ as alias to jQuery
1198 * // other code using $ as an alias to the other library
1199 * @desc Reverts the $ alias and then creates and executes a
1200 * function to provide the $ as a jQuery alias inside the functions
1201 * scope. Inside the function the original $ object is not available.
1202 * This works well for most plugins that don't rely on any other library.
1205 * @name $.noConflict
1209 noConflict: function() {
1215 * A generic iterator function, which can be used to seemlessly
1216 * iterate over both objects and arrays. This function is not the same
1217 * as $().each() - which is used to iterate, exclusively, over a jQuery
1218 * object. This function can be used to iterate over anything.
1220 * The callback has two arguments:the key (objects) or index (arrays) as first
1221 * the first, and the value as the second.
1223 * @example $.each( [0,1,2], function(i, n){
1224 * alert( "Item #" + i + ": " + n );
1226 * @desc This is an example of iterating over the items in an array,
1227 * accessing both the current item and its index.
1229 * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1230 * alert( "Name: " + i + ", Value: " + n );
1233 * @desc This is an example of iterating over the properties in an
1234 * Object, accessing both the current item and its key.
1237 * @param Object obj The object, or array, to iterate over.
1238 * @param Function fn The function that will be executed on every object.
1242 // args is for internal usage only
1243 each: function( obj, fn, args ) {
1244 if ( obj.length == undefined )
1245 for ( var i in obj )
1246 fn.apply( obj[i], args || [i, obj[i]] );
1248 for ( var i = 0, ol = obj.length; i < ol; i++ )
1249 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1253 prop: function(elem, value, type){
1254 // Handle executable functions
1255 if ( value.constructor == Function )
1256 return value.call( elem )
1258 // Handle passing in a number to a CSS property
1259 if ( value.constructor == Number && type == "css" )
1260 return value + "px";
1266 // internal only, use addClass("class")
1267 add: function( elem, c ){
1268 jQuery.each( c.split(/\s+/), function(i, cur){
1269 if ( !jQuery.className.has( elem.className, cur ) )
1270 elem.className += ( elem.className ? " " : "" ) + cur;
1274 // internal only, use removeClass("class")
1275 remove: function( elem, c ){
1276 elem.className = c ?
1277 jQuery.grep( elem.className.split(/\s+/), function(cur){
1278 return !jQuery.className.has( c, cur );
1282 // internal only, use is(".class")
1283 has: function( t, c ) {
1284 t = t.className || t;
1285 return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
1290 * Swap in/out style options.
1293 swap: function(e,o,f) {
1294 for ( var i in o ) {
1295 e.style["old"+i] = e.style[i];
1300 e.style[i] = e.style["old"+i];
1303 css: function(e,p) {
1304 if ( p == "height" || p == "width" ) {
1305 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1307 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1308 old["padding" + d[i]] = 0;
1309 old["border" + d[i] + "Width"] = 0;
1312 jQuery.swap( e, old, function() {
1313 if (jQuery.css(e,"display") != "none") {
1314 oHeight = e.offsetHeight;
1315 oWidth = e.offsetWidth;
1317 e = jQuery(e.cloneNode(true))
1318 .find(":radio").removeAttr("checked").end()
1320 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1321 }).appendTo(e.parentNode)[0];
1323 var parPos = jQuery.css(e.parentNode,"position");
1324 if ( parPos == "" || parPos == "static" )
1325 e.parentNode.style.position = "relative";
1327 oHeight = e.clientHeight;
1328 oWidth = e.clientWidth;
1330 if ( parPos == "" || parPos == "static" )
1331 e.parentNode.style.position = "static";
1333 e.parentNode.removeChild(e);
1337 return p == "height" ? oHeight : oWidth;
1340 return jQuery.curCSS( e, p );
1343 curCSS: function(elem, prop, force) {
1346 if (prop == 'opacity' && jQuery.browser.msie)
1347 return jQuery.attr(elem.style, 'opacity');
1349 if (prop == "float" || prop == "cssFloat")
1350 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1352 if (!force && elem.style[prop])
1353 ret = elem.style[prop];
1355 else if (document.defaultView && document.defaultView.getComputedStyle) {
1357 if (prop == "cssFloat" || prop == "styleFloat")
1360 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1361 var cur = document.defaultView.getComputedStyle(elem, null);
1364 ret = cur.getPropertyValue(prop);
1365 else if ( prop == 'display' )
1368 jQuery.swap(elem, { display: 'block' }, function() {
1369 var c = document.defaultView.getComputedStyle(this, '');
1370 ret = c && c.getPropertyValue(prop) || '';
1373 } else if (elem.currentStyle) {
1375 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1376 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1383 clean: function(a) {
1386 for ( var i = 0, al = a.length; i < al; i++ ) {
1389 // Convert html string into DOM nodes
1390 if ( typeof arg == "string" ) {
1391 // Trim whitespace, otherwise indexOf won't work as expected
1392 var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
1395 // option or optgroup
1396 !s.indexOf("<opt") &&
1397 [1, "<select>", "</select>"] ||
1399 (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
1400 [1, "<table>", "</table>"] ||
1402 !s.indexOf("<tr") &&
1403 [2, "<table><tbody>", "</tbody></table>"] ||
1405 // <thead> matched above
1406 (!s.indexOf("<td") || !s.indexOf("<th")) &&
1407 [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1411 // Go to html and back, then peel off extra wrappers
1412 div.innerHTML = wrap[1] + s + wrap[2];
1414 // Move to the right depth
1416 div = div.firstChild;
1418 // Remove IE's autoinserted <tbody> from table fragments
1419 if ( jQuery.browser.msie ) {
1421 // String was a <table>, *may* have spurious <tbody>
1422 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 )
1423 tb = div.firstChild && div.firstChild.childNodes;
1425 // String was a bare <thead> or <tfoot>
1426 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1427 tb = div.childNodes;
1429 for ( var n = tb.length-1; n >= 0 ; --n )
1430 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1431 tb[n].parentNode.removeChild(tb[n]);
1435 arg = div.childNodes;
1441 r = jQuery.merge( r, arg );
1448 attr: function(elem, name, value){
1451 "class": "className",
1452 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1453 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1454 innerHTML: "innerHTML",
1455 className: "className",
1457 disabled: "disabled",
1459 readonly: "readOnly",
1460 selected: "selected"
1463 // IE actually uses filters for opacity ... elem is actually elem.style
1464 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1465 // IE has trouble with opacity if it does not have layout
1466 // Force it by setting the zoom level
1469 // Set the alpha filter to set the opacity
1470 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1471 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1473 } else if ( name == "opacity" && jQuery.browser.msie )
1474 return elem.filter ?
1475 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1477 // Mozilla doesn't play well with opacity 1
1478 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1481 // Certain attributes only work when accessed via the old DOM 0 way
1483 if ( value != undefined ) elem[fix[name]] = value;
1484 return elem[fix[name]];
1486 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') )
1487 return elem.getAttributeNode(name).nodeValue;
1489 // IE elem.getAttribute passes even for style
1490 else if ( elem.tagName ) {
1491 if ( value != undefined ) elem.setAttribute( name, value );
1492 return elem.getAttribute( name );
1495 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1496 if ( value != undefined ) elem[name] = value;
1502 * Remove the whitespace from the beginning and end of a string.
1504 * @example $.trim(" hello, how are you? ");
1505 * @result "hello, how are you?"
1509 * @param String str The string to trim.
1513 return t.replace(/^\s+|\s+$/g, "");
1516 makeArray: function( a ) {
1519 if ( a.constructor != Array )
1520 for ( var i = 0, al = a.length; i < al; i++ )
1528 inArray: function( b, a ) {
1529 for ( var i = 0, al = a.length; i < al; i++ )
1536 * Merge two arrays together, removing all duplicates.
1538 * The new array is: All the results from the first array, followed
1539 * by the unique results from the second array.
1541 * @example $.merge( [0,1,2], [2,3,4] )
1542 * @result [0,1,2,3,4]
1543 * @desc Merges two arrays, removing the duplicate 2
1545 * @example $.merge( [3,2,1], [4,3,2] )
1547 * @desc Merges two arrays, removing the duplicates 3 and 2
1551 * @param Array first The first array to merge.
1552 * @param Array second The second array to merge.
1555 merge: function(first, second) {
1556 var r = [].slice.call( first, 0 );
1558 // Now check for duplicates between the two arrays
1559 // and only add the unique items
1560 for ( var i = 0, sl = second.length; i < sl; i++ )
1561 // Check for duplicates
1562 if ( jQuery.inArray( second[i], r ) == -1 )
1563 // The item is unique, add it
1564 first.push( second[i] );
1570 * Filter items out of an array, by using a filter function.
1572 * The specified function will be passed two arguments: The
1573 * current array item and the index of the item in the array. The
1574 * function must return 'true' to keep the item in the array,
1575 * false to remove it.
1577 * @example $.grep( [0,1,2], function(i){
1584 * @param Array array The Array to find items in.
1585 * @param Function fn The function to process each item against.
1586 * @param Boolean inv Invert the selection - select the opposite of the function.
1589 grep: function(elems, fn, inv) {
1590 // If a string is passed in for the function, make a function
1591 // for it (a handy shortcut)
1592 if ( typeof fn == "string" )
1593 fn = new Function("a","i","return " + fn);
1597 // Go through the array, only saving the items
1598 // that pass the validator function
1599 for ( var i = 0, el = elems.length; i < el; i++ )
1600 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1601 result.push( elems[i] );
1607 * Translate all items in an array to another array of items.
1609 * The translation function that is provided to this method is
1610 * called for each item in the array and is passed one argument:
1611 * The item to be translated.
1613 * The function can then return the translated value, 'null'
1614 * (to remove the item), or an array of values - which will
1615 * be flattened into the full array.
1617 * @example $.map( [0,1,2], function(i){
1621 * @desc Maps the original array to a new one and adds 4 to each value.
1623 * @example $.map( [0,1,2], function(i){
1624 * return i > 0 ? i + 1 : null;
1627 * @desc Maps the original array to a new one and adds 1 to each
1628 * value if it is bigger then zero, otherwise it's removed-
1630 * @example $.map( [0,1,2], function(i){
1631 * return [ i, i + 1 ];
1633 * @result [0, 1, 1, 2, 2, 3]
1634 * @desc Maps the original array to a new one, each element is added
1635 * with it's original value and the value plus one.
1639 * @param Array array The Array to translate.
1640 * @param Function fn The function to process each item against.
1643 map: function(elems, fn) {
1644 // If a string is passed in for the function, make a function
1645 // for it (a handy shortcut)
1646 if ( typeof fn == "string" )
1647 fn = new Function("a","return " + fn);
1649 var result = [], r = [];
1651 // Go through the array, translating each of the items to their
1652 // new value (or values).
1653 for ( var i = 0, el = elems.length; i < el; i++ ) {
1654 var val = fn(elems[i],i);
1656 if ( val !== null && val != undefined ) {
1657 if ( val.constructor != Array ) val = [val];
1658 result = result.concat( val );
1662 var r = result.length ? [ result[0] ] : [];
1664 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1665 for ( var j = 0; j < i; j++ )
1666 if ( result[i] == r[j] )
1669 r.push( result[i] );
1677 * Contains flags for the useragent, read from navigator.userAgent.
1678 * Available flags are: safari, opera, msie, mozilla
1680 * This property is available before the DOM is ready, therefore you can
1681 * use it to add ready events only for certain browsers.
1683 * There are situations where object detections is not reliable enough, in that
1684 * cases it makes sense to use browser detection. Simply try to avoid both!
1686 * A combination of browser and object detection yields quite reliable results.
1688 * @example $.browser.msie
1689 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1691 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1692 * @desc Alerts "this is safari!" only for safari browsers
1701 * Wheather the W3C compliant box model is being used.
1709 var b = navigator.userAgent.toLowerCase();
1711 // Figure out what browser is being used
1713 safari: /webkit/.test(b),
1714 opera: /opera/.test(b),
1715 msie: /msie/.test(b) && !/opera/.test(b),
1716 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1719 // Check to see if the W3C box model is being used
1720 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1724 * Get a set of elements containing the unique parents of the matched
1727 * Can be filtered with an optional expressions.
1729 * @example $("p").parent()
1730 * @before <div><p>Hello</p><p>Hello</p></div>
1731 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1732 * @desc Find the parent element of each paragraph.
1734 * @example $("p").parent(".selected")
1735 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1736 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1737 * @desc Find the parent element of each paragraph with a class "selected".
1741 * @param String expr (optional) An expression to filter the parents with
1742 * @cat DOM/Traversing
1746 * Get a set of elements containing the unique ancestors of the matched
1747 * set of elements (except for the root element).
1749 * Can be filtered with an optional expressions.
1751 * @example $("span").parents()
1752 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1753 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1754 * @desc Find all parent elements of each span.
1756 * @example $("span").parents("p")
1757 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1758 * @result [ <p><span>Hello</span></p> ]
1759 * @desc Find all parent elements of each span that is a paragraph.
1763 * @param String expr (optional) An expression to filter the ancestors with
1764 * @cat DOM/Traversing
1768 * Get a set of elements containing the unique next siblings of each of the
1769 * matched set of elements.
1771 * It only returns the very next sibling, not all next siblings.
1773 * Can be filtered with an optional expressions.
1775 * @example $("p").next()
1776 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1777 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1778 * @desc Find the very next sibling of each paragraph.
1780 * @example $("p").next(".selected")
1781 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1782 * @result [ <p class="selected">Hello Again</p> ]
1783 * @desc Find the very next sibling of each paragraph that has a class "selected".
1787 * @param String expr (optional) An expression to filter the next Elements with
1788 * @cat DOM/Traversing
1792 * Get a set of elements containing the unique previous siblings of each of the
1793 * matched set of elements.
1795 * Can be filtered with an optional expressions.
1797 * It only returns the immediately previous sibling, not all previous siblings.
1799 * @example $("p").prev()
1800 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1801 * @result [ <div><span>Hello Again</span></div> ]
1802 * @desc Find the very previous sibling of each paragraph.
1804 * @example $("p").prev(".selected")
1805 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1806 * @result [ <div><span>Hello</span></div> ]
1807 * @desc Find the very previous sibling of each paragraph that has a class "selected".
1811 * @param String expr (optional) An expression to filter the previous Elements with
1812 * @cat DOM/Traversing
1816 * Get a set of elements containing all of the unique siblings of each of the
1817 * matched set of elements.
1819 * Can be filtered with an optional expressions.
1821 * @example $("div").siblings()
1822 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1823 * @result [ <p>Hello</p>, <p>And Again</p> ]
1824 * @desc Find all siblings of each div.
1826 * @example $("div").siblings(".selected")
1827 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1828 * @result [ <p class="selected">Hello Again</p> ]
1829 * @desc Find all siblings with a class "selected" of each div.
1833 * @param String expr (optional) An expression to filter the sibling Elements with
1834 * @cat DOM/Traversing
1838 * Get a set of elements containing all of the unique children of each of the
1839 * matched set of elements.
1841 * Can be filtered with an optional expressions.
1843 * @example $("div").children()
1844 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1845 * @result [ <span>Hello Again</span> ]
1846 * @desc Find all children of each div.
1848 * @example $("div").children(".selected")
1849 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1850 * @result [ <p class="selected">Hello Again</p> ]
1851 * @desc Find all children with a class "selected" of each div.
1855 * @param String expr (optional) An expression to filter the child Elements with
1856 * @cat DOM/Traversing
1859 parent: "a.parentNode",
1860 parents: "jQuery.parents(a)",
1861 next: "jQuery.nth(a,2,'nextSibling')",
1862 prev: "jQuery.nth(a,2,'previousSibling')",
1863 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1864 children: "jQuery.sibling(a.firstChild)"
1866 jQuery.fn[ i ] = function(a) {
1867 var ret = jQuery.map(this,n);
1868 if ( a && typeof a == "string" )
1869 ret = jQuery.multiFilter(a,ret);
1870 return this.pushStack( ret );
1875 * Append all of the matched elements to another, specified, set of elements.
1876 * This operation is, essentially, the reverse of doing a regular
1877 * $(A).append(B), in that instead of appending B to A, you're appending
1880 * @example $("p").appendTo("#foo");
1881 * @before <p>I would like to say: </p><div id="foo"></div>
1882 * @result <div id="foo"><p>I would like to say: </p></div>
1883 * @desc Appends all paragraphs to the element with the ID "foo"
1887 * @param <Content> content Content to append to the selected element to.
1888 * @cat DOM/Manipulation
1889 * @see append(<Content>)
1893 * Prepend all of the matched elements to another, specified, set of elements.
1894 * This operation is, essentially, the reverse of doing a regular
1895 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1898 * @example $("p").prependTo("#foo");
1899 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1900 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1901 * @desc Prepends all paragraphs to the element with the ID "foo"
1905 * @param <Content> content Content to prepend to the selected element to.
1906 * @cat DOM/Manipulation
1907 * @see prepend(<Content>)
1911 * Insert all of the matched elements before another, specified, set of elements.
1912 * This operation is, essentially, the reverse of doing a regular
1913 * $(A).before(B), in that instead of inserting B before A, you're inserting
1916 * @example $("p").insertBefore("#foo");
1917 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1918 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1919 * @desc Same as $("#foo").before("p")
1921 * @name insertBefore
1923 * @param <Content> content Content to insert the selected element before.
1924 * @cat DOM/Manipulation
1925 * @see before(<Content>)
1929 * Insert all of the matched elements after another, specified, set of elements.
1930 * This operation is, essentially, the reverse of doing a regular
1931 * $(A).after(B), in that instead of inserting B after A, you're inserting
1934 * @example $("p").insertAfter("#foo");
1935 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1936 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1937 * @desc Same as $("#foo").after("p")
1941 * @param <Content> content Content to insert the selected element after.
1942 * @cat DOM/Manipulation
1943 * @see after(<Content>)
1948 prependTo: "prepend",
1949 insertBefore: "before",
1950 insertAfter: "after"
1952 jQuery.fn[ i ] = function(){
1954 return this.each(function(){
1955 for ( var j = 0, al = a.length; j < al; j++ )
1956 jQuery(a[j])[n]( this );
1962 * Remove an attribute from each of the matched elements.
1964 * @example $("input").removeAttr("disabled")
1965 * @before <input disabled="disabled"/>
1970 * @param String name The name of the attribute to remove.
1971 * @cat DOM/Attributes
1975 * Adds the specified class(es) to each of the set of matched elements.
1977 * @example $("p").addClass("selected")
1978 * @before <p>Hello</p>
1979 * @result [ <p class="selected">Hello</p> ]
1981 * @example $("p").addClass("selected highlight")
1982 * @before <p>Hello</p>
1983 * @result [ <p class="selected highlight">Hello</p> ]
1987 * @param String class One or more CSS classes to add to the elements
1988 * @cat DOM/Attributes
1989 * @see removeClass(String)
1993 * Removes all or the specified class(es) from the set of matched elements.
1995 * @example $("p").removeClass()
1996 * @before <p class="selected">Hello</p>
1997 * @result [ <p>Hello</p> ]
1999 * @example $("p").removeClass("selected")
2000 * @before <p class="selected first">Hello</p>
2001 * @result [ <p class="first">Hello</p> ]
2003 * @example $("p").removeClass("selected highlight")
2004 * @before <p class="highlight selected first">Hello</p>
2005 * @result [ <p class="first">Hello</p> ]
2009 * @param String class (optional) One or more CSS classes to remove from the elements
2010 * @cat DOM/Attributes
2011 * @see addClass(String)
2015 * Adds the specified class if it is not present, removes it if it is
2018 * @example $("p").toggleClass("selected")
2019 * @before <p>Hello</p><p class="selected">Hello Again</p>
2020 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2024 * @param String class A CSS class with which to toggle the elements
2025 * @cat DOM/Attributes
2029 * Removes all matched elements from the DOM. This does NOT remove them from the
2030 * jQuery object, allowing you to use the matched elements further.
2032 * Can be filtered with an optional expressions.
2034 * @example $("p").remove();
2035 * @before <p>Hello</p> how are <p>you?</p>
2038 * @example $("p").remove(".hello");
2039 * @before <p class="hello">Hello</p> how are <p>you?</p>
2040 * @result how are <p>you?</p>
2044 * @param String expr (optional) A jQuery expression to filter elements by.
2045 * @cat DOM/Manipulation
2049 * Removes all child nodes from the set of matched elements.
2051 * @example $("p").empty()
2052 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2053 * @result [ <p></p> ]
2057 * @cat DOM/Manipulation
2061 removeAttr: function( key ) {
2062 jQuery.attr( this, key, "" );
2063 this.removeAttribute( key );
2065 addClass: function(c){
2066 jQuery.className.add(this,c);
2068 removeClass: function(c){
2069 jQuery.className.remove(this,c);
2071 toggleClass: function( c ){
2072 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2074 remove: function(a){
2075 if ( !a || jQuery.filter( a, [this] ).r.length )
2076 this.parentNode.removeChild( this );
2079 while ( this.firstChild )
2080 this.removeChild( this.firstChild );
2083 jQuery.fn[ i ] = function() {
2084 return this.each( n, arguments );
2089 * Reduce the set of matched elements to a single element.
2090 * The position of the element in the set of matched elements
2091 * starts at 0 and goes to length - 1.
2093 * @example $("p").eq(1)
2094 * @before <p>This is just a test.</p><p>So is this</p>
2095 * @result [ <p>So is this</p> ]
2099 * @param Number pos The index of the element that you wish to limit to.
2104 * Reduce the set of matched elements to all elements before a given position.
2105 * The position of the element in the set of matched elements
2106 * starts at 0 and goes to length - 1.
2108 * @example $("p").lt(1)
2109 * @before <p>This is just a test.</p><p>So is this</p>
2110 * @result [ <p>This is just a test.</p> ]
2114 * @param Number pos Reduce the set to all elements below this position.
2119 * Reduce the set of matched elements to all elements after a given position.
2120 * The position of the element in the set of matched elements
2121 * starts at 0 and goes to length - 1.
2123 * @example $("p").gt(0)
2124 * @before <p>This is just a test.</p><p>So is this</p>
2125 * @result [ <p>So is this</p> ]
2129 * @param Number pos Reduce the set to all elements after this position.
2134 * Filter the set of elements to those that contain the specified text.
2136 * @example $("p").contains("test")
2137 * @before <p>This is just a test.</p><p>So is this</p>
2138 * @result [ <p>This is just a test.</p> ]
2142 * @param String str The string that will be contained within the text of an element.
2143 * @cat DOM/Traversing
2145 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2146 jQuery.fn[ n ] = function(num,fn) {
2147 return this.filter( ":" + n + "(" + num + ")", fn );
2152 * Get the current computed, pixel, width of the first matched element.
2154 * @example $("p").width();
2155 * @before <p>This is just a test.</p>
2164 * Set the CSS width of every matched element. If no explicit unit
2165 * was specified (like 'em' or '%') then "px" is added to the width.
2167 * @example $("p").width(20);
2168 * @before <p>This is just a test.</p>
2169 * @result <p style="width:20px;">This is just a test.</p>
2171 * @example $("p").width("20em");
2172 * @before <p>This is just a test.</p>
2173 * @result <p style="width:20em;">This is just a test.</p>
2177 * @param Number|String val Set the CSS property to the specified value.
2182 * Get the current computed, pixel, height of the first matched element.
2184 * @example $("p").height();
2185 * @before <p>This is just a test.</p>
2194 * Set the CSS width of every matched element. If no explicit unit
2195 * was specified (like 'em' or '%') then "px" is added to the width.
2197 * @example $("p").height(20);
2198 * @before <p>This is just a test.</p>
2199 * @result <p style="height:20px;">This is just a test.</p>
2201 * @example $("p").height("20em");
2202 * @before <p>This is just a test.</p>
2203 * @result <p style="height:20em;">This is just a test.</p>
2207 * @param Number|String val Set the CSS property to the specified value.
2211 jQuery.each( [ "height", "width" ], function(i,n){
2212 jQuery.fn[ n ] = function(h) {
2213 return h == undefined ?
2214 ( this.length ? jQuery.css( this[0], n ) : null ) :
2215 this.css( n, h.constructor == String ? h : h + "px" );