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
23 var jQuery = function(a,c) {
24 // Make sure that a selection was provided
27 // Shortcut for document ready
28 // Safari reports typeof on DOM NodeLists as a function
29 if ( typeof a == "function" && !a.nodeType && a[0] == undefined )
30 return jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
32 // Watch for when a jQuery object is passed as the selector
34 return jQuery( jQuery.makeArray( a ) );
36 // Watch for when a jQuery object is passed at the context
38 return jQuery( c ).find(a);
40 // If the context is global, return a new object
42 return new jQuery(a,c);
44 // Handle HTML strings
45 if ( typeof a == "string" ) {
46 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
47 if ( m ) a = jQuery.clean( [ m[1] ] );
50 // Watch for when an array is passed in
51 return this.setArray( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?
52 // Assume that it is an array of DOM Elements
53 jQuery.makeArray( a ) :
55 // Find the matching elements and save them for later
56 jQuery.find( a, c ) );
59 // Map over the $ in case of overwrite
60 if ( typeof $ != "undefined" )
63 // Map the jQuery namespace to the '$' one
67 * This function accepts a string containing a CSS or
68 * basic XPath selector which is then used to match a set of elements.
70 * The core functionality of jQuery centers around this function.
71 * Everything in jQuery is based upon this, or uses this in some way.
72 * The most basic use of this function is to pass in an expression
73 * (usually consisting of CSS or XPath), which then finds all matching
76 * By default, $() looks for DOM elements within the context of the
77 * current HTML document.
79 * @example $("div > p")
80 * @desc This finds all p elements that are children of a div element.
81 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
82 * @result [ <p>two</p> ]
84 * @example $("input:radio", document.forms[0])
85 * @desc Searches for all inputs of type radio within the first form in the document
87 * @example $("div", xml.responseXML)
88 * @desc This finds all div elements within the specified XML document.
91 * @param String expr An expression to search with
92 * @param Element context (optional) A DOM Element, or Document, representing the base context.
96 * @see $(Element<Array>)
100 * This function accepts a string of raw HTML.
102 * The HTML string is different from the traditional selectors in that
103 * it creates the DOM elements representing that HTML string, on the fly,
104 * to be (assumedly) inserted into the document later.
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.
119 * Wrap jQuery functionality around a specific DOM Element.
120 * This function also accepts XML Documents and Window objects
121 * as valid arguments (even though they are not DOM Elements).
123 * @example $(document).find("div > p")
124 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
125 * @result [ <p>two</p> ]
127 * @example $(document.body).background( "black" );
128 * @desc Sets the background color of the page to black.
131 * @param Element elem A DOM element to be encapsulated by a jQuery object.
137 * Wrap jQuery functionality around a set of DOM Elements.
139 * @example $( myForm.elements ).hide()
140 * @desc Hides all the input elements within a form
143 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
149 * A shorthand for $(document).ready(), allowing you to bind a function
150 * to be executed when the DOM document has finished loading. This function
151 * behaves just like $(document).ready(), in that it should be used to wrap
152 * all of the other $() operations on your page. While this function is,
153 * technically, chainable - there really isn't much use for chaining against it.
154 * You can have as many $(document).ready events on your page as you like.
156 * See ready(Function) for details about the ready event.
158 * @example $(function(){
159 * // Document is ready
161 * @desc Executes the function when the DOM is ready to be used.
164 * @param Function fn The function to execute when the DOM is ready.
170 * A means of creating a cloned copy of a jQuery object. This function
171 * copies the set of matched elements from one jQuery object and creates
172 * another, new, jQuery object containing the same elements.
174 * @example var div = $("div");
175 * $( div ).find("p");
176 * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div' (as would normally be the case if a simple div.find("p") was done).
179 * @param jQuery obj The jQuery object to be cloned.
184 jQuery.fn = jQuery.prototype = {
186 * The current version of jQuery.
197 * The number of elements currently matched.
199 * @example $("img").length;
200 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
210 * The number of elements currently matched.
212 * @example $("img").size();
213 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
227 * Access all matched elements. This serves as a backwards-compatible
228 * way of accessing all matched elements (other than the jQuery object
229 * itself, which is, in fact, an array of elements).
231 * @example $("img").get();
232 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
233 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
236 * @type Array<Element>
241 * Access a single matched element. num is used to access the
242 * Nth element matched.
244 * @example $("img").get(1);
245 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
246 * @result [ <img src="test1.jpg"/> ]
250 * @param Number num Access the element in the Nth position.
253 get: function( num ) {
254 return num == undefined ?
256 // Return a 'clean' array
257 jQuery.makeArray( this ) :
259 // Return just the object
264 * Set the jQuery object to an array of elements, while maintaining
267 * @example $("img").set([ document.body ]);
268 * @result $("img").set() == [ document.body ]
273 * @param Elements elems An array of elements
277 var ret = jQuery(this);
278 ret.prevObject = this;
279 return ret.setArray( a );
283 * Set the jQuery object to an array of elements. This operation is
284 * completely destructive - be sure to use .set() if you wish to maintain
287 * @example $("img").setArray([ document.body ]);
288 * @result $("img").setArray() == [ document.body ]
293 * @param Elements elems An array of elements
296 setArray: function( a ) {
298 [].push.apply( this, a );
303 * Execute a function within the context of every matched element.
304 * This means that every time the passed-in function is executed
305 * (which is once for every element matched) the 'this' keyword
306 * points to the specific element.
308 * Additionally, the function, when executed, is passed a single
309 * argument representing the position of the element in the matched
312 * @example $("img").each(function(i){
313 * this.src = "test" + i + ".jpg";
315 * @before <img/><img/>
316 * @result <img src="test0.jpg"/><img src="test1.jpg"/>
317 * @desc Iterates over two images and sets their src property
321 * @param Function fn A function to execute
324 each: function( fn, args ) {
325 return jQuery.each( this, fn, args );
329 * Searches every matched element for the object and returns
330 * the index of the element, if found, starting with zero.
331 * Returns -1 if the object wasn't found.
333 * @example $("*").index(document.getElementById('foobar'))
334 * @before <div id="foobar"></div><b></b><span id="foo"></span>
337 * @example $("*").index(document.getElementById('foo'))
338 * @before <div id="foobar"></div><b></b><span id="foo"></span>
341 * @example $("*").index(document.getElementById('bar'))
342 * @before <div id="foobar"></div><b></b><span id="foo"></span>
347 * @param Object obj Object to search for
350 index: function( obj ) {
352 this.each(function(i){
353 if ( this == obj ) pos = i;
359 * Access a property on the first matched element.
360 * This method makes it easy to retrieve a property value
361 * from the first matched element.
363 * @example $("img").attr("src");
364 * @before <img src="test.jpg"/>
369 * @param String name The name of the property to access.
374 * Set a key/value object as properties to all matched elements.
376 * This serves as the best way to set a large number of properties
377 * on all matched elements.
379 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
381 * @result <img src="test.jpg" alt="Test Image"/>
385 * @param Map properties Key/value pairs to set as object properties.
390 * Set a single property to a value, on all matched elements.
392 * Note that you can't set the name property of input elements in IE.
393 * Use $(html) or .append(html) or .html(html) to create elements
394 * on the fly including the name property.
396 * @example $("img").attr("src","test.jpg");
398 * @result <img src="test.jpg"/>
402 * @param String key The name of the property to set.
403 * @param Object value The value to set the property to.
406 attr: function( key, value, type ) {
407 // Check to see if we're setting style values
408 return typeof key != "string" || value != undefined ?
409 this.each(function(){
410 // See if we're setting a hash of styles
411 if ( value == undefined )
412 // Set all the styles
413 for ( var prop in key )
415 type ? this.style : this,
419 // See if we're setting a single key/value style
422 type ? this.style : this,
427 // Look for the case where we're accessing a style value
428 jQuery[ type || "attr" ]( this[0], key );
432 * Access a style property on the first matched element.
433 * This method makes it easy to retrieve a style property value
434 * from the first matched element.
436 * @example $("p").css("color");
437 * @before <p style="color:red;">Test Paragraph.</p>
439 * @desc Retrieves the color style of the first paragraph
441 * @example $("p").css("fontWeight");
442 * @before <p style="font-weight: bold;">Test Paragraph.</p>
444 * @desc Retrieves the font-weight style of the first paragraph.
445 * Note that for all style properties with a dash (like 'font-weight'), you have to
446 * write it in camelCase. In other words: Every time you have a '-' in a
447 * property, remove it and replace the next character with an uppercase
448 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
449 * borderStyle, borderBottomWidth etc.
453 * @param String name The name of the property to access.
458 * Set a key/value object as style properties to all matched elements.
460 * This serves as the best way to set a large number of style properties
461 * on all matched elements.
463 * @example $("p").css({ color: "red", background: "blue" });
464 * @before <p>Test Paragraph.</p>
465 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
469 * @param Map properties Key/value pairs to set as style properties.
474 * Set a single style property to a value, on all matched elements.
476 * @example $("p").css("color","red");
477 * @before <p>Test Paragraph.</p>
478 * @result <p style="color:red;">Test Paragraph.</p>
479 * @desc Changes the color of all paragraphs to red
483 * @param String key The name of the property to set.
484 * @param Object value The value to set the property to.
487 css: function( key, value ) {
488 return this.attr( key, value, "curCSS" );
492 * Retrieve the text contents of all matched elements. The result is
493 * a string that contains the combined text contents of all matched
494 * elements. This method works on both HTML and XML documents.
496 * @example $("p").text();
497 * @before <p>Test Paragraph.</p>
498 * @result Test Paragraph.
506 * Set the text contents of all matched elements. This has the same
507 * effect as calling .html() with your specified string.
509 * @example $("p").text("Some new text.");
510 * @before <p>Test Paragraph.</p>
511 * @result <p>Some new text.</p>
513 * @param String val The text value to set the contents of the element to.
520 // A surprisingly high number of people expect the
521 // .text() method to do this, so lets do it!
522 if ( typeof e == "string" )
523 return this.html( e );
527 for ( var j = 0, el = e.length; j < el; j++ ) {
528 var r = e[j].childNodes;
529 for ( var i = 0, rl = r.length; i < rl; i++ )
530 if ( r[i].nodeType != 8 )
531 t += r[i].nodeType != 1 ?
532 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
538 * Wrap all matched elements with a structure of other elements.
539 * This wrapping process is most useful for injecting additional
540 * stucture into a document, without ruining the original semantic
541 * qualities of a document.
543 * This works by going through the first element
544 * provided (which is generated, on the fly, from the provided HTML)
545 * and finds the deepest ancestor element within its
546 * structure - it is that element that will en-wrap everything else.
548 * This does not work with elements that contain text. Any necessary text
549 * must be added after the wrapping is done.
551 * @example $("p").wrap("<div class='wrap'></div>");
552 * @before <p>Test Paragraph.</p>
553 * @result <div class='wrap'><p>Test Paragraph.</p></div>
557 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
558 * @cat DOM/Manipulation
562 * Wrap all matched elements with a structure of other elements.
563 * This wrapping process is most useful for injecting additional
564 * stucture into a document, without ruining the original semantic
565 * qualities of a document.
567 * This works by going through the first element
568 * provided and finding the deepest ancestor element within its
569 * structure - it is that element that will en-wrap everything else.
571 * This does not work with elements that contain text. Any necessary text
572 * must be added after the wrapping is done.
574 * @example $("p").wrap( document.getElementById('content') );
575 * @before <p>Test Paragraph.</p><div id="content"></div>
576 * @result <div id="content"><p>Test Paragraph.</p></div>
580 * @param Element elem A DOM element that will be wrapped.
581 * @cat DOM/Manipulation
584 // The elements to wrap the target around
585 var a = jQuery.clean(arguments);
587 // Wrap each of the matched elements individually
588 return this.each(function(){
589 // Clone the structure that we're using to wrap
590 var b = a[0].cloneNode(true);
592 // Insert it before the element to be wrapped
593 this.parentNode.insertBefore( b, this );
595 // Find the deepest point in the wrap structure
596 while ( b.firstChild )
599 // Move the matched element to within the wrap structure
600 b.appendChild( this );
605 * Append content to the inside of every matched element.
607 * This operation is similar to doing an appendChild to all the
608 * specified elements, adding them into the document.
610 * @example $("p").append("<b>Hello</b>");
611 * @before <p>I would like to say: </p>
612 * @result <p>I would like to say: <b>Hello</b></p>
614 * @example $("p").append( $("#foo")[0] );
615 * @before <p>I would like to say: </p><b id="foo">Hello</b>
616 * @result <p>I would like to say: <b id="foo">Hello</b></p>
618 * @example $("p").append( $("b") );
619 * @before <p>I would like to say: </p><b>Hello</b>
620 * @result <p>I would like to say: <b>Hello</b></p>
624 * @param <Content> content Content to append to the target
625 * @cat DOM/Manipulation
626 * @see prepend(<Content>)
627 * @see before(<Content>)
628 * @see after(<Content>)
631 return this.domManip(arguments, true, 1, function(a){
632 this.appendChild( a );
637 * Prepend content to the inside of every matched element.
639 * This operation is the best way to insert elements
640 * inside, at the beginning, of all matched elements.
642 * @example $("p").prepend("<b>Hello</b>");
643 * @before <p>I would like to say: </p>
644 * @result <p><b>Hello</b>I would like to say: </p>
646 * @example $("p").prepend( $("#foo")[0] );
647 * @before <p>I would like to say: </p><b id="foo">Hello</b>
648 * @result <p><b id="foo">Hello</b>I would like to say: </p>
650 * @example $("p").prepend( $("b") );
651 * @before <p>I would like to say: </p><b>Hello</b>
652 * @result <p><b>Hello</b>I would like to say: </p>
656 * @param <Content> content Content to prepend to the target.
657 * @cat DOM/Manipulation
658 * @see append(<Content>)
659 * @see before(<Content>)
660 * @see after(<Content>)
662 prepend: function() {
663 return this.domManip(arguments, true, -1, function(a){
664 this.insertBefore( a, this.firstChild );
669 * Insert content before each of the matched elements.
671 * @example $("p").before("<b>Hello</b>");
672 * @before <p>I would like to say: </p>
673 * @result <b>Hello</b><p>I would like to say: </p>
675 * @example $("p").before( $("#foo")[0] );
676 * @before <p>I would like to say: </p><b id="foo">Hello</b>
677 * @result <b id="foo">Hello</b><p>I would like to say: </p>
679 * @example $("p").before( $("b") );
680 * @before <p>I would like to say: </p><b>Hello</b>
681 * @result <b>Hello</b><p>I would like to say: </p>
685 * @param <Content> content Content to insert before each target.
686 * @cat DOM/Manipulation
687 * @see append(<Content>)
688 * @see prepend(<Content>)
689 * @see after(<Content>)
692 return this.domManip(arguments, false, 1, function(a){
693 this.parentNode.insertBefore( a, this );
698 * Insert content after each of the matched elements.
700 * @example $("p").after("<b>Hello</b>");
701 * @before <p>I would like to say: </p>
702 * @result <p>I would like to say: </p><b>Hello</b>
704 * @example $("p").after( $("#foo")[0] );
705 * @before <b id="foo">Hello</b><p>I would like to say: </p>
706 * @result <p>I would like to say: </p><b id="foo">Hello</b>
708 * @example $("p").after( $("b") );
709 * @before <b>Hello</b><p>I would like to say: </p>
710 * @result <p>I would like to say: </p><b>Hello</b>
714 * @param <Content> content Content to insert after each target.
715 * @cat DOM/Manipulation
716 * @see append(<Content>)
717 * @see prepend(<Content>)
718 * @see before(<Content>)
721 return this.domManip(arguments, false, -1, function(a){
722 this.parentNode.insertBefore( a, this.nextSibling );
727 * End the most recent 'destructive' operation, reverting the list of matched elements
728 * back to its previous state. After an end operation, the list of matched elements will
729 * revert to the last state of matched elements.
731 * If there was no destructive operation before, an empty set is returned.
733 * @example $("p").find("span").end();
734 * @before <p><span>Hello</span>, how are you?</p>
735 * @result $("p").find("span").end() == [ <p>...</p> ]
739 * @cat DOM/Traversing
742 return this.prevObject || jQuery([]);
746 * Searches for all elements that match the specified expression.
747 * This method is the optimal way of finding additional descendant
748 * elements with which to process.
750 * All searching is done using a jQuery expression. The expression can be
751 * written using CSS 1-3 Selector syntax, or basic XPath.
753 * @example $("p").find("span");
754 * @before <p><span>Hello</span>, how are you?</p>
755 * @result $("p").find("span") == [ <span>Hello</span> ]
759 * @param String expr An expression to search with.
760 * @cat DOM/Traversing
763 return this.set( jQuery.map( this, function(a){
764 return jQuery.find(t,a);
769 * Create cloned copies of all matched DOM Elements. This does
770 * not create a cloned copy of this particular jQuery object,
771 * instead it creates duplicate copies of all DOM Elements.
772 * This is useful for moving copies of the elements to another
773 * location in the DOM.
775 * @example $("b").clone().prependTo("p");
776 * @before <b>Hello</b><p>, how are you?</p>
777 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
781 * @cat DOM/Manipulation
783 clone: function(deep) {
784 return this.set( jQuery.map( this, function(a){
785 return a.cloneNode( deep != undefined ? deep : true );
790 * Removes all elements from the set of matched elements that do not
791 * match the specified expression. This method is used to narrow down
792 * the results of a search.
794 * All searching is done using a jQuery expression. The expression
795 * can be written using CSS 1-3 Selector syntax, or basic XPath.
797 * @example $("p").filter(".selected")
798 * @before <p class="selected">Hello</p><p>How are you?</p>
799 * @result [ <p class="selected">Hello</p> ]
803 * @param String expr An expression to search with.
804 * @cat DOM/Traversing
808 * Removes all elements from the set of matched elements that do not
809 * pass the specified filter. This method is used to narrow down
810 * the results of a search.
812 * The elements to filter are passed as the first argument, their
813 * index inside the set as the second.
815 * @example $("p").filter(function(element, index) {
816 * return $("ol", element).length == 0;
818 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
819 * @result [ <p>How are you?</p> ]
820 * @desc Remove all elements that have a child ol element
824 * @param Function filter A function to use for filtering
825 * @cat DOM/Traversing
829 * Removes all elements from the set of matched elements that do not
830 * match at least one of the expressions passed to the function. This
831 * method is used when you want to filter the set of matched elements
832 * through more than one expression.
834 * Elements will be retained in the jQuery object if they match at
835 * least one of the expressions passed.
837 * @example $("p").filter([".selected", ":first"])
838 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
839 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
843 * @param Array<String> exprs A set of expressions to evaluate against
844 * @cat DOM/Traversing
846 filter: function(t) {
848 t.constructor == Array &&
849 jQuery.map(this,function(a){
850 for ( var i = 0, tl = t.length; i < tl; i++ )
851 if ( jQuery.filter(t[i],[a]).r.length )
856 t.constructor == Boolean &&
857 ( t ? this.get() : [] ) ||
859 typeof t == "function" &&
860 jQuery.grep( this, t ) ||
862 jQuery.filter(t,this).r );
866 * Removes the specified Element from the set of matched elements. This
867 * method is used to remove a single Element from a jQuery object.
869 * @example $("p").not( document.getElementById("selected") )
870 * @before <p>Hello</p><p id="selected">Hello Again</p>
871 * @result [ <p>Hello</p> ]
875 * @param Element el An element to remove from the set
876 * @cat DOM/Traversing
880 * Removes elements matching the specified expression from the set
881 * of matched elements. This method is used to remove one or more
882 * elements from a jQuery object.
884 * @example $("p").not("#selected")
885 * @before <p>Hello</p><p id="selected">Hello Again</p>
886 * @result [ <p>Hello</p> ]
890 * @param String expr An expression with which to remove matching elements
891 * @cat DOM/Traversing
894 return this.set( typeof t == "string" ?
895 jQuery.filter(t,this,true).r :
896 jQuery.grep(this,function(a){ return a != t; }) );
900 * Adds the elements matched by the expression to the jQuery object. This
901 * can be used to concatenate the result sets of two expressions.
903 * @example $("p").add("span")
904 * @before <p>Hello</p><p><span>Hello Again</span></p>
905 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
909 * @param String expr An expression whose matched elements are added
910 * @cat DOM/Traversing
914 * Adds each of the Elements in the array to the set of matched elements.
915 * This is used to add a set of Elements to a jQuery object.
917 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
918 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
919 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
923 * @param Array<Element> els An array of Elements to add
924 * @cat DOM/Traversing
928 * Adds a single Element to the set of matched elements. This is used to
929 * add a single Element to a jQuery object.
931 * @example $("p").add( document.getElementById("a") )
932 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
933 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
937 * @param Element el An Element to add
938 * @cat DOM/Traversing
941 return this.set( jQuery.merge(
942 this.get(), typeof t == "string" ?
944 t.constructor == Array ? t : [t] ) );
948 * Checks the current selection against an expression and returns true,
949 * if at least one element of the selection fits the given expression.
950 * Does return false, if no element fits or the expression is not valid.
952 * @example $("input[@type='checkbox']").parent().is("form")
953 * @before <form><input type="checkbox" /></form>
955 * @desc Returns true, because the parent of the input is a form element
957 * @example $("input[@type='checkbox']").parent().is("form")
958 * @before <form><p><input type="checkbox" /></p></form>
960 * @desc Returns false, because the parent of the input is a p element
962 * @example $("form").is(null)
963 * @before <form></form>
965 * @desc An invalid expression always returns false.
969 * @param String expr The expression with which to filter
970 * @cat DOM/Traversing
973 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
980 * @param Boolean table Insert TBODY in TABLEs if one is not found.
981 * @param Number dir If dir<0, process args in reverse order.
982 * @param Function fn The function doing the DOM manipulation.
986 domManip: function(args, table, dir, fn){
987 var clone = this.length > 1;
988 var a = jQuery.clean(args);
992 return this.each(function(){
995 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
996 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
998 for ( var i = 0, al = a.length; i < al; i++ )
999 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1006 * Extends the jQuery object itself. Can be used to add functions into
1007 * the jQuery namespace and to add plugin methods (plugins).
1009 * @example jQuery.fn.extend({
1010 * check: function() {
1011 * return this.each(function() { this.checked = true; });
1013 * uncheck: function() {
1014 * return this.each(function() { this.checked = false; });
1017 * $("input[@type=checkbox]").check();
1018 * $("input[@type=radio]").uncheck();
1019 * @desc Adds two plugin methods.
1021 * @example jQuery.extend({
1022 * min: function(a, b) { return a < b ? a : b; },
1023 * max: function(a, b) { return a > b ? a : b; }
1025 * @desc Adds two functions into the jQuery namespace
1028 * @param Object prop The object that will be merged into the jQuery object
1034 * Extend one object with one or more others, returning the original,
1035 * modified, object. This is a great utility for simple inheritance.
1037 * @example var settings = { validate: false, limit: 5, name: "foo" };
1038 * var options = { validate: true, name: "bar" };
1039 * jQuery.extend(settings, options);
1040 * @result settings == { validate: true, limit: 5, name: "bar" }
1041 * @desc Merge settings and options, modifying settings
1043 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1044 * var options = { validate: true, name: "bar" };
1045 * var settings = jQuery.extend({}, defaults, options);
1046 * @result settings == { validate: true, limit: 5, name: "bar" }
1047 * @desc Merge defaults and options, without modifying the defaults
1050 * @param Object target The object to extend
1051 * @param Object prop1 The object that will be merged into the first.
1052 * @param Object propN (optional) More objects to merge into the first
1056 jQuery.extend = jQuery.fn.extend = function() {
1057 // copy reference to target object
1058 var target = arguments[0],
1061 // extend jQuery itself if only one argument is passed
1062 if ( arguments.length == 1 ) {
1067 while (prop = arguments[a++])
1068 // Extend the base object
1069 for ( var i in prop ) target[i] = prop[i];
1071 // Return the modified object
1083 jQuery.initDone = true;
1085 jQuery.each( jQuery.macros.axis, function(i,n){
1086 jQuery.fn[ i ] = function(a) {
1087 var ret = jQuery.map(this,n);
1088 if ( a && typeof a == "string" )
1089 ret = jQuery.filter(a,ret).r;
1090 return this.set( ret );
1094 jQuery.each( jQuery.macros.to, function(i,n){
1095 jQuery.fn[ i ] = function(){
1097 return this.each(function(){
1098 for ( var j = 0, al = a.length; j < al; j++ )
1099 jQuery(a[j])[n]( this );
1104 jQuery.each( jQuery.macros.each, function(i,n){
1105 jQuery.fn[ i ] = function() {
1106 return this.each( n, arguments );
1110 jQuery.each( jQuery.macros.filter, function(i,n){
1111 jQuery.fn[ n ] = function(num,fn) {
1112 return this.filter( ":" + n + "(" + num + ")", fn );
1116 jQuery.each( jQuery.macros.attr, function(i,n){
1118 jQuery.fn[ i ] = function(h) {
1119 return h == undefined ?
1120 this.length ? this[0][n] : null :
1125 jQuery.each( jQuery.macros.css, function(i,n){
1126 jQuery.fn[ n ] = function(h) {
1127 return h == undefined ?
1128 ( this.length ? jQuery.css( this[0], n ) : null ) :
1136 * A generic iterator function, which can be used to seemlessly
1137 * iterate over both objects and arrays. This function is not the same
1138 * as $().each() - which is used to iterate, exclusively, over a jQuery
1139 * object. This function can be used to iterate over anything.
1141 * @example $.each( [0,1,2], function(i){
1142 * alert( "Item #" + i + ": " + this );
1144 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1146 * @example $.each( { name: "John", lang: "JS" }, function(i){
1147 * alert( "Name: " + i + ", Value: " + this );
1149 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1152 * @param Object obj The object, or array, to iterate over.
1153 * @param Function fn The function that will be executed on every object.
1157 // args is for internal usage only
1158 each: function( obj, fn, args ) {
1159 if ( obj.length == undefined )
1160 for ( var i in obj )
1161 fn.apply( obj[i], args || [i, obj[i]] );
1163 for ( var i = 0, ol = obj.length; i < ol; i++ )
1164 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1169 add: function( elem, c ){
1170 jQuery.each( c.split(/\s+/), function(i, cur){
1171 if ( !jQuery.className.has( elem.className, cur ) )
1172 elem.className += ( elem.className ? " " : "" ) + cur;
1175 remove: function( elem, c ){
1176 elem.className = c ?
1177 jQuery.grep( elem.className.split(/\s+/), function(cur){
1178 return !jQuery.className.has( c, cur );
1181 has: function( classes, c ){
1182 return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
1187 * Swap in/out style options.
1190 swap: function(e,o,f) {
1191 for ( var i in o ) {
1192 e.style["old"+i] = e.style[i];
1197 e.style[i] = e.style["old"+i];
1200 css: function(e,p) {
1201 if ( p == "height" || p == "width" ) {
1202 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1204 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1205 old["padding" + d[i]] = 0;
1206 old["border" + d[i] + "Width"] = 0;
1209 jQuery.swap( e, old, function() {
1210 if (jQuery.css(e,"display") != "none") {
1211 oHeight = e.offsetHeight;
1212 oWidth = e.offsetWidth;
1214 e = jQuery(e.cloneNode(true))
1215 .find(":radio").removeAttr("checked").end()
1217 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1218 }).appendTo(e.parentNode)[0];
1220 var parPos = jQuery.css(e.parentNode,"position");
1221 if ( parPos == "" || parPos == "static" )
1222 e.parentNode.style.position = "relative";
1224 oHeight = e.clientHeight;
1225 oWidth = e.clientWidth;
1227 if ( parPos == "" || parPos == "static" )
1228 e.parentNode.style.position = "static";
1230 e.parentNode.removeChild(e);
1234 return p == "height" ? oHeight : oWidth;
1237 return jQuery.curCSS( e, p );
1240 curCSS: function(elem, prop, force) {
1243 if (prop == 'opacity' && jQuery.browser.msie)
1244 return jQuery.attr(elem.style, 'opacity');
1246 if (prop == "float" || prop == "cssFloat")
1247 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1249 if (!force && elem.style[prop]) {
1251 ret = elem.style[prop];
1253 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1255 if (prop == "cssFloat" || prop == "styleFloat")
1258 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1259 var cur = document.defaultView.getComputedStyle(elem, null);
1262 ret = cur.getPropertyValue(prop);
1263 else if ( prop == 'display' )
1266 jQuery.swap(elem, { display: 'block' }, function() {
1267 var c = document.defaultView.getComputedStyle(this, '');
1268 ret = c && c.getPropertyValue(prop) || '';
1271 } else if (elem.currentStyle) {
1273 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1274 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1281 clean: function(a) {
1283 for ( var i = 0, al = a.length; i < al; i++ ) {
1285 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
1286 // Trim whitespace, otherwise indexOf won't work as expected
1287 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6),
1288 div = document.createElement("div"), wrap = [0,"",""];
1290 if ( s.substring(0,4) == "<opt" ) // option or optgroup
1291 wrap = [1, "<select>", "</select>"];
1292 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" )
1293 wrap = [1, "<table>", "</table>"];
1294 else if ( s3 == "<tr" )
1295 wrap = [2, "<table><tbody>", "</tbody></table>"];
1296 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above
1297 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1299 // Go to html and back, then peel off extra wrappers
1300 div.innerHTML = wrap[1] + s + wrap[2];
1301 while ( wrap[0]-- ) div = div.firstChild;
1303 // Remove IE's autoinserted <tbody> from table fragments
1304 if ( jQuery.browser.msie ) {
1306 // String was a <table>, *may* have spurious <tbody>
1307 if ( s6 == "<table" && s.indexOf("<tbody") < 0 )
1308 tb = div.firstChild && div.firstChild.childNodes;
1309 // String was a bare <thead> or <tfoot>
1310 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1311 tb = div.childNodes;
1313 for ( var n = tb.length-1; n >= 0 ; --n )
1314 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1315 tb[n].parentNode.removeChild(tb[n]);
1319 arg = div.childNodes;
1323 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1324 for ( var n = 0, argl = arg.length; n < argl; n++ ) // Handles Array, jQuery, DOM NodeList collections
1327 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1333 attr: function(elem, name, value){
1336 "class": "className",
1337 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1338 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1339 innerHTML: "innerHTML",
1340 className: "className",
1342 disabled: "disabled",
1344 readonly: "readOnly",
1345 selected: "selected"
1348 // IE actually uses filters for opacity ... elem is actually elem.style
1349 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1350 // IE has trouble with opacity if it does not have layout
1351 // Force it by setting the zoom level
1354 // Set the alpha filter to set the opacity
1355 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1356 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1358 } else if ( name == "opacity" && jQuery.browser.msie ) {
1359 return elem.filter ?
1360 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1363 // Mozilla doesn't play well with opacity 1
1364 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1367 // Certain attributes only work when accessed via the old DOM 0 way
1369 if ( value != undefined ) elem[fix[name]] = value;
1370 return elem[fix[name]];
1372 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1373 return elem.getAttributeNode(name).nodeValue;
1375 // IE elem.getAttribute passes even for style
1376 } else if ( elem.tagName ) {
1377 if ( value != undefined ) elem.setAttribute( name, value );
1378 return elem.getAttribute( name );
1381 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1382 if ( value != undefined ) elem[name] = value;
1388 * Remove the whitespace from the beginning and end of a string.
1390 * @example $.trim(" hello, how are you? ");
1391 * @result "hello, how are you?"
1395 * @param String str The string to trim.
1399 return t.replace(/^\s+|\s+$/g, "");
1402 makeArray: function( a ) {
1405 if ( a.constructor != Array ) {
1406 for ( var i = 0, al = a.length; i < al; i++ )
1414 inArray: function( b, a ) {
1415 for ( var i = 0, al = a.length; i < al; i++ )
1422 * Merge two arrays together, removing all duplicates. The final order
1423 * or the new array is: All the results from the first array, followed
1424 * by the unique results from the second array.
1426 * @example $.merge( [0,1,2], [2,3,4] )
1427 * @result [0,1,2,3,4]
1429 * @example $.merge( [3,2,1], [4,3,2] )
1434 * @param Array first The first array to merge.
1435 * @param Array second The second array to merge.
1438 merge: function(first, second) {
1439 var r = [].slice.call( first, 0 );
1441 // Now check for duplicates between the two arrays
1442 // and only add the unique items
1443 for ( var i = 0, sl = second.length; i < sl; i++ ) {
1444 // Check for duplicates
1445 if ( jQuery.inArray( second[i], r ) == -1 )
1446 // The item is unique, add it
1447 first.push( second[i] );
1454 * Filter items out of an array, by using a filter function.
1455 * The specified function will be passed two arguments: The
1456 * current array item and the index of the item in the array. The
1457 * function should return 'true' if you wish to keep the item in
1458 * the array, false if it should be removed.
1460 * @example $.grep( [0,1,2], function(i){
1467 * @param Array array The Array to find items in.
1468 * @param Function fn The function to process each item against.
1469 * @param Boolean inv Invert the selection - select the opposite of the function.
1472 grep: function(elems, fn, inv) {
1473 // If a string is passed in for the function, make a function
1474 // for it (a handy shortcut)
1475 if ( typeof fn == "string" )
1476 fn = new Function("a","i","return " + fn);
1480 // Go through the array, only saving the items
1481 // that pass the validator function
1482 for ( var i = 0, el = elems.length; i < el; i++ )
1483 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1484 result.push( elems[i] );
1490 * Translate all items in an array to another array of items.
1491 * The translation function that is provided to this method is
1492 * called for each item in the array and is passed one argument:
1493 * The item to be translated. The function can then return:
1494 * The translated value, 'null' (to remove the item), or
1495 * an array of values - which will be flattened into the full array.
1497 * @example $.map( [0,1,2], function(i){
1502 * @example $.map( [0,1,2], function(i){
1503 * return i > 0 ? i + 1 : null;
1507 * @example $.map( [0,1,2], function(i){
1508 * return [ i, i + 1 ];
1510 * @result [0, 1, 1, 2, 2, 3]
1514 * @param Array array The Array to translate.
1515 * @param Function fn The function to process each item against.
1518 map: function(elems, fn) {
1519 // If a string is passed in for the function, make a function
1520 // for it (a handy shortcut)
1521 if ( typeof fn == "string" )
1522 fn = new Function("a","return " + fn);
1524 var result = [], r = [];
1526 // Go through the array, translating each of the items to their
1527 // new value (or values).
1528 for ( var i = 0, el = elems.length; i < el; i++ ) {
1529 var val = fn(elems[i],i);
1531 if ( val !== null && val != undefined ) {
1532 if ( val.constructor != Array ) val = [val];
1533 result = result.concat( val );
1537 var r = [ result[0] ];
1539 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1540 for ( var j = 0; j < i; j++ )
1541 if ( result[i] == r[j] )
1544 r.push( result[i] );
1552 * Contains flags for the useragent, read from navigator.userAgent.
1553 * Available flags are: safari, opera, msie, mozilla
1554 * This property is available before the DOM is ready, therefore you can
1555 * use it to add ready events only for certain browsers.
1557 * There are situations where object detections is not reliable enough, in that
1558 * cases it makes sense to use browser detection. Simply try to avoid both!
1560 * A combination of browser and object detection yields quite reliable results.
1562 * @example $.browser.msie
1563 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1565 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1566 * @desc Alerts "this is safari!" only for safari browsers
1575 * Wheather the W3C compliant box model is being used.
1583 var b = navigator.userAgent.toLowerCase();
1585 // Figure out what browser is being used
1587 safari: /webkit/.test(b),
1588 opera: /opera/.test(b),
1589 msie: /msie/.test(b) && !/opera/.test(b),
1590 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1593 // Check to see if the W3C box model is being used
1594 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1600 * Append all of the matched elements to another, specified, set of elements.
1601 * This operation is, essentially, the reverse of doing a regular
1602 * $(A).append(B), in that instead of appending B to A, you're appending
1605 * @example $("p").appendTo("#foo");
1606 * @before <p>I would like to say: </p><div id="foo"></div>
1607 * @result <div id="foo"><p>I would like to say: </p></div>
1611 * @param String expr A jQuery expression of elements to match.
1612 * @cat DOM/Manipulation
1617 * Prepend all of the matched elements to another, specified, set of elements.
1618 * This operation is, essentially, the reverse of doing a regular
1619 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1622 * @example $("p").prependTo("#foo");
1623 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1624 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1628 * @param String expr A jQuery expression of elements to match.
1629 * @cat DOM/Manipulation
1631 prependTo: "prepend",
1634 * Insert all of the matched elements before another, specified, set of elements.
1635 * This operation is, essentially, the reverse of doing a regular
1636 * $(A).before(B), in that instead of inserting B before A, you're inserting
1639 * @example $("p").insertBefore("#foo");
1640 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1641 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1643 * @name insertBefore
1645 * @param String expr A jQuery expression of elements to match.
1646 * @cat DOM/Manipulation
1648 insertBefore: "before",
1651 * Insert all of the matched elements after another, specified, set of elements.
1652 * This operation is, essentially, the reverse of doing a regular
1653 * $(A).after(B), in that instead of inserting B after A, you're inserting
1656 * @example $("p").insertAfter("#foo");
1657 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1658 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1662 * @param String expr A jQuery expression of elements to match.
1663 * @cat DOM/Manipulation
1665 insertAfter: "after"
1669 * Get the current CSS width of the first matched element.
1671 * @example $("p").width();
1672 * @before <p>This is just a test.</p>
1681 * Set the CSS width of every matched element. Be sure to include
1682 * the "px" (or other unit of measurement) after the number that you
1683 * specify, otherwise you might get strange results.
1685 * @example $("p").width("20px");
1686 * @before <p>This is just a test.</p>
1687 * @result <p style="width:20px;">This is just a test.</p>
1691 * @param String val Set the CSS property to the specified value.
1696 * Get the current CSS height of the first matched element.
1698 * @example $("p").height();
1699 * @before <p>This is just a test.</p>
1708 * Set the CSS height of every matched element. Be sure to include
1709 * the "px" (or other unit of measurement) after the number that you
1710 * specify, otherwise you might get strange results.
1712 * @example $("p").height("20px");
1713 * @before <p>This is just a test.</p>
1714 * @result <p style="height:20px;">This is just a test.</p>
1718 * @param String val Set the CSS property to the specified value.
1723 * Get the current CSS top of the first matched element.
1725 * @example $("p").top();
1726 * @before <p>This is just a test.</p>
1735 * Set the CSS top of every matched element. Be sure to include
1736 * the "px" (or other unit of measurement) after the number that you
1737 * specify, otherwise you might get strange results.
1739 * @example $("p").top("20px");
1740 * @before <p>This is just a test.</p>
1741 * @result <p style="top:20px;">This is just a test.</p>
1745 * @param String val Set the CSS property to the specified value.
1750 * Get the current CSS left of the first matched element.
1752 * @example $("p").left();
1753 * @before <p>This is just a test.</p>
1762 * Set the CSS left of every matched element. Be sure to include
1763 * the "px" (or other unit of measurement) after the number that you
1764 * specify, otherwise you might get strange results.
1766 * @example $("p").left("20px");
1767 * @before <p>This is just a test.</p>
1768 * @result <p style="left:20px;">This is just a test.</p>
1772 * @param String val Set the CSS property to the specified value.
1777 * Get the current CSS position of the first matched element.
1779 * @example $("p").position();
1780 * @before <p>This is just a test.</p>
1789 * Set the CSS position of every matched element.
1791 * @example $("p").position("relative");
1792 * @before <p>This is just a test.</p>
1793 * @result <p style="position:relative;">This is just a test.</p>
1797 * @param String val Set the CSS property to the specified value.
1802 * Get the current CSS float of the first matched element.
1804 * @example $("p").float();
1805 * @before <p>This is just a test.</p>
1814 * Set the CSS float of every matched element.
1816 * @example $("p").float("left");
1817 * @before <p>This is just a test.</p>
1818 * @result <p style="float:left;">This is just a test.</p>
1822 * @param String val Set the CSS property to the specified value.
1827 * Get the current CSS overflow of the first matched element.
1829 * @example $("p").overflow();
1830 * @before <p>This is just a test.</p>
1839 * Set the CSS overflow of every matched element.
1841 * @example $("p").overflow("auto");
1842 * @before <p>This is just a test.</p>
1843 * @result <p style="overflow:auto;">This is just a test.</p>
1847 * @param String val Set the CSS property to the specified value.
1852 * Get the current CSS color of the first matched element.
1854 * @example $("p").color();
1855 * @before <p>This is just a test.</p>
1864 * Set the CSS color of every matched element.
1866 * @example $("p").color("blue");
1867 * @before <p>This is just a test.</p>
1868 * @result <p style="color:blue;">This is just a test.</p>
1872 * @param String val Set the CSS property to the specified value.
1877 * Get the current CSS background of the first matched element.
1879 * @example $("p").background();
1880 * @before <p style="background:blue;">This is just a test.</p>
1889 * Set the CSS background of every matched element.
1891 * @example $("p").background("blue");
1892 * @before <p>This is just a test.</p>
1893 * @result <p style="background:blue;">This is just a test.</p>
1897 * @param String val Set the CSS property to the specified value.
1901 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1904 * Reduce the set of matched elements to a single element.
1905 * The position of the element in the set of matched elements
1906 * starts at 0 and goes to length - 1.
1908 * @example $("p").eq(1)
1909 * @before <p>This is just a test.</p><p>So is this</p>
1910 * @result [ <p>So is this</p> ]
1914 * @param Number pos The index of the element that you wish to limit to.
1919 * Reduce the set of matched elements to all elements before a given position.
1920 * The position of the element in the set of matched elements
1921 * starts at 0 and goes to length - 1.
1923 * @example $("p").lt(1)
1924 * @before <p>This is just a test.</p><p>So is this</p>
1925 * @result [ <p>This is just a test.</p> ]
1929 * @param Number pos Reduce the set to all elements below this position.
1934 * Reduce the set of matched elements to all elements after a given position.
1935 * The position of the element in the set of matched elements
1936 * starts at 0 and goes to length - 1.
1938 * @example $("p").gt(0)
1939 * @before <p>This is just a test.</p><p>So is this</p>
1940 * @result [ <p>So is this</p> ]
1944 * @param Number pos Reduce the set to all elements after this position.
1949 * Filter the set of elements to those that contain the specified text.
1951 * @example $("p").contains("test")
1952 * @before <p>This is just a test.</p><p>So is this</p>
1953 * @result [ <p>This is just a test.</p> ]
1957 * @param String str The string that will be contained within the text of an element.
1958 * @cat DOM/Traversing
1961 filter: [ "eq", "lt", "gt", "contains" ],
1965 * Get the current value of the first matched element.
1967 * @example $("input").val();
1968 * @before <input type="text" value="some text"/>
1969 * @result "some text"
1973 * @cat DOM/Attributes
1977 * Set the value of every matched element.
1979 * @example $("input").val("test");
1980 * @before <input type="text" value="some text"/>
1981 * @result <input type="text" value="test"/>
1985 * @param String val Set the property to the specified value.
1986 * @cat DOM/Attributes
1991 * Get the html contents of the first matched element.
1992 * This property is not available on XML documents.
1994 * @example $("div").html();
1995 * @before <div><input/></div>
2000 * @cat DOM/Attributes
2004 * Set the html contents of every matched element.
2005 * This property is not available on XML documents.
2007 * @example $("div").html("<b>new stuff</b>");
2008 * @before <div><input/></div>
2009 * @result <div><b>new stuff</b></div>
2013 * @param String val Set the html contents to the specified value.
2014 * @cat DOM/Attributes
2019 * Get the current id of the first matched element.
2021 * @example $("input").id();
2022 * @before <input type="text" id="test" value="some text"/>
2027 * @cat DOM/Attributes
2031 * Set the id of every matched element.
2033 * @example $("input").id("newid");
2034 * @before <input type="text" id="test" value="some text"/>
2035 * @result <input type="text" id="newid" value="some text"/>
2039 * @param String val Set the property to the specified value.
2040 * @cat DOM/Attributes
2045 * Get the current title of the first matched element.
2047 * @example $("img").title();
2048 * @before <img src="test.jpg" title="my image"/>
2049 * @result "my image"
2053 * @cat DOM/Attributes
2057 * Set the title of every matched element.
2059 * @example $("img").title("new title");
2060 * @before <img src="test.jpg" title="my image"/>
2061 * @result <img src="test.jpg" title="new image"/>
2065 * @param String val Set the property to the specified value.
2066 * @cat DOM/Attributes
2071 * Get the current name of the first matched element.
2073 * @example $("input").name();
2074 * @before <input type="text" name="username"/>
2075 * @result "username"
2079 * @cat DOM/Attributes
2083 * Set the name of every matched element.
2085 * @example $("input").name("user");
2086 * @before <input type="text" name="username"/>
2087 * @result <input type="text" name="user"/>
2091 * @param String val Set the property to the specified value.
2092 * @cat DOM/Attributes
2097 * Get the current href of the first matched element.
2099 * @example $("a").href();
2100 * @before <a href="test.html">my link</a>
2101 * @result "test.html"
2105 * @cat DOM/Attributes
2109 * Set the href of every matched element.
2111 * @example $("a").href("test2.html");
2112 * @before <a href="test.html">my link</a>
2113 * @result <a href="test2.html">my link</a>
2117 * @param String val Set the property to the specified value.
2118 * @cat DOM/Attributes
2123 * Get the current src of the first matched element.
2125 * @example $("img").src();
2126 * @before <img src="test.jpg" title="my image"/>
2127 * @result "test.jpg"
2131 * @cat DOM/Attributes
2135 * Set the src of every matched element.
2137 * @example $("img").src("test2.jpg");
2138 * @before <img src="test.jpg" title="my image"/>
2139 * @result <img src="test2.jpg" title="my image"/>
2143 * @param String val Set the property to the specified value.
2144 * @cat DOM/Attributes
2149 * Get the current rel of the first matched element.
2151 * @example $("a").rel();
2152 * @before <a href="test.html" rel="nofollow">my link</a>
2153 * @result "nofollow"
2157 * @cat DOM/Attributes
2161 * Set the rel of every matched element.
2163 * @example $("a").rel("nofollow");
2164 * @before <a href="test.html">my link</a>
2165 * @result <a href="test.html" rel="nofollow">my link</a>
2169 * @param String val Set the property to the specified value.
2170 * @cat DOM/Attributes
2177 * Get a set of elements containing the unique parents of the matched
2180 * @example $("p").parent()
2181 * @before <div><p>Hello</p><p>Hello</p></div>
2182 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2186 * @cat DOM/Traversing
2190 * Get a set of elements containing the unique parents of the matched
2191 * set of elements, and filtered by an expression.
2193 * @example $("p").parent(".selected")
2194 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2195 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2199 * @param String expr An expression to filter the parents with
2200 * @cat DOM/Traversing
2202 parent: "a.parentNode",
2205 * Get a set of elements containing the unique ancestors of the matched
2206 * set of elements (except for the root element).
2208 * @example $("span").parents()
2209 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2210 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2214 * @cat DOM/Traversing
2218 * Get a set of elements containing the unique ancestors of the matched
2219 * set of elements, and filtered by an expression.
2221 * @example $("span").parents("p")
2222 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2223 * @result [ <p><span>Hello</span></p> ]
2227 * @param String expr An expression to filter the ancestors with
2228 * @cat DOM/Traversing
2230 parents: jQuery.parents,
2233 * Get a set of elements containing the unique next siblings of each of the
2234 * matched set of elements.
2236 * It only returns the very next sibling, not all next siblings.
2238 * @example $("p").next()
2239 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2240 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2244 * @cat DOM/Traversing
2248 * Get a set of elements containing the unique next siblings of each of the
2249 * matched set of elements, and filtered by an expression.
2251 * It only returns the very next sibling, not all next siblings.
2253 * @example $("p").next(".selected")
2254 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2255 * @result [ <p class="selected">Hello Again</p> ]
2259 * @param String expr An expression to filter the next Elements with
2260 * @cat DOM/Traversing
2262 next: "jQuery.nth(a,1,'nextSibling')",
2265 * Get a set of elements containing the unique previous siblings of each of the
2266 * matched set of elements.
2268 * It only returns the immediately previous sibling, not all previous siblings.
2270 * @example $("p").prev()
2271 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2272 * @result [ <div><span>Hello Again</span></div> ]
2276 * @cat DOM/Traversing
2280 * Get a set of elements containing the unique previous siblings of each of the
2281 * matched set of elements, and filtered by an expression.
2283 * It only returns the immediately previous sibling, not all previous siblings.
2285 * @example $("p").prev(".selected")
2286 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2287 * @result [ <div><span>Hello</span></div> ]
2291 * @param String expr An expression to filter the previous Elements with
2292 * @cat DOM/Traversing
2294 prev: "jQuery.nth(a,1,'previousSibling')",
2297 * Get a set of elements containing all of the unique siblings of each of the
2298 * matched set of elements.
2300 * @example $("div").siblings()
2301 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2302 * @result [ <p>Hello</p>, <p>And Again</p> ]
2306 * @cat DOM/Traversing
2310 * Get a set of elements containing all of the unique siblings of each of the
2311 * matched set of elements, and filtered by an expression.
2313 * @example $("div").siblings(".selected")
2314 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2315 * @result [ <p class="selected">Hello Again</p> ]
2319 * @param String expr An expression to filter the sibling Elements with
2320 * @cat DOM/Traversing
2322 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
2325 * Get a set of elements containing all of the unique children of each of the
2326 * matched set of elements.
2328 * @example $("div").children()
2329 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2330 * @result [ <span>Hello Again</span> ]
2334 * @cat DOM/Traversing
2338 * Get a set of elements containing all of the unique children of each of the
2339 * matched set of elements, and filtered by an expression.
2341 * @example $("div").children(".selected")
2342 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2343 * @result [ <p class="selected">Hello Again</p> ]
2347 * @param String expr An expression to filter the child Elements with
2348 * @cat DOM/Traversing
2350 children: "jQuery.sibling(a.firstChild)"
2356 * Remove an attribute from each of the matched elements.
2358 * @example $("input").removeAttr("disabled")
2359 * @before <input disabled="disabled"/>
2364 * @param String name The name of the attribute to remove.
2367 removeAttr: function( key ) {
2368 jQuery.attr( this, key, "" );
2369 this.removeAttribute( key );
2373 * Displays each of the set of matched elements if they are hidden.
2375 * @example $("p").show()
2376 * @before <p style="display: none">Hello</p>
2377 * @result [ <p style="display: block">Hello</p> ]
2384 this.style.display = this.oldblock ? this.oldblock : "";
2385 if ( jQuery.css(this,"display") == "none" )
2386 this.style.display = "block";
2390 * Hides each of the set of matched elements if they are shown.
2392 * @example $("p").hide()
2393 * @before <p>Hello</p>
2394 * @result [ <p style="display: none">Hello</p> ]
2396 * var pass = true, div = $("div");
2397 * div.hide().each(function(){
2398 * if ( this.style.display != "none" ) pass = false;
2400 * ok( pass, "Hide" );
2407 this.oldblock = this.oldblock || jQuery.css(this,"display");
2408 if ( this.oldblock == "none" )
2409 this.oldblock = "block";
2410 this.style.display = "none";
2414 * Toggles each of the set of matched elements. If they are shown,
2415 * toggle makes them hidden. If they are hidden, toggle
2418 * @example $("p").toggle()
2419 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2420 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2427 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2431 * Adds the specified class to each of the set of matched elements.
2433 * @example $("p").addClass("selected")
2434 * @before <p>Hello</p>
2435 * @result [ <p class="selected">Hello</p> ]
2439 * @param String class A CSS class to add to the elements
2442 addClass: function(c){
2443 jQuery.className.add(this,c);
2447 * Removes all or the specified class from the set of matched elements.
2449 * @example $("p").removeClass()
2450 * @before <p class="selected">Hello</p>
2451 * @result [ <p>Hello</p> ]
2453 * @example $("p").removeClass("selected")
2454 * @before <p class="selected first">Hello</p>
2455 * @result [ <p class="first">Hello</p> ]
2459 * @param String class (optional) A CSS class to remove from the elements
2462 removeClass: function(c){
2463 jQuery.className.remove(this,c);
2467 * Adds the specified class if it is not present, removes it if it is
2470 * @example $("p").toggleClass("selected")
2471 * @before <p>Hello</p><p class="selected">Hello Again</p>
2472 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2476 * @param String class A CSS class with which to toggle the elements
2479 toggleClass: function( c ){
2480 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2484 * Removes all matched elements from the DOM. This does NOT remove them from the
2485 * jQuery object, allowing you to use the matched elements further.
2487 * @example $("p").remove();
2488 * @before <p>Hello</p> how are <p>you?</p>
2493 * @cat DOM/Manipulation
2497 * Removes only elements (out of the list of matched elements) that match
2498 * the specified jQuery expression. This does NOT remove them from the
2499 * jQuery object, allowing you to use the matched elements further.
2501 * @example $("p").remove(".hello");
2502 * @before <p class="hello">Hello</p> how are <p>you?</p>
2503 * @result how are <p>you?</p>
2507 * @param String expr A jQuery expression to filter elements by.
2508 * @cat DOM/Manipulation
2510 remove: function(a){
2511 if ( !a || jQuery.filter( a, [this] ).r )
2512 this.parentNode.removeChild( this );
2516 * Removes all child nodes from the set of matched elements.
2518 * @example $("p").empty()
2519 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2520 * @result [ <p></p> ]
2524 * @cat DOM/Manipulation
2527 while ( this.firstChild )
2528 this.removeChild( this.firstChild );