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 hash of key/value object properties to all matched elements.
375 * This serves as the best way to set a large number of properties
376 * on all matched elements.
378 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
380 * @result <img src="test.jpg" alt="Test Image"/>
384 * @param Hash prop A set of key/value pairs to set as object properties.
389 * Set a single property to a value, on all matched elements.
391 * Note that you can't set the name property of input elements in IE.
392 * Use $(html) or $().append(html) or $().html(html) to create elements
393 * on the fly including the name property.
395 * @example $("img").attr("src","test.jpg");
397 * @result <img src="test.jpg"/>
401 * @param String key The name of the property to set.
402 * @param Object value The value to set the property to.
405 attr: function( key, value, type ) {
406 // Check to see if we're setting style values
407 return typeof key != "string" || value != undefined ?
408 this.each(function(){
409 // See if we're setting a hash of styles
410 if ( value == undefined )
411 // Set all the styles
412 for ( var prop in key )
414 type ? this.style : this,
418 // See if we're setting a single key/value style
421 type ? this.style : this,
426 // Look for the case where we're accessing a style value
427 jQuery[ type || "attr" ]( this[0], key );
431 * Access a style property on the first matched element.
432 * This method makes it easy to retrieve a style property value
433 * from the first matched element.
435 * @example $("p").css("color");
436 * @before <p style="color:red;">Test Paragraph.</p>
438 * @desc Retrieves the color style of the first paragraph
440 * @example $("p").css("fontWeight");
441 * @before <p style="font-weight: bold;">Test Paragraph.</p>
443 * @desc Retrieves the font-weight style of the first paragraph.
444 * Note that for all style properties with a dash (like 'font-weight'), you have to
445 * write it in camelCase. In other words: Every time you have a '-' in a
446 * property, remove it and replace the next character with an uppercase
447 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
448 * borderStyle, borderBottomWidth etc.
452 * @param String name The name of the property to access.
457 * Set a hash of key/value style properties to all matched elements.
458 * This serves as the best way to set a large number of style properties
459 * on all matched elements.
461 * @example $("p").css({ color: "red", background: "blue" });
462 * @before <p>Test Paragraph.</p>
463 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
467 * @param Hash prop A set of key/value pairs to set as style properties.
472 * Set a single style property to a value, on all matched elements.
474 * @example $("p").css("color","red");
475 * @before <p>Test Paragraph.</p>
476 * @result <p style="color:red;">Test Paragraph.</p>
477 * @desc Changes the color of all paragraphs to red
481 * @param String key The name of the property to set.
482 * @param Object value The value to set the property to.
485 css: function( key, value ) {
486 return this.attr( key, value, "curCSS" );
490 * Retrieve the text contents of all matched elements. The result is
491 * a string that contains the combined text contents of all matched
492 * elements. This method works on both HTML and XML documents.
494 * @example $("p").text();
495 * @before <p>Test Paragraph.</p>
496 * @result Test Paragraph.
504 * Set the text contents of all matched elements. This has the same
505 * effect as calling .html() with your specified string.
507 * @example $("p").text("Some new text.");
508 * @before <p>Test Paragraph.</p>
509 * @result <p>Some new text.</p>
511 * @param String val The text value to set the contents of the element to.
518 // A surprisingly high number of people expect the
519 // .text() method to do this, so lets do it!
520 if ( typeof e == "string" )
521 return this.html( e );
525 for ( var j = 0, el = e.length; j < el; j++ ) {
526 var r = e[j].childNodes;
527 for ( var i = 0, rl = r.length; i < rl; i++ )
528 if ( r[i].nodeType != 8 )
529 t += r[i].nodeType != 1 ?
530 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
536 * Wrap all matched elements with a structure of other elements.
537 * This wrapping process is most useful for injecting additional
538 * stucture into a document, without ruining the original semantic
539 * qualities of a document.
541 * This works by going through the first element
542 * provided (which is generated, on the fly, from the provided HTML)
543 * and finds the deepest ancestor element within its
544 * structure - it is that element that will en-wrap everything else.
546 * This does not work with elements that contain text. Any necessary text
547 * must be added after the wrapping is done.
549 * @example $("p").wrap("<div class='wrap'></div>");
550 * @before <p>Test Paragraph.</p>
551 * @result <div class='wrap'><p>Test Paragraph.</p></div>
555 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
556 * @cat DOM/Manipulation
560 * Wrap all matched elements with a structure of other elements.
561 * This wrapping process is most useful for injecting additional
562 * stucture into a document, without ruining the original semantic
563 * qualities of a document.
565 * This works by going through the first element
566 * provided and finding the deepest ancestor element within its
567 * structure - it is that element that will en-wrap everything else.
569 * This does not work with elements that contain text. Any necessary text
570 * must be added after the wrapping is done.
572 * @example $("p").wrap( document.getElementById('content') );
573 * @before <p>Test Paragraph.</p><div id="content"></div>
574 * @result <div id="content"><p>Test Paragraph.</p></div>
578 * @param Element elem A DOM element that will be wrapped.
579 * @cat DOM/Manipulation
582 // The elements to wrap the target around
583 var a = jQuery.clean(arguments);
585 // Wrap each of the matched elements individually
586 return this.each(function(){
587 // Clone the structure that we're using to wrap
588 var b = a[0].cloneNode(true);
590 // Insert it before the element to be wrapped
591 this.parentNode.insertBefore( b, this );
593 // Find the deepest point in the wrap structure
594 while ( b.firstChild )
597 // Move the matched element to within the wrap structure
598 b.appendChild( this );
603 * Append content to the inside of every matched element.
605 * This operation is similar to doing an appendChild to all the
606 * specified elements, adding them into the document.
608 * @example $("p").append("<b>Hello</b>");
609 * @before <p>I would like to say: </p>
610 * @result <p>I would like to say: <b>Hello</b></p>
612 * @example $("p").append( $("#foo")[0] );
613 * @before <p>I would like to say: </p><b id="foo">Hello</b>
614 * @result <p>I would like to say: <b id="foo">Hello</b></p>
616 * @example $("p").append( $("b") );
617 * @before <p>I would like to say: </p><b>Hello</b>
618 * @result <p>I would like to say: <b>Hello</b></p>
622 * @param <Content> content Content to append to the target
623 * @cat DOM/Manipulation
624 * @see prepend(<Content>)
625 * @see before(<Content>)
626 * @see after(<Content>)
629 return this.domManip(arguments, true, 1, function(a){
630 this.appendChild( a );
635 * Prepend content to the inside of every matched element.
637 * This operation is the best way to insert elements
638 * inside, at the beginning, of all matched elements.
640 * @example $("p").prepend("<b>Hello</b>");
641 * @before <p>I would like to say: </p>
642 * @result <p><b>Hello</b>I would like to say: </p>
644 * @example $("p").prepend( $("#foo")[0] );
645 * @before <p>I would like to say: </p><b id="foo">Hello</b>
646 * @result <p><b id="foo">Hello</b>I would like to say: </p>
648 * @example $("p").prepend( $("b") );
649 * @before <p>I would like to say: </p><b>Hello</b>
650 * @result <p><b>Hello</b>I would like to say: </p>
654 * @param <Content> content Content to prepend to the target.
655 * @cat DOM/Manipulation
656 * @see append(<Content>)
657 * @see before(<Content>)
658 * @see after(<Content>)
660 prepend: function() {
661 return this.domManip(arguments, true, -1, function(a){
662 this.insertBefore( a, this.firstChild );
667 * Insert content before each of the matched elements.
669 * @example $("p").before("<b>Hello</b>");
670 * @before <p>I would like to say: </p>
671 * @result <b>Hello</b><p>I would like to say: </p>
673 * @example $("p").before( $("#foo")[0] );
674 * @before <p>I would like to say: </p><b id="foo">Hello</b>
675 * @result <b id="foo">Hello</b><p>I would like to say: </p>
677 * @example $("p").before( $("b") );
678 * @before <p>I would like to say: </p><b>Hello</b>
679 * @result <b>Hello</b><p>I would like to say: </p>
683 * @param <Content> content Content to insert before each target.
684 * @cat DOM/Manipulation
685 * @see append(<Content>)
686 * @see prepend(<Content>)
687 * @see after(<Content>)
690 return this.domManip(arguments, false, 1, function(a){
691 this.parentNode.insertBefore( a, this );
696 * Insert content after each of the matched elements.
698 * @example $("p").after("<b>Hello</b>");
699 * @before <p>I would like to say: </p>
700 * @result <p>I would like to say: </p><b>Hello</b>
702 * @example $("p").after( $("#foo")[0] );
703 * @before <b id="foo">Hello</b><p>I would like to say: </p>
704 * @result <p>I would like to say: </p><b id="foo">Hello</b>
706 * @example $("p").after( $("b") );
707 * @before <b>Hello</b><p>I would like to say: </p>
708 * @result <p>I would like to say: </p><b>Hello</b>
712 * @param <Content> content Content to insert after each target.
713 * @cat DOM/Manipulation
714 * @see append(<Content>)
715 * @see prepend(<Content>)
716 * @see before(<Content>)
719 return this.domManip(arguments, false, -1, function(a){
720 this.parentNode.insertBefore( a, this.nextSibling );
725 * End the most recent 'destructive' operation, reverting the list of matched elements
726 * back to its previous state. After an end operation, the list of matched elements will
727 * revert to the last state of matched elements.
729 * If there was no destructive operation before, an empty set is returned.
731 * @example $("p").find("span").end();
732 * @before <p><span>Hello</span>, how are you?</p>
733 * @result $("p").find("span").end() == [ <p>...</p> ]
737 * @cat DOM/Traversing
740 return this.prevObject || jQuery([]);
744 * Searches for all elements that match the specified expression.
745 * This method is the optimal way of finding additional descendant
746 * elements with which to process.
748 * All searching is done using a jQuery expression. The expression can be
749 * written using CSS 1-3 Selector syntax, or basic XPath.
751 * @example $("p").find("span");
752 * @before <p><span>Hello</span>, how are you?</p>
753 * @result $("p").find("span") == [ <span>Hello</span> ]
757 * @param String expr An expression to search with.
758 * @cat DOM/Traversing
761 return this.set( jQuery.map( this, function(a){
762 return jQuery.find(t,a);
767 * Create cloned copies of all matched DOM Elements. This does
768 * not create a cloned copy of this particular jQuery object,
769 * instead it creates duplicate copies of all DOM Elements.
770 * This is useful for moving copies of the elements to another
771 * location in the DOM.
773 * @example $("b").clone().prependTo("p");
774 * @before <b>Hello</b><p>, how are you?</p>
775 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
779 * @cat DOM/Manipulation
781 clone: function(deep) {
782 return this.set( jQuery.map( this, function(a){
783 return a.cloneNode( deep != undefined ? deep : true );
788 * Removes all elements from the set of matched elements that do not
789 * match the specified expression. This method is used to narrow down
790 * the results of a search.
792 * All searching is done using a jQuery expression. The expression
793 * can be written using CSS 1-3 Selector syntax, or basic XPath.
795 * @example $("p").filter(".selected")
796 * @before <p class="selected">Hello</p><p>How are you?</p>
797 * @result [ <p class="selected">Hello</p> ]
801 * @param String expr An expression to search with.
802 * @cat DOM/Traversing
806 * Removes all elements from the set of matched elements that do not
807 * pass the specified filter. This method is used to narrow down
808 * the results of a search.
810 * The elements to filter are passed as the first argument, their
811 * index inside the set as the second.
813 * @example $("p").filter(function(element, index) {
814 * return $("ol", element).length == 0;
816 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
817 * @result [ <p>How are you?</p> ]
818 * @desc Remove all elements that have a child ol element
822 * @param Function filter A function to use for filtering
823 * @cat DOM/Traversing
827 * Removes all elements from the set of matched elements that do not
828 * match at least one of the expressions passed to the function. This
829 * method is used when you want to filter the set of matched elements
830 * through more than one expression.
832 * Elements will be retained in the jQuery object if they match at
833 * least one of the expressions passed.
835 * @example $("p").filter([".selected", ":first"])
836 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
837 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
841 * @param Array<String> exprs A set of expressions to evaluate against
842 * @cat DOM/Traversing
844 filter: function(t) {
846 t.constructor == Array &&
847 jQuery.map(this,function(a){
848 for ( var i = 0, tl = t.length; i < tl; i++ )
849 if ( jQuery.filter(t[i],[a]).r.length )
854 t.constructor == Boolean &&
855 ( t ? this.get() : [] ) ||
857 typeof t == "function" &&
858 jQuery.grep( this, t ) ||
860 jQuery.filter(t,this).r );
864 * Removes the specified Element from the set of matched elements. This
865 * method is used to remove a single Element from a jQuery object.
867 * @example $("p").not( document.getElementById("selected") )
868 * @before <p>Hello</p><p id="selected">Hello Again</p>
869 * @result [ <p>Hello</p> ]
873 * @param Element el An element to remove from the set
874 * @cat DOM/Traversing
878 * Removes elements matching the specified expression from the set
879 * of matched elements. This method is used to remove one or more
880 * elements from a jQuery object.
882 * @example $("p").not("#selected")
883 * @before <p>Hello</p><p id="selected">Hello Again</p>
884 * @result [ <p>Hello</p> ]
888 * @param String expr An expression with which to remove matching elements
889 * @cat DOM/Traversing
892 return this.set( typeof t == "string" ?
893 jQuery.filter(t,this,true).r :
894 jQuery.grep(this,function(a){ return a != t; }) );
898 * Adds the elements matched by the expression to the jQuery object. This
899 * can be used to concatenate the result sets of two expressions.
901 * @example $("p").add("span")
902 * @before <p>Hello</p><p><span>Hello Again</span></p>
903 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
907 * @param String expr An expression whose matched elements are added
908 * @cat DOM/Traversing
912 * Adds each of the Elements in the array to the set of matched elements.
913 * This is used to add a set of Elements to a jQuery object.
915 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
916 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
917 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
921 * @param Array<Element> els An array of Elements to add
922 * @cat DOM/Traversing
926 * Adds a single Element to the set of matched elements. This is used to
927 * add a single Element to a jQuery object.
929 * @example $("p").add( document.getElementById("a") )
930 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
931 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
935 * @param Element el An Element to add
936 * @cat DOM/Traversing
939 return this.set( jQuery.merge(
940 this.get(), typeof t == "string" ?
942 t.constructor == Array ? t : [t] ) );
946 * Checks the current selection against an expression and returns true,
947 * if at least one element of the selection fits the given expression.
948 * Does return false, if no element fits or the expression is not valid.
950 * @example $("input[@type='checkbox']").parent().is("form")
951 * @before <form><input type="checkbox" /></form>
953 * @desc Returns true, because the parent of the input is a form element
955 * @example $("input[@type='checkbox']").parent().is("form")
956 * @before <form><p><input type="checkbox" /></p></form>
958 * @desc Returns false, because the parent of the input is a p element
960 * @example $("form").is(null)
961 * @before <form></form>
963 * @desc An invalid expression always returns false.
967 * @param String expr The expression with which to filter
968 * @cat DOM/Traversing
971 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
978 * @param Boolean table Insert TBODY in TABLEs if one is not found.
979 * @param Number dir If dir<0, process args in reverse order.
980 * @param Function fn The function doing the DOM manipulation.
984 domManip: function(args, table, dir, fn){
985 var clone = this.length > 1;
986 var a = jQuery.clean(args);
990 return this.each(function(){
993 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
994 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
996 for ( var i = 0, al = a.length; i < al; i++ )
997 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1004 * Extends the jQuery object itself. Can be used to add functions into
1005 * the jQuery namespace and to add plugin methods (plugins).
1007 * @example jQuery.fn.extend({
1008 * check: function() {
1009 * return this.each(function() { this.checked = true; });
1011 * uncheck: function() {
1012 * return this.each(function() { this.checked = false; });
1015 * $("input[@type=checkbox]").check();
1016 * $("input[@type=radio]").uncheck();
1017 * @desc Adds two plugin methods.
1019 * @example jQuery.extend({
1020 * min: function(a, b) { return a < b ? a : b; },
1021 * max: function(a, b) { return a > b ? a : b; }
1023 * @desc Adds two functions into the jQuery namespace
1026 * @param Object prop The object that will be merged into the jQuery object
1032 * Extend one object with one or more others, returning the original,
1033 * modified, object. This is a great utility for simple inheritance.
1035 * @example var settings = { validate: false, limit: 5, name: "foo" };
1036 * var options = { validate: true, name: "bar" };
1037 * jQuery.extend(settings, options);
1038 * @result settings == { validate: true, limit: 5, name: "bar" }
1039 * @desc Merge settings and options, modifying settings
1041 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1042 * var options = { validate: true, name: "bar" };
1043 * var settings = jQuery.extend({}, defaults, options);
1044 * @result settings == { validate: true, limit: 5, name: "bar" }
1045 * @desc Merge defaults and options, without modifying the defaults
1048 * @param Object target The object to extend
1049 * @param Object prop1 The object that will be merged into the first.
1050 * @param Object propN (optional) More objects to merge into the first
1054 jQuery.extend = jQuery.fn.extend = function() {
1055 // copy reference to target object
1056 var target = arguments[0],
1059 // extend jQuery itself if only one argument is passed
1060 if ( arguments.length == 1 ) {
1065 while (prop = arguments[a++])
1066 // Extend the base object
1067 for ( var i in prop ) target[i] = prop[i];
1069 // Return the modified object
1081 jQuery.initDone = true;
1083 jQuery.each( jQuery.macros.axis, function(i,n){
1084 jQuery.fn[ i ] = function(a) {
1085 var ret = jQuery.map(this,n);
1086 if ( a && typeof a == "string" )
1087 ret = jQuery.filter(a,ret).r;
1088 return this.set( ret );
1092 jQuery.each( jQuery.macros.to, function(i,n){
1093 jQuery.fn[ i ] = function(){
1095 return this.each(function(){
1096 for ( var j = 0, al = a.length; j < al; j++ )
1097 jQuery(a[j])[n]( this );
1102 jQuery.each( jQuery.macros.each, function(i,n){
1103 jQuery.fn[ i ] = function() {
1104 return this.each( n, arguments );
1108 jQuery.each( jQuery.macros.filter, function(i,n){
1109 jQuery.fn[ n ] = function(num,fn) {
1110 return this.filter( ":" + n + "(" + num + ")", fn );
1114 jQuery.each( jQuery.macros.attr, function(i,n){
1116 jQuery.fn[ i ] = function(h) {
1117 return h == undefined ?
1118 this.length ? this[0][n] : null :
1123 jQuery.each( jQuery.macros.css, function(i,n){
1124 jQuery.fn[ n ] = function(h) {
1125 return h == undefined ?
1126 ( this.length ? jQuery.css( this[0], n ) : null ) :
1134 * A generic iterator function, which can be used to seemlessly
1135 * iterate over both objects and arrays. This function is not the same
1136 * as $().each() - which is used to iterate, exclusively, over a jQuery
1137 * object. This function can be used to iterate over anything.
1139 * @example $.each( [0,1,2], function(i){
1140 * alert( "Item #" + i + ": " + this );
1142 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1144 * @example $.each( { name: "John", lang: "JS" }, function(i){
1145 * alert( "Name: " + i + ", Value: " + this );
1147 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1150 * @param Object obj The object, or array, to iterate over.
1151 * @param Function fn The function that will be executed on every object.
1155 // args is for internal usage only
1156 each: function( obj, fn, args ) {
1157 if ( obj.length == undefined )
1158 for ( var i in obj )
1159 fn.apply( obj[i], args || [i, obj[i]] );
1161 for ( var i = 0, ol = obj.length; i < ol; i++ )
1162 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1167 add: function( elem, c ){
1168 jQuery.each( c.split(/\s+/), function(i, cur){
1169 if ( !jQuery.className.has( elem.className, cur ) )
1170 elem.className += ( elem.className ? " " : "" ) + cur;
1173 remove: function( elem, c ){
1174 elem.className = c ?
1175 jQuery.grep( elem.className.split(/\s+/), function(cur){
1176 return !jQuery.className.has( c, cur );
1179 has: function( classes, c ){
1180 return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
1185 * Swap in/out style options.
1188 swap: function(e,o,f) {
1189 for ( var i in o ) {
1190 e.style["old"+i] = e.style[i];
1195 e.style[i] = e.style["old"+i];
1198 css: function(e,p) {
1199 if ( p == "height" || p == "width" ) {
1200 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1202 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1203 old["padding" + d[i]] = 0;
1204 old["border" + d[i] + "Width"] = 0;
1207 jQuery.swap( e, old, function() {
1208 if (jQuery.css(e,"display") != "none") {
1209 oHeight = e.offsetHeight;
1210 oWidth = e.offsetWidth;
1212 e = jQuery(e.cloneNode(true))
1213 .find(":radio").removeAttr("checked").end()
1215 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1216 }).appendTo(e.parentNode)[0];
1218 var parPos = jQuery.css(e.parentNode,"position");
1219 if ( parPos == "" || parPos == "static" )
1220 e.parentNode.style.position = "relative";
1222 oHeight = e.clientHeight;
1223 oWidth = e.clientWidth;
1225 if ( parPos == "" || parPos == "static" )
1226 e.parentNode.style.position = "static";
1228 e.parentNode.removeChild(e);
1232 return p == "height" ? oHeight : oWidth;
1235 return jQuery.curCSS( e, p );
1238 curCSS: function(elem, prop, force) {
1241 if (prop == 'opacity' && jQuery.browser.msie)
1242 return jQuery.attr(elem.style, 'opacity');
1244 if (prop == "float" || prop == "cssFloat")
1245 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1247 if (!force && elem.style[prop]) {
1249 ret = elem.style[prop];
1251 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1253 if (prop == "cssFloat" || prop == "styleFloat")
1256 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1257 var cur = document.defaultView.getComputedStyle(elem, null);
1260 ret = cur.getPropertyValue(prop);
1261 else if ( prop == 'display' )
1264 jQuery.swap(elem, { display: 'block' }, function() {
1265 var c = document.defaultView.getComputedStyle(this, '');
1266 ret = c && c.getPropertyValue(prop) || '';
1269 } else if (elem.currentStyle) {
1271 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1272 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1279 clean: function(a) {
1281 for ( var i = 0, al = a.length; i < al; i++ ) {
1283 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
1284 // Trim whitespace, otherwise indexOf won't work as expected
1285 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6),
1286 div = document.createElement("div"), wrap = [0,"",""];
1288 if ( s.substring(0,4) == "<opt" ) // option or optgroup
1289 wrap = [1, "<select>", "</select>"];
1290 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" )
1291 wrap = [1, "<table>", "</table>"];
1292 else if ( s3 == "<tr" )
1293 wrap = [2, "<table><tbody>", "</tbody></table>"];
1294 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above
1295 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1297 // Go to html and back, then peel off extra wrappers
1298 div.innerHTML = wrap[1] + s + wrap[2];
1299 while ( wrap[0]-- ) div = div.firstChild;
1301 // Remove IE's autoinserted <tbody> from table fragments
1302 if ( jQuery.browser.msie ) {
1304 // String was a <table>, *may* have spurious <tbody>
1305 if ( s6 == "<table" && s.indexOf("<tbody") < 0 )
1306 tb = div.firstChild && div.firstChild.childNodes;
1307 // String was a bare <thead> or <tfoot>
1308 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1309 tb = div.childNodes;
1311 for ( var n = tb.length-1; n >= 0 ; --n )
1312 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1313 tb[n].parentNode.removeChild(tb[n]);
1317 arg = div.childNodes;
1321 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1322 for ( var n = 0, argl = arg.length; n < argl; n++ ) // Handles Array, jQuery, DOM NodeList collections
1325 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1331 attr: function(elem, name, value){
1334 "class": "className",
1335 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1336 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1337 innerHTML: "innerHTML",
1338 className: "className",
1340 disabled: "disabled",
1342 readonly: "readOnly",
1343 selected: "selected"
1346 // IE actually uses filters for opacity ... elem is actually elem.style
1347 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1348 // IE has trouble with opacity if it does not have layout
1349 // Force it by setting the zoom level
1352 // Set the alpha filter to set the opacity
1353 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1354 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1356 } else if ( name == "opacity" && jQuery.browser.msie ) {
1357 return elem.filter ?
1358 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1361 // Mozilla doesn't play well with opacity 1
1362 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1365 // Certain attributes only work when accessed via the old DOM 0 way
1367 if ( value != undefined ) elem[fix[name]] = value;
1368 return elem[fix[name]];
1370 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1371 return elem.getAttributeNode(name).nodeValue;
1373 // IE elem.getAttribute passes even for style
1374 } else if ( elem.tagName ) {
1375 if ( value != undefined ) elem.setAttribute( name, value );
1376 return elem.getAttribute( name );
1379 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1380 if ( value != undefined ) elem[name] = value;
1386 * Remove the whitespace from the beginning and end of a string.
1388 * @example $.trim(" hello, how are you? ");
1389 * @result "hello, how are you?"
1393 * @param String str The string to trim.
1397 return t.replace(/^\s+|\s+$/g, "");
1400 makeArray: function( a ) {
1403 if ( a.constructor != Array ) {
1404 for ( var i = 0, al = a.length; i < al; i++ )
1412 inArray: function( b, a ) {
1413 for ( var i = 0, al = a.length; i < al; i++ )
1420 * Merge two arrays together, removing all duplicates. The final order
1421 * or the new array is: All the results from the first array, followed
1422 * by the unique results from the second array.
1424 * @example $.merge( [0,1,2], [2,3,4] )
1425 * @result [0,1,2,3,4]
1427 * @example $.merge( [3,2,1], [4,3,2] )
1432 * @param Array first The first array to merge.
1433 * @param Array second The second array to merge.
1436 merge: function(first, second) {
1437 var r = [].slice.call( first, 0 );
1439 // Now check for duplicates between the two arrays
1440 // and only add the unique items
1441 for ( var i = 0, sl = second.length; i < sl; i++ ) {
1442 // Check for duplicates
1443 if ( jQuery.inArray( second[i], r ) == -1 )
1444 // The item is unique, add it
1445 first.push( second[i] );
1452 * Filter items out of an array, by using a filter function.
1453 * The specified function will be passed two arguments: The
1454 * current array item and the index of the item in the array. The
1455 * function should return 'true' if you wish to keep the item in
1456 * the array, false if it should be removed.
1458 * @example $.grep( [0,1,2], function(i){
1465 * @param Array array The Array to find items in.
1466 * @param Function fn The function to process each item against.
1467 * @param Boolean inv Invert the selection - select the opposite of the function.
1470 grep: function(elems, fn, inv) {
1471 // If a string is passed in for the function, make a function
1472 // for it (a handy shortcut)
1473 if ( typeof fn == "string" )
1474 fn = new Function("a","i","return " + fn);
1478 // Go through the array, only saving the items
1479 // that pass the validator function
1480 for ( var i = 0, el = elems.length; i < el; i++ )
1481 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1482 result.push( elems[i] );
1488 * Translate all items in an array to another array of items.
1489 * The translation function that is provided to this method is
1490 * called for each item in the array and is passed one argument:
1491 * The item to be translated. The function can then return:
1492 * The translated value, 'null' (to remove the item), or
1493 * an array of values - which will be flattened into the full array.
1495 * @example $.map( [0,1,2], function(i){
1500 * @example $.map( [0,1,2], function(i){
1501 * return i > 0 ? i + 1 : null;
1505 * @example $.map( [0,1,2], function(i){
1506 * return [ i, i + 1 ];
1508 * @result [0, 1, 1, 2, 2, 3]
1512 * @param Array array The Array to translate.
1513 * @param Function fn The function to process each item against.
1516 map: function(elems, fn) {
1517 // If a string is passed in for the function, make a function
1518 // for it (a handy shortcut)
1519 if ( typeof fn == "string" )
1520 fn = new Function("a","return " + fn);
1522 var result = [], r = [];
1524 // Go through the array, translating each of the items to their
1525 // new value (or values).
1526 for ( var i = 0, el = elems.length; i < el; i++ ) {
1527 var val = fn(elems[i],i);
1529 if ( val !== null && val != undefined ) {
1530 if ( val.constructor != Array ) val = [val];
1531 result = result.concat( val );
1535 var r = [ result[0] ];
1537 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1538 for ( var j = 0; j < i; j++ )
1539 if ( result[i] == r[j] )
1542 r.push( result[i] );
1550 * Contains flags for the useragent, read from navigator.userAgent.
1551 * Available flags are: safari, opera, msie, mozilla
1552 * This property is available before the DOM is ready, therefore you can
1553 * use it to add ready events only for certain browsers.
1555 * There are situations where object detections is not reliable enough, in that
1556 * cases it makes sense to use browser detection. Simply try to avoid both!
1558 * A combination of browser and object detection yields quite reliable results.
1560 * @example $.browser.msie
1561 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1563 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1564 * @desc Alerts "this is safari!" only for safari browsers
1573 * Wheather the W3C compliant box model is being used.
1581 var b = navigator.userAgent.toLowerCase();
1583 // Figure out what browser is being used
1585 safari: /webkit/.test(b),
1586 opera: /opera/.test(b),
1587 msie: /msie/.test(b) && !/opera/.test(b),
1588 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1591 // Check to see if the W3C box model is being used
1592 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1598 * Append all of the matched elements to another, specified, set of elements.
1599 * This operation is, essentially, the reverse of doing a regular
1600 * $(A).append(B), in that instead of appending B to A, you're appending
1603 * @example $("p").appendTo("#foo");
1604 * @before <p>I would like to say: </p><div id="foo"></div>
1605 * @result <div id="foo"><p>I would like to say: </p></div>
1609 * @param String expr A jQuery expression of elements to match.
1610 * @cat DOM/Manipulation
1615 * Prepend all of the matched elements to another, specified, set of elements.
1616 * This operation is, essentially, the reverse of doing a regular
1617 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1620 * @example $("p").prependTo("#foo");
1621 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1622 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1626 * @param String expr A jQuery expression of elements to match.
1627 * @cat DOM/Manipulation
1629 prependTo: "prepend",
1632 * Insert all of the matched elements before another, specified, set of elements.
1633 * This operation is, essentially, the reverse of doing a regular
1634 * $(A).before(B), in that instead of inserting B before A, you're inserting
1637 * @example $("p").insertBefore("#foo");
1638 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1639 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1641 * @name insertBefore
1643 * @param String expr A jQuery expression of elements to match.
1644 * @cat DOM/Manipulation
1646 insertBefore: "before",
1649 * Insert all of the matched elements after another, specified, set of elements.
1650 * This operation is, essentially, the reverse of doing a regular
1651 * $(A).after(B), in that instead of inserting B after A, you're inserting
1654 * @example $("p").insertAfter("#foo");
1655 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1656 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1660 * @param String expr A jQuery expression of elements to match.
1661 * @cat DOM/Manipulation
1663 insertAfter: "after"
1667 * Get the current CSS width of the first matched element.
1669 * @example $("p").width();
1670 * @before <p>This is just a test.</p>
1679 * Set the CSS width of every matched element. Be sure to include
1680 * the "px" (or other unit of measurement) after the number that you
1681 * specify, otherwise you might get strange results.
1683 * @example $("p").width("20px");
1684 * @before <p>This is just a test.</p>
1685 * @result <p style="width:20px;">This is just a test.</p>
1689 * @param String val Set the CSS property to the specified value.
1694 * Get the current CSS height of the first matched element.
1696 * @example $("p").height();
1697 * @before <p>This is just a test.</p>
1706 * Set the CSS height of every matched element. Be sure to include
1707 * the "px" (or other unit of measurement) after the number that you
1708 * specify, otherwise you might get strange results.
1710 * @example $("p").height("20px");
1711 * @before <p>This is just a test.</p>
1712 * @result <p style="height:20px;">This is just a test.</p>
1716 * @param String val Set the CSS property to the specified value.
1721 * Get the current CSS top of the first matched element.
1723 * @example $("p").top();
1724 * @before <p>This is just a test.</p>
1733 * Set the CSS top of every matched element. Be sure to include
1734 * the "px" (or other unit of measurement) after the number that you
1735 * specify, otherwise you might get strange results.
1737 * @example $("p").top("20px");
1738 * @before <p>This is just a test.</p>
1739 * @result <p style="top:20px;">This is just a test.</p>
1743 * @param String val Set the CSS property to the specified value.
1748 * Get the current CSS left of the first matched element.
1750 * @example $("p").left();
1751 * @before <p>This is just a test.</p>
1760 * Set the CSS left of every matched element. Be sure to include
1761 * the "px" (or other unit of measurement) after the number that you
1762 * specify, otherwise you might get strange results.
1764 * @example $("p").left("20px");
1765 * @before <p>This is just a test.</p>
1766 * @result <p style="left:20px;">This is just a test.</p>
1770 * @param String val Set the CSS property to the specified value.
1775 * Get the current CSS position of the first matched element.
1777 * @example $("p").position();
1778 * @before <p>This is just a test.</p>
1787 * Set the CSS position of every matched element.
1789 * @example $("p").position("relative");
1790 * @before <p>This is just a test.</p>
1791 * @result <p style="position:relative;">This is just a test.</p>
1795 * @param String val Set the CSS property to the specified value.
1800 * Get the current CSS float of the first matched element.
1802 * @example $("p").float();
1803 * @before <p>This is just a test.</p>
1812 * Set the CSS float of every matched element.
1814 * @example $("p").float("left");
1815 * @before <p>This is just a test.</p>
1816 * @result <p style="float:left;">This is just a test.</p>
1820 * @param String val Set the CSS property to the specified value.
1825 * Get the current CSS overflow of the first matched element.
1827 * @example $("p").overflow();
1828 * @before <p>This is just a test.</p>
1837 * Set the CSS overflow of every matched element.
1839 * @example $("p").overflow("auto");
1840 * @before <p>This is just a test.</p>
1841 * @result <p style="overflow:auto;">This is just a test.</p>
1845 * @param String val Set the CSS property to the specified value.
1850 * Get the current CSS color of the first matched element.
1852 * @example $("p").color();
1853 * @before <p>This is just a test.</p>
1862 * Set the CSS color of every matched element.
1864 * @example $("p").color("blue");
1865 * @before <p>This is just a test.</p>
1866 * @result <p style="color:blue;">This is just a test.</p>
1870 * @param String val Set the CSS property to the specified value.
1875 * Get the current CSS background of the first matched element.
1877 * @example $("p").background();
1878 * @before <p style="background:blue;">This is just a test.</p>
1887 * Set the CSS background of every matched element.
1889 * @example $("p").background("blue");
1890 * @before <p>This is just a test.</p>
1891 * @result <p style="background:blue;">This is just a test.</p>
1895 * @param String val Set the CSS property to the specified value.
1899 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1902 * Reduce the set of matched elements to a single element.
1903 * The position of the element in the set of matched elements
1904 * starts at 0 and goes to length - 1.
1906 * @example $("p").eq(1)
1907 * @before <p>This is just a test.</p><p>So is this</p>
1908 * @result [ <p>So is this</p> ]
1912 * @param Number pos The index of the element that you wish to limit to.
1917 * Reduce the set of matched elements to all elements before a given position.
1918 * The position of the element in the set of matched elements
1919 * starts at 0 and goes to length - 1.
1921 * @example $("p").lt(1)
1922 * @before <p>This is just a test.</p><p>So is this</p>
1923 * @result [ <p>This is just a test.</p> ]
1927 * @param Number pos Reduce the set to all elements below this position.
1932 * Reduce the set of matched elements to all elements after a given position.
1933 * The position of the element in the set of matched elements
1934 * starts at 0 and goes to length - 1.
1936 * @example $("p").gt(0)
1937 * @before <p>This is just a test.</p><p>So is this</p>
1938 * @result [ <p>So is this</p> ]
1942 * @param Number pos Reduce the set to all elements after this position.
1947 * Filter the set of elements to those that contain the specified text.
1949 * @example $("p").contains("test")
1950 * @before <p>This is just a test.</p><p>So is this</p>
1951 * @result [ <p>This is just a test.</p> ]
1955 * @param String str The string that will be contained within the text of an element.
1956 * @cat DOM/Traversing
1959 filter: [ "eq", "lt", "gt", "contains" ],
1963 * Get the current value of the first matched element.
1965 * @example $("input").val();
1966 * @before <input type="text" value="some text"/>
1967 * @result "some text"
1971 * @cat DOM/Attributes
1975 * Set the value of every matched element.
1977 * @example $("input").val("test");
1978 * @before <input type="text" value="some text"/>
1979 * @result <input type="text" value="test"/>
1983 * @param String val Set the property to the specified value.
1984 * @cat DOM/Attributes
1989 * Get the html contents of the first matched element.
1990 * This property is not available on XML documents.
1992 * @example $("div").html();
1993 * @before <div><input/></div>
1998 * @cat DOM/Attributes
2002 * Set the html contents of every matched element.
2003 * This property is not available on XML documents.
2005 * @example $("div").html("<b>new stuff</b>");
2006 * @before <div><input/></div>
2007 * @result <div><b>new stuff</b></div>
2011 * @param String val Set the html contents to the specified value.
2012 * @cat DOM/Attributes
2017 * Get the current id of the first matched element.
2019 * @example $("input").id();
2020 * @before <input type="text" id="test" value="some text"/>
2025 * @cat DOM/Attributes
2029 * Set the id of every matched element.
2031 * @example $("input").id("newid");
2032 * @before <input type="text" id="test" value="some text"/>
2033 * @result <input type="text" id="newid" value="some text"/>
2037 * @param String val Set the property to the specified value.
2038 * @cat DOM/Attributes
2043 * Get the current title of the first matched element.
2045 * @example $("img").title();
2046 * @before <img src="test.jpg" title="my image"/>
2047 * @result "my image"
2051 * @cat DOM/Attributes
2055 * Set the title of every matched element.
2057 * @example $("img").title("new title");
2058 * @before <img src="test.jpg" title="my image"/>
2059 * @result <img src="test.jpg" title="new image"/>
2063 * @param String val Set the property to the specified value.
2064 * @cat DOM/Attributes
2069 * Get the current name of the first matched element.
2071 * @example $("input").name();
2072 * @before <input type="text" name="username"/>
2073 * @result "username"
2077 * @cat DOM/Attributes
2081 * Set the name of every matched element.
2083 * @example $("input").name("user");
2084 * @before <input type="text" name="username"/>
2085 * @result <input type="text" name="user"/>
2089 * @param String val Set the property to the specified value.
2090 * @cat DOM/Attributes
2095 * Get the current href of the first matched element.
2097 * @example $("a").href();
2098 * @before <a href="test.html">my link</a>
2099 * @result "test.html"
2103 * @cat DOM/Attributes
2107 * Set the href of every matched element.
2109 * @example $("a").href("test2.html");
2110 * @before <a href="test.html">my link</a>
2111 * @result <a href="test2.html">my link</a>
2115 * @param String val Set the property to the specified value.
2116 * @cat DOM/Attributes
2121 * Get the current src of the first matched element.
2123 * @example $("img").src();
2124 * @before <img src="test.jpg" title="my image"/>
2125 * @result "test.jpg"
2129 * @cat DOM/Attributes
2133 * Set the src of every matched element.
2135 * @example $("img").src("test2.jpg");
2136 * @before <img src="test.jpg" title="my image"/>
2137 * @result <img src="test2.jpg" title="my image"/>
2141 * @param String val Set the property to the specified value.
2142 * @cat DOM/Attributes
2147 * Get the current rel of the first matched element.
2149 * @example $("a").rel();
2150 * @before <a href="test.html" rel="nofollow">my link</a>
2151 * @result "nofollow"
2155 * @cat DOM/Attributes
2159 * Set the rel of every matched element.
2161 * @example $("a").rel("nofollow");
2162 * @before <a href="test.html">my link</a>
2163 * @result <a href="test.html" rel="nofollow">my link</a>
2167 * @param String val Set the property to the specified value.
2168 * @cat DOM/Attributes
2175 * Get a set of elements containing the unique parents of the matched
2178 * @example $("p").parent()
2179 * @before <div><p>Hello</p><p>Hello</p></div>
2180 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2184 * @cat DOM/Traversing
2188 * Get a set of elements containing the unique parents of the matched
2189 * set of elements, and filtered by an expression.
2191 * @example $("p").parent(".selected")
2192 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2193 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2197 * @param String expr An expression to filter the parents with
2198 * @cat DOM/Traversing
2200 parent: "a.parentNode",
2203 * Get a set of elements containing the unique ancestors of the matched
2204 * set of elements (except for the root element).
2206 * @example $("span").parents()
2207 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2208 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2212 * @cat DOM/Traversing
2216 * Get a set of elements containing the unique ancestors of the matched
2217 * set of elements, and filtered by an expression.
2219 * @example $("span").parents("p")
2220 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2221 * @result [ <p><span>Hello</span></p> ]
2225 * @param String expr An expression to filter the ancestors with
2226 * @cat DOM/Traversing
2228 parents: jQuery.parents,
2231 * Get a set of elements containing the unique next siblings of each of the
2232 * matched set of elements.
2234 * It only returns the very next sibling, not all next siblings.
2236 * @example $("p").next()
2237 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2238 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2242 * @cat DOM/Traversing
2246 * Get a set of elements containing the unique next siblings of each of the
2247 * matched set of elements, and filtered by an expression.
2249 * It only returns the very next sibling, not all next siblings.
2251 * @example $("p").next(".selected")
2252 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2253 * @result [ <p class="selected">Hello Again</p> ]
2257 * @param String expr An expression to filter the next Elements with
2258 * @cat DOM/Traversing
2260 next: "jQuery.nth(a,1,'nextSibling')",
2263 * Get a set of elements containing the unique previous siblings of each of the
2264 * matched set of elements.
2266 * It only returns the immediately previous sibling, not all previous siblings.
2268 * @example $("p").prev()
2269 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2270 * @result [ <div><span>Hello Again</span></div> ]
2274 * @cat DOM/Traversing
2278 * Get a set of elements containing the unique previous siblings of each of the
2279 * matched set of elements, and filtered by an expression.
2281 * It only returns the immediately previous sibling, not all previous siblings.
2283 * @example $("p").prev(".selected")
2284 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2285 * @result [ <div><span>Hello</span></div> ]
2289 * @param String expr An expression to filter the previous Elements with
2290 * @cat DOM/Traversing
2292 prev: "jQuery.nth(a,1,'previousSibling')",
2295 * Get a set of elements containing all of the unique siblings of each of the
2296 * matched set of elements.
2298 * @example $("div").siblings()
2299 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2300 * @result [ <p>Hello</p>, <p>And Again</p> ]
2304 * @cat DOM/Traversing
2308 * Get a set of elements containing all of the unique siblings of each of the
2309 * matched set of elements, and filtered by an expression.
2311 * @example $("div").siblings(".selected")
2312 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2313 * @result [ <p class="selected">Hello Again</p> ]
2317 * @param String expr An expression to filter the sibling Elements with
2318 * @cat DOM/Traversing
2320 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
2323 * Get a set of elements containing all of the unique children of each of the
2324 * matched set of elements.
2326 * @example $("div").children()
2327 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2328 * @result [ <span>Hello Again</span> ]
2332 * @cat DOM/Traversing
2336 * Get a set of elements containing all of the unique children of each of the
2337 * matched set of elements, and filtered by an expression.
2339 * @example $("div").children(".selected")
2340 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2341 * @result [ <p class="selected">Hello Again</p> ]
2345 * @param String expr An expression to filter the child Elements with
2346 * @cat DOM/Traversing
2348 children: "jQuery.sibling(a.firstChild)"
2354 * Remove an attribute from each of the matched elements.
2356 * @example $("input").removeAttr("disabled")
2357 * @before <input disabled="disabled"/>
2362 * @param String name The name of the attribute to remove.
2365 removeAttr: function( key ) {
2366 jQuery.attr( this, key, "" );
2367 this.removeAttribute( key );
2371 * Displays each of the set of matched elements if they are hidden.
2373 * @example $("p").show()
2374 * @before <p style="display: none">Hello</p>
2375 * @result [ <p style="display: block">Hello</p> ]
2382 this.style.display = this.oldblock ? this.oldblock : "";
2383 if ( jQuery.css(this,"display") == "none" )
2384 this.style.display = "block";
2388 * Hides each of the set of matched elements if they are shown.
2390 * @example $("p").hide()
2391 * @before <p>Hello</p>
2392 * @result [ <p style="display: none">Hello</p> ]
2394 * var pass = true, div = $("div");
2395 * div.hide().each(function(){
2396 * if ( this.style.display != "none" ) pass = false;
2398 * ok( pass, "Hide" );
2405 this.oldblock = this.oldblock || jQuery.css(this,"display");
2406 if ( this.oldblock == "none" )
2407 this.oldblock = "block";
2408 this.style.display = "none";
2412 * Toggles each of the set of matched elements. If they are shown,
2413 * toggle makes them hidden. If they are hidden, toggle
2416 * @example $("p").toggle()
2417 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2418 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2425 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2429 * Adds the specified class to each of the set of matched elements.
2431 * @example $("p").addClass("selected")
2432 * @before <p>Hello</p>
2433 * @result [ <p class="selected">Hello</p> ]
2437 * @param String class A CSS class to add to the elements
2440 addClass: function(c){
2441 jQuery.className.add(this,c);
2445 * Removes all or the specified class from the set of matched elements.
2447 * @example $("p").removeClass()
2448 * @before <p class="selected">Hello</p>
2449 * @result [ <p>Hello</p> ]
2451 * @example $("p").removeClass("selected")
2452 * @before <p class="selected first">Hello</p>
2453 * @result [ <p class="first">Hello</p> ]
2457 * @param String class (optional) A CSS class to remove from the elements
2460 removeClass: function(c){
2461 jQuery.className.remove(this,c);
2465 * Adds the specified class if it is not present, removes it if it is
2468 * @example $("p").toggleClass("selected")
2469 * @before <p>Hello</p><p class="selected">Hello Again</p>
2470 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2474 * @param String class A CSS class with which to toggle the elements
2477 toggleClass: function( c ){
2478 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2482 * Removes all matched elements from the DOM. This does NOT remove them from the
2483 * jQuery object, allowing you to use the matched elements further.
2485 * @example $("p").remove();
2486 * @before <p>Hello</p> how are <p>you?</p>
2491 * @cat DOM/Manipulation
2495 * Removes only elements (out of the list of matched elements) that match
2496 * the specified jQuery expression. This does NOT remove them from the
2497 * jQuery object, allowing you to use the matched elements further.
2499 * @example $("p").remove(".hello");
2500 * @before <p class="hello">Hello</p> how are <p>you?</p>
2501 * @result how are <p>you?</p>
2505 * @param String expr A jQuery expression to filter elements by.
2506 * @cat DOM/Manipulation
2508 remove: function(a){
2509 if ( !a || jQuery.filter( a, [this] ).r )
2510 this.parentNode.removeChild( this );
2514 * Removes all child nodes from the set of matched elements.
2516 * @example $("p").empty()
2517 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2518 * @result [ <p></p> ]
2522 * @cat DOM/Manipulation
2525 while ( this.firstChild )
2526 this.removeChild( this.firstChild );