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 any number of elements to the inside of every matched elements,
604 * generated from the provided HTML.
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>
614 * @param String html A string of HTML, that will be created on the fly and appended to the target.
615 * @cat DOM/Manipulation
619 * Append an element to the inside of all matched elements.
620 * This operation is similar to doing an appendChild to all the
621 * specified elements, adding them into the document.
623 * @example $("p").append( $("#foo")[0] );
624 * @before <p>I would like to say: </p><b id="foo">Hello</b>
625 * @result <p>I would like to say: <b id="foo">Hello</b></p>
629 * @param Element elem A DOM element that will be appended.
630 * @cat DOM/Manipulation
634 * Append any number of elements to the inside of all matched elements.
635 * This operation is similar to doing an appendChild to all the
636 * specified elements, adding them into the document.
638 * @example $("p").append( $("b") );
639 * @before <p>I would like to say: </p><b>Hello</b>
640 * @result <p>I would like to say: <b>Hello</b></p>
644 * @param Array<Element> elems An array of elements, all of which will be appended.
645 * @cat DOM/Manipulation
648 return this.domManip(arguments, true, 1, function(a){
649 this.appendChild( a );
654 * Prepend any number of elements to the inside of every matched elements,
655 * generated from the provided HTML.
656 * This operation is the best way to insert dynamically created elements
657 * inside, at the beginning, of all the matched element.
659 * @example $("p").prepend("<b>Hello</b>");
660 * @before <p>I would like to say: </p>
661 * @result <p><b>Hello</b>I would like to say: </p>
665 * @param String html A string of HTML, that will be created on the fly and appended to the target.
666 * @cat DOM/Manipulation
670 * Prepend an element to the inside of all matched elements.
671 * This operation is the best way to insert an element inside, at the
672 * beginning, of all the matched element.
674 * @example $("p").prepend( $("#foo")[0] );
675 * @before <p>I would like to say: </p><b id="foo">Hello</b>
676 * @result <p><b id="foo">Hello</b>I would like to say: </p>
680 * @param Element elem A DOM element that will be appended.
681 * @cat DOM/Manipulation
685 * Prepend any number of elements to the inside of all matched elements.
686 * This operation is the best way to insert a set of elements inside, at the
687 * beginning, of all the matched element.
689 * @example $("p").prepend( $("b") );
690 * @before <p>I would like to say: </p><b>Hello</b>
691 * @result <p><b>Hello</b>I would like to say: </p>
695 * @param Array<Element> elems An array of elements, all of which will be appended.
696 * @cat DOM/Manipulation
698 prepend: function() {
699 return this.domManip(arguments, true, -1, function(a){
700 this.insertBefore( a, this.firstChild );
705 * Insert any number of dynamically generated elements before each of the
708 * @example $("p").before("<b>Hello</b>");
709 * @before <p>I would like to say: </p>
710 * @result <b>Hello</b><p>I would like to say: </p>
714 * @param String html A string of HTML, that will be created on the fly and appended to the target.
715 * @cat DOM/Manipulation
719 * Insert an element before each of the matched elements.
721 * @example $("p").before( $("#foo")[0] );
722 * @before <p>I would like to say: </p><b id="foo">Hello</b>
723 * @result <b id="foo">Hello</b><p>I would like to say: </p>
727 * @param Element elem A DOM element that will be appended.
728 * @cat DOM/Manipulation
732 * Insert any number of elements before each of the matched elements.
734 * @example $("p").before( $("b") );
735 * @before <p>I would like to say: </p><b>Hello</b>
736 * @result <b>Hello</b><p>I would like to say: </p>
740 * @param Array<Element> elems An array of elements, all of which will be appended.
741 * @cat DOM/Manipulation
744 return this.domManip(arguments, false, 1, function(a){
745 this.parentNode.insertBefore( a, this );
750 * Insert any number of dynamically generated elements after each of the
753 * @example $("p").after("<b>Hello</b>");
754 * @before <p>I would like to say: </p>
755 * @result <p>I would like to say: </p><b>Hello</b>
759 * @param String html A string of HTML, that will be created on the fly and appended to the target.
760 * @cat DOM/Manipulation
764 * Insert an element after each of the matched elements.
766 * @example $("p").after( $("#foo")[0] );
767 * @before <b id="foo">Hello</b><p>I would like to say: </p>
768 * @result <p>I would like to say: </p><b id="foo">Hello</b>
772 * @param Element elem A DOM element that will be appended.
773 * @cat DOM/Manipulation
777 * Insert any number of elements after each of the matched elements.
779 * @example $("p").after( $("b") );
780 * @before <b>Hello</b><p>I would like to say: </p>
781 * @result <p>I would like to say: </p><b>Hello</b>
785 * @param Array<Element> elems An array of elements, all of which will be appended.
786 * @cat DOM/Manipulation
789 return this.domManip(arguments, false, -1, function(a){
790 this.parentNode.insertBefore( a, this.nextSibling );
795 * End the most recent 'destructive' operation, reverting the list of matched elements
796 * back to its previous state. After an end operation, the list of matched elements will
797 * revert to the last state of matched elements.
799 * @example $("p").find("span").end();
800 * @before <p><span>Hello</span>, how are you?</p>
801 * @result $("p").find("span").end() == [ <p>...</p> ]
805 * @cat DOM/Traversing
808 return this.prevObject || jQuery([]);
812 * Searches for all elements that match the specified expression.
813 * This method is the optimal way of finding additional descendant
814 * elements with which to process.
816 * All searching is done using a jQuery expression. The expression can be
817 * written using CSS 1-3 Selector syntax, or basic XPath.
819 * @example $("p").find("span");
820 * @before <p><span>Hello</span>, how are you?</p>
821 * @result $("p").find("span") == [ <span>Hello</span> ]
825 * @param String expr An expression to search with.
826 * @cat DOM/Traversing
829 return this.set( jQuery.map( this, function(a){
830 return jQuery.find(t,a);
835 * Create cloned copies of all matched DOM Elements. This does
836 * not create a cloned copy of this particular jQuery object,
837 * instead it creates duplicate copies of all DOM Elements.
838 * This is useful for moving copies of the elements to another
839 * location in the DOM.
841 * @example $("b").clone().prependTo("p");
842 * @before <b>Hello</b><p>, how are you?</p>
843 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
847 * @cat DOM/Manipulation
849 clone: function(deep) {
850 return this.set( jQuery.map( this, function(a){
851 return a.cloneNode( deep != undefined ? deep : true );
856 * Removes all elements from the set of matched elements that do not
857 * match the specified expression. This method is used to narrow down
858 * the results of a search.
860 * All searching is done using a jQuery expression. The expression
861 * can be written using CSS 1-3 Selector syntax, or basic XPath.
863 * @example $("p").filter(".selected")
864 * @before <p class="selected">Hello</p><p>How are you?</p>
865 * @result [ <p class="selected">Hello</p> ]
869 * @param String expr An expression to search with.
870 * @cat DOM/Traversing
874 * Removes all elements from the set of matched elements that do not
875 * pass the specified filter. This method is used to narrow down
876 * the results of a search.
878 * The elements to filter are passed as the first argument, their
879 * index inside the set as the second.
881 * @example $("p").filter(function(element, index) {
882 * return $("ol", element).length == 0;
884 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
885 * @result [ <p>How are you?</p> ]
886 * @desc Remove all elements that have a child ol element
890 * @param Function filter A function to use for filtering
891 * @cat DOM/Traversing
895 * Removes all elements from the set of matched elements that do not
896 * match at least one of the expressions passed to the function. This
897 * method is used when you want to filter the set of matched elements
898 * through more than one expression.
900 * Elements will be retained in the jQuery object if they match at
901 * least one of the expressions passed.
903 * @example $("p").filter([".selected", ":first"])
904 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
905 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
909 * @param Array<String> exprs A set of expressions to evaluate against
910 * @cat DOM/Traversing
912 filter: function(t) {
914 t.constructor == Array &&
915 jQuery.map(this,function(a){
916 for ( var i = 0, tl = t.length; i < tl; i++ )
917 if ( jQuery.filter(t[i],[a]).r.length )
922 t.constructor == Boolean &&
923 ( t ? this.get() : [] ) ||
925 typeof t == "function" &&
926 jQuery.grep( this, t ) ||
928 jQuery.filter(t,this).r );
932 * Removes the specified Element from the set of matched elements. This
933 * method is used to remove a single Element from a jQuery object.
935 * @example $("p").not( document.getElementById("selected") )
936 * @before <p>Hello</p><p id="selected">Hello Again</p>
937 * @result [ <p>Hello</p> ]
941 * @param Element el An element to remove from the set
942 * @cat DOM/Traversing
946 * Removes elements matching the specified expression from the set
947 * of matched elements. This method is used to remove one or more
948 * elements from a jQuery object.
950 * @example $("p").not("#selected")
951 * @before <p>Hello</p><p id="selected">Hello Again</p>
952 * @result [ <p>Hello</p> ]
956 * @param String expr An expression with which to remove matching elements
957 * @cat DOM/Traversing
960 return this.set( typeof t == "string" ?
961 jQuery.filter(t,this,true).r :
962 jQuery.grep(this,function(a){ return a != t; }) );
966 * Adds the elements matched by the expression to the jQuery object. This
967 * can be used to concatenate the result sets of two expressions.
969 * @example $("p").add("span")
970 * @before <p>Hello</p><p><span>Hello Again</span></p>
971 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
975 * @param String expr An expression whose matched elements are added
976 * @cat DOM/Traversing
980 * Adds each of the Elements in the array to the set of matched elements.
981 * This is used to add a set of Elements to a jQuery object.
983 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
984 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
985 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
989 * @param Array<Element> els An array of Elements to add
990 * @cat DOM/Traversing
994 * Adds a single Element to the set of matched elements. This is used to
995 * add a single Element to a jQuery object.
997 * @example $("p").add( document.getElementById("a") )
998 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
999 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1003 * @param Element el An Element to add
1004 * @cat DOM/Traversing
1007 return this.set( jQuery.merge(
1008 this.get(), typeof t == "string" ?
1010 t.constructor == Array ? t : [t] ) );
1014 * Checks the current selection against an expression and returns true,
1015 * if at least one element of the selection fits the given expression.
1016 * Does return false, if no element fits or the expression is not valid.
1018 * @example $("input[@type='checkbox']").parent().is("form")
1019 * @before <form><input type="checkbox" /></form>
1021 * @desc Returns true, because the parent of the input is a form element
1023 * @example $("input[@type='checkbox']").parent().is("form")
1024 * @before <form><p><input type="checkbox" /></p></form>
1026 * @desc Returns false, because the parent of the input is a p element
1028 * @example $("form").is(null)
1029 * @before <form></form>
1031 * @desc An invalid expression always returns false.
1035 * @param String expr The expression with which to filter
1036 * @cat DOM/Traversing
1038 is: function(expr) {
1039 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1046 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1047 * @param Number dir If dir<0, process args in reverse order.
1048 * @param Function fn The function doing the DOM manipulation.
1052 domManip: function(args, table, dir, fn){
1053 var clone = this.length > 1;
1054 var a = jQuery.clean(args);
1058 return this.each(function(){
1061 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1062 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1064 for ( var i = 0, al = a.length; i < al; i++ )
1065 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1072 * Extends the jQuery object itself. Can be used to add functions into
1073 * the jQuery namespace and to add plugin methods (plugins).
1075 * @example jQuery.fn.extend({
1076 * check: function() {
1077 * return this.each(function() { this.checked = true; });
1079 * uncheck: function() {
1080 * return this.each(function() { this.checked = false; });
1083 * $("input[@type=checkbox]").check();
1084 * $("input[@type=radio]").uncheck();
1085 * @desc Adds two plugin methods.
1087 * @example jQuery.extend({
1088 * min: function(a, b) { return a < b ? a : b; },
1089 * max: function(a, b) { return a > b ? a : b; }
1091 * @desc Adds two functions into the jQuery namespace
1094 * @param Object prop The object that will be merged into the jQuery object
1100 * Extend one object with one or more others, returning the original,
1101 * modified, object. This is a great utility for simple inheritance.
1103 * @example var settings = { validate: false, limit: 5, name: "foo" };
1104 * var options = { validate: true, name: "bar" };
1105 * jQuery.extend(settings, options);
1106 * @result settings == { validate: true, limit: 5, name: "bar" }
1107 * @desc Merge settings and options, modifying settings
1109 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1110 * var options = { validate: true, name: "bar" };
1111 * var settings = jQuery.extend({}, defaults, options);
1112 * @result settings == { validate: true, limit: 5, name: "bar" }
1113 * @desc Merge defaults and options, without modifying the defaults
1116 * @param Object target The object to extend
1117 * @param Object prop1 The object that will be merged into the first.
1118 * @param Object propN (optional) More objects to merge into the first
1122 jQuery.extend = jQuery.fn.extend = function() {
1123 // copy reference to target object
1124 var target = arguments[0],
1127 // extend jQuery itself if only one argument is passed
1128 if ( arguments.length == 1 ) {
1133 while (prop = arguments[a++])
1134 // Extend the base object
1135 for ( var i in prop ) target[i] = prop[i];
1137 // Return the modified object
1149 jQuery.initDone = true;
1151 jQuery.each( jQuery.macros.axis, function(i,n){
1152 jQuery.fn[ i ] = function(a) {
1153 var ret = jQuery.map(this,n);
1154 if ( a && typeof a == "string" )
1155 ret = jQuery.filter(a,ret).r;
1156 return this.set( ret );
1160 jQuery.each( jQuery.macros.to, function(i,n){
1161 jQuery.fn[ i ] = function(){
1163 return this.each(function(){
1164 for ( var j = 0, al = a.length; j < al; j++ )
1165 jQuery(a[j])[n]( this );
1170 jQuery.each( jQuery.macros.each, function(i,n){
1171 jQuery.fn[ i ] = function() {
1172 return this.each( n, arguments );
1176 jQuery.each( jQuery.macros.filter, function(i,n){
1177 jQuery.fn[ n ] = function(num,fn) {
1178 return this.filter( ":" + n + "(" + num + ")", fn );
1182 jQuery.each( jQuery.macros.attr, function(i,n){
1184 jQuery.fn[ i ] = function(h) {
1185 return h == undefined ?
1186 this.length ? this[0][n] : null :
1191 jQuery.each( jQuery.macros.css, function(i,n){
1192 jQuery.fn[ n ] = function(h) {
1193 return h == undefined ?
1194 ( this.length ? jQuery.css( this[0], n ) : null ) :
1202 * A generic iterator function, which can be used to seemlessly
1203 * iterate over both objects and arrays. This function is not the same
1204 * as $().each() - which is used to iterate, exclusively, over a jQuery
1205 * object. This function can be used to iterate over anything.
1207 * @example $.each( [0,1,2], function(i){
1208 * alert( "Item #" + i + ": " + this );
1210 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1212 * @example $.each( { name: "John", lang: "JS" }, function(i){
1213 * alert( "Name: " + i + ", Value: " + this );
1215 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1218 * @param Object obj The object, or array, to iterate over.
1219 * @param Function fn The function that will be executed on every object.
1223 // args is for internal usage only
1224 each: function( obj, fn, args ) {
1225 if ( obj.length == undefined )
1226 for ( var i in obj )
1227 fn.apply( obj[i], args || [i, obj[i]] );
1229 for ( var i = 0, ol = obj.length; i < ol; i++ )
1230 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1235 add: function( elem, c ){
1236 jQuery.each( c.split(/\s+/), function(i, cur){
1237 if ( !jQuery.className.has( elem.className, cur ) )
1238 elem.className += ( elem.className ? " " : "" ) + cur;
1241 remove: function( elem, c ){
1242 elem.className = c ?
1243 jQuery.grep( elem.className.split(/\s+/), function(cur){
1244 return !jQuery.className.has( c, cur );
1247 has: function( classes, c ){
1248 return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
1253 * Swap in/out style options.
1256 swap: function(e,o,f) {
1257 for ( var i in o ) {
1258 e.style["old"+i] = e.style[i];
1263 e.style[i] = e.style["old"+i];
1266 css: function(e,p) {
1267 if ( p == "height" || p == "width" ) {
1268 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1270 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1271 old["padding" + d[i]] = 0;
1272 old["border" + d[i] + "Width"] = 0;
1275 jQuery.swap( e, old, function() {
1276 if (jQuery.css(e,"display") != "none") {
1277 oHeight = e.offsetHeight;
1278 oWidth = e.offsetWidth;
1280 e = jQuery(e.cloneNode(true))
1281 .find(":radio").removeAttr("checked").end()
1283 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1284 }).appendTo(e.parentNode)[0];
1286 var parPos = jQuery.css(e.parentNode,"position");
1287 if ( parPos == "" || parPos == "static" )
1288 e.parentNode.style.position = "relative";
1290 oHeight = e.clientHeight;
1291 oWidth = e.clientWidth;
1293 if ( parPos == "" || parPos == "static" )
1294 e.parentNode.style.position = "static";
1296 e.parentNode.removeChild(e);
1300 return p == "height" ? oHeight : oWidth;
1303 return jQuery.curCSS( e, p );
1306 curCSS: function(elem, prop, force) {
1309 if (prop == 'opacity' && jQuery.browser.msie)
1310 return jQuery.attr(elem.style, 'opacity');
1312 if (prop == "float" || prop == "cssFloat")
1313 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1315 if (!force && elem.style[prop]) {
1317 ret = elem.style[prop];
1319 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1321 if (prop == "cssFloat" || prop == "styleFloat")
1324 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1325 var cur = document.defaultView.getComputedStyle(elem, null);
1328 ret = cur.getPropertyValue(prop);
1329 else if ( prop == 'display' )
1332 jQuery.swap(elem, { display: 'block' }, function() {
1333 var c = document.defaultView.getComputedStyle(this, '');
1334 ret = c && c.getPropertyValue(prop) || '';
1337 } else if (elem.currentStyle) {
1339 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1340 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1347 clean: function(a) {
1349 for ( var i = 0, al = a.length; i < al; i++ ) {
1351 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
1352 // Trim whitespace, otherwise indexOf won't work as expected
1353 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6),
1354 div = document.createElement("div"), wrap = [0,"",""];
1356 if ( s.substring(0,4) == "<opt" ) // option or optgroup
1357 wrap = [1, "<select>", "</select>"];
1358 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" )
1359 wrap = [1, "<table>", "</table>"];
1360 else if ( s3 == "<tr" )
1361 wrap = [2, "<table><tbody>", "</tbody></table>"];
1362 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above
1363 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1365 // Go to html and back, then peel off extra wrappers
1366 div.innerHTML = wrap[1] + s + wrap[2];
1367 while ( wrap[0]-- ) div = div.firstChild;
1369 // Remove IE's autoinserted <tbody> from table fragments
1370 if ( jQuery.browser.msie ) {
1372 // String was a <table>, *may* have spurious <tbody>
1373 if ( s6 == "<table" && s.indexOf("<tbody") < 0 )
1374 tb = div.firstChild && div.firstChild.childNodes;
1375 // String was a bare <thead> or <tfoot>
1376 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1377 tb = div.childNodes;
1379 for ( var n = tb.length-1; n >= 0 ; --n )
1380 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1381 tb[n].parentNode.removeChild(tb[n]);
1385 arg = div.childNodes;
1389 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1390 for ( var n = 0, argl = arg.length; n < argl; n++ ) // Handles Array, jQuery, DOM NodeList collections
1393 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1399 attr: function(elem, name, value){
1402 "class": "className",
1403 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1404 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1405 innerHTML: "innerHTML",
1406 className: "className",
1408 disabled: "disabled",
1410 readonly: "readOnly",
1411 selected: "selected"
1414 // IE actually uses filters for opacity ... elem is actually elem.style
1415 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1416 // IE has trouble with opacity if it does not have layout
1417 // Force it by setting the zoom level
1420 // Set the alpha filter to set the opacity
1421 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1422 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1424 } else if ( name == "opacity" && jQuery.browser.msie ) {
1425 return elem.filter ?
1426 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1429 // Mozilla doesn't play well with opacity 1
1430 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1433 // Certain attributes only work when accessed via the old DOM 0 way
1435 if ( value != undefined ) elem[fix[name]] = value;
1436 return elem[fix[name]];
1438 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1439 return elem.getAttributeNode(name).nodeValue;
1441 // IE elem.getAttribute passes even for style
1442 } else if ( elem.tagName ) {
1443 if ( value != undefined ) elem.setAttribute( name, value );
1444 return elem.getAttribute( name );
1447 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1448 if ( value != undefined ) elem[name] = value;
1454 * Remove the whitespace from the beginning and end of a string.
1456 * @example $.trim(" hello, how are you? ");
1457 * @result "hello, how are you?"
1461 * @param String str The string to trim.
1465 return t.replace(/^\s+|\s+$/g, "");
1468 makeArray: function( a ) {
1471 if ( a.constructor != Array ) {
1472 for ( var i = 0, al = a.length; i < al; i++ )
1480 inArray: function( b, a ) {
1481 for ( var i = 0, al = a.length; i < al; i++ )
1488 * Merge two arrays together, removing all duplicates. The final order
1489 * or the new array is: All the results from the first array, followed
1490 * by the unique results from the second array.
1492 * @example $.merge( [0,1,2], [2,3,4] )
1493 * @result [0,1,2,3,4]
1495 * @example $.merge( [3,2,1], [4,3,2] )
1500 * @param Array first The first array to merge.
1501 * @param Array second The second array to merge.
1504 merge: function(first, second) {
1505 var r = [].slice.call( first, 0 );
1507 // Now check for duplicates between the two arrays
1508 // and only add the unique items
1509 for ( var i = 0, sl = second.length; i < sl; i++ ) {
1510 // Check for duplicates
1511 if ( jQuery.inArray( second[i], r ) == -1 )
1512 // The item is unique, add it
1513 first.push( second[i] );
1520 * Filter items out of an array, by using a filter function.
1521 * The specified function will be passed two arguments: The
1522 * current array item and the index of the item in the array. The
1523 * function should return 'true' if you wish to keep the item in
1524 * the array, false if it should be removed.
1526 * @example $.grep( [0,1,2], function(i){
1533 * @param Array array The Array to find items in.
1534 * @param Function fn The function to process each item against.
1535 * @param Boolean inv Invert the selection - select the opposite of the function.
1538 grep: function(elems, fn, inv) {
1539 // If a string is passed in for the function, make a function
1540 // for it (a handy shortcut)
1541 if ( typeof fn == "string" )
1542 fn = new Function("a","i","return " + fn);
1546 // Go through the array, only saving the items
1547 // that pass the validator function
1548 for ( var i = 0, el = elems.length; i < el; i++ )
1549 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1550 result.push( elems[i] );
1556 * Translate all items in an array to another array of items.
1557 * The translation function that is provided to this method is
1558 * called for each item in the array and is passed one argument:
1559 * The item to be translated. The function can then return:
1560 * The translated value, 'null' (to remove the item), or
1561 * an array of values - which will be flattened into the full array.
1563 * @example $.map( [0,1,2], function(i){
1568 * @example $.map( [0,1,2], function(i){
1569 * return i > 0 ? i + 1 : null;
1573 * @example $.map( [0,1,2], function(i){
1574 * return [ i, i + 1 ];
1576 * @result [0, 1, 1, 2, 2, 3]
1580 * @param Array array The Array to translate.
1581 * @param Function fn The function to process each item against.
1584 map: function(elems, fn) {
1585 // If a string is passed in for the function, make a function
1586 // for it (a handy shortcut)
1587 if ( typeof fn == "string" )
1588 fn = new Function("a","return " + fn);
1590 var result = [], r = [];
1592 // Go through the array, translating each of the items to their
1593 // new value (or values).
1594 for ( var i = 0, el = elems.length; i < el; i++ ) {
1595 var val = fn(elems[i],i);
1597 if ( val !== null && val != undefined ) {
1598 if ( val.constructor != Array ) val = [val];
1599 result = result.concat( val );
1603 var r = [ result[0] ];
1605 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1606 for ( var j = 0; j < i; j++ )
1607 if ( result[i] == r[j] )
1610 r.push( result[i] );
1618 * Contains flags for the useragent, read from navigator.userAgent.
1619 * Available flags are: safari, opera, msie, mozilla
1620 * This property is available before the DOM is ready, therefore you can
1621 * use it to add ready events only for certain browsers.
1623 * There are situations where object detections is not reliable enough, in that
1624 * cases it makes sense to use browser detection. Simply try to avoid both!
1626 * A combination of browser and object detection yields quite reliable results.
1628 * @example $.browser.msie
1629 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1631 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1632 * @desc Alerts "this is safari!" only for safari browsers
1641 * Wheather the W3C compliant box model is being used.
1649 var b = navigator.userAgent.toLowerCase();
1651 // Figure out what browser is being used
1653 safari: /webkit/.test(b),
1654 opera: /opera/.test(b),
1655 msie: /msie/.test(b) && !/opera/.test(b),
1656 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1659 // Check to see if the W3C box model is being used
1660 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1666 * Append all of the matched elements to another, specified, set of elements.
1667 * This operation is, essentially, the reverse of doing a regular
1668 * $(A).append(B), in that instead of appending B to A, you're appending
1671 * @example $("p").appendTo("#foo");
1672 * @before <p>I would like to say: </p><div id="foo"></div>
1673 * @result <div id="foo"><p>I would like to say: </p></div>
1677 * @param String expr A jQuery expression of elements to match.
1678 * @cat DOM/Manipulation
1683 * Prepend all of the matched elements to another, specified, set of elements.
1684 * This operation is, essentially, the reverse of doing a regular
1685 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1688 * @example $("p").prependTo("#foo");
1689 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1690 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1694 * @param String expr A jQuery expression of elements to match.
1695 * @cat DOM/Manipulation
1697 prependTo: "prepend",
1700 * Insert all of the matched elements before another, specified, set of elements.
1701 * This operation is, essentially, the reverse of doing a regular
1702 * $(A).before(B), in that instead of inserting B before A, you're inserting
1705 * @example $("p").insertBefore("#foo");
1706 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1707 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1709 * @name insertBefore
1711 * @param String expr A jQuery expression of elements to match.
1712 * @cat DOM/Manipulation
1714 insertBefore: "before",
1717 * Insert all of the matched elements after another, specified, set of elements.
1718 * This operation is, essentially, the reverse of doing a regular
1719 * $(A).after(B), in that instead of inserting B after A, you're inserting
1722 * @example $("p").insertAfter("#foo");
1723 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1724 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1728 * @param String expr A jQuery expression of elements to match.
1729 * @cat DOM/Manipulation
1731 insertAfter: "after"
1735 * Get the current CSS width of the first matched element.
1737 * @example $("p").width();
1738 * @before <p>This is just a test.</p>
1747 * Set the CSS width of every matched element. Be sure to include
1748 * the "px" (or other unit of measurement) after the number that you
1749 * specify, otherwise you might get strange results.
1751 * @example $("p").width("20px");
1752 * @before <p>This is just a test.</p>
1753 * @result <p style="width:20px;">This is just a test.</p>
1757 * @param String val Set the CSS property to the specified value.
1762 * Get the current CSS height of the first matched element.
1764 * @example $("p").height();
1765 * @before <p>This is just a test.</p>
1774 * Set the CSS height of every matched element. Be sure to include
1775 * the "px" (or other unit of measurement) after the number that you
1776 * specify, otherwise you might get strange results.
1778 * @example $("p").height("20px");
1779 * @before <p>This is just a test.</p>
1780 * @result <p style="height:20px;">This is just a test.</p>
1784 * @param String val Set the CSS property to the specified value.
1789 * Get the current CSS top of the first matched element.
1791 * @example $("p").top();
1792 * @before <p>This is just a test.</p>
1801 * Set the CSS top of every matched element. Be sure to include
1802 * the "px" (or other unit of measurement) after the number that you
1803 * specify, otherwise you might get strange results.
1805 * @example $("p").top("20px");
1806 * @before <p>This is just a test.</p>
1807 * @result <p style="top:20px;">This is just a test.</p>
1811 * @param String val Set the CSS property to the specified value.
1816 * Get the current CSS left of the first matched element.
1818 * @example $("p").left();
1819 * @before <p>This is just a test.</p>
1828 * Set the CSS left of every matched element. Be sure to include
1829 * the "px" (or other unit of measurement) after the number that you
1830 * specify, otherwise you might get strange results.
1832 * @example $("p").left("20px");
1833 * @before <p>This is just a test.</p>
1834 * @result <p style="left:20px;">This is just a test.</p>
1838 * @param String val Set the CSS property to the specified value.
1843 * Get the current CSS position of the first matched element.
1845 * @example $("p").position();
1846 * @before <p>This is just a test.</p>
1855 * Set the CSS position of every matched element.
1857 * @example $("p").position("relative");
1858 * @before <p>This is just a test.</p>
1859 * @result <p style="position:relative;">This is just a test.</p>
1863 * @param String val Set the CSS property to the specified value.
1868 * Get the current CSS float of the first matched element.
1870 * @example $("p").float();
1871 * @before <p>This is just a test.</p>
1880 * Set the CSS float of every matched element.
1882 * @example $("p").float("left");
1883 * @before <p>This is just a test.</p>
1884 * @result <p style="float:left;">This is just a test.</p>
1888 * @param String val Set the CSS property to the specified value.
1893 * Get the current CSS overflow of the first matched element.
1895 * @example $("p").overflow();
1896 * @before <p>This is just a test.</p>
1905 * Set the CSS overflow of every matched element.
1907 * @example $("p").overflow("auto");
1908 * @before <p>This is just a test.</p>
1909 * @result <p style="overflow:auto;">This is just a test.</p>
1913 * @param String val Set the CSS property to the specified value.
1918 * Get the current CSS color of the first matched element.
1920 * @example $("p").color();
1921 * @before <p>This is just a test.</p>
1930 * Set the CSS color of every matched element.
1932 * @example $("p").color("blue");
1933 * @before <p>This is just a test.</p>
1934 * @result <p style="color:blue;">This is just a test.</p>
1938 * @param String val Set the CSS property to the specified value.
1943 * Get the current CSS background of the first matched element.
1945 * @example $("p").background();
1946 * @before <p style="background:blue;">This is just a test.</p>
1955 * Set the CSS background of every matched element.
1957 * @example $("p").background("blue");
1958 * @before <p>This is just a test.</p>
1959 * @result <p style="background:blue;">This is just a test.</p>
1963 * @param String val Set the CSS property to the specified value.
1967 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1970 * Reduce the set of matched elements to a single element.
1971 * The position of the element in the set of matched elements
1972 * starts at 0 and goes to length - 1.
1974 * @example $("p").eq(1)
1975 * @before <p>This is just a test.</p><p>So is this</p>
1976 * @result [ <p>So is this</p> ]
1980 * @param Number pos The index of the element that you wish to limit to.
1985 * Reduce the set of matched elements to all elements before a given position.
1986 * The position of the element in the set of matched elements
1987 * starts at 0 and goes to length - 1.
1989 * @example $("p").lt(1)
1990 * @before <p>This is just a test.</p><p>So is this</p>
1991 * @result [ <p>This is just a test.</p> ]
1995 * @param Number pos Reduce the set to all elements below this position.
2000 * Reduce the set of matched elements to all elements after a given position.
2001 * The position of the element in the set of matched elements
2002 * starts at 0 and goes to length - 1.
2004 * @example $("p").gt(0)
2005 * @before <p>This is just a test.</p><p>So is this</p>
2006 * @result [ <p>So is this</p> ]
2010 * @param Number pos Reduce the set to all elements after this position.
2015 * Filter the set of elements to those that contain the specified text.
2017 * @example $("p").contains("test")
2018 * @before <p>This is just a test.</p><p>So is this</p>
2019 * @result [ <p>This is just a test.</p> ]
2023 * @param String str The string that will be contained within the text of an element.
2024 * @cat DOM/Traversing
2027 filter: [ "eq", "lt", "gt", "contains" ],
2031 * Get the current value of the first matched element.
2033 * @example $("input").val();
2034 * @before <input type="text" value="some text"/>
2035 * @result "some text"
2039 * @cat DOM/Attributes
2043 * Set the value of every matched element.
2045 * @example $("input").val("test");
2046 * @before <input type="text" value="some text"/>
2047 * @result <input type="text" value="test"/>
2051 * @param String val Set the property to the specified value.
2052 * @cat DOM/Attributes
2057 * Get the html contents of the first matched element.
2058 * This property is not available on XML documents.
2060 * @example $("div").html();
2061 * @before <div><input/></div>
2066 * @cat DOM/Attributes
2070 * Set the html contents of every matched element.
2071 * This property is not available on XML documents.
2073 * @example $("div").html("<b>new stuff</b>");
2074 * @before <div><input/></div>
2075 * @result <div><b>new stuff</b></div>
2079 * @param String val Set the html contents to the specified value.
2080 * @cat DOM/Attributes
2085 * Get the current id of the first matched element.
2087 * @example $("input").id();
2088 * @before <input type="text" id="test" value="some text"/>
2093 * @cat DOM/Attributes
2097 * Set the id of every matched element.
2099 * @example $("input").id("newid");
2100 * @before <input type="text" id="test" value="some text"/>
2101 * @result <input type="text" id="newid" value="some text"/>
2105 * @param String val Set the property to the specified value.
2106 * @cat DOM/Attributes
2111 * Get the current title of the first matched element.
2113 * @example $("img").title();
2114 * @before <img src="test.jpg" title="my image"/>
2115 * @result "my image"
2119 * @cat DOM/Attributes
2123 * Set the title of every matched element.
2125 * @example $("img").title("new title");
2126 * @before <img src="test.jpg" title="my image"/>
2127 * @result <img src="test.jpg" title="new image"/>
2131 * @param String val Set the property to the specified value.
2132 * @cat DOM/Attributes
2137 * Get the current name of the first matched element.
2139 * @example $("input").name();
2140 * @before <input type="text" name="username"/>
2141 * @result "username"
2145 * @cat DOM/Attributes
2149 * Set the name of every matched element.
2151 * @example $("input").name("user");
2152 * @before <input type="text" name="username"/>
2153 * @result <input type="text" name="user"/>
2157 * @param String val Set the property to the specified value.
2158 * @cat DOM/Attributes
2163 * Get the current href of the first matched element.
2165 * @example $("a").href();
2166 * @before <a href="test.html">my link</a>
2167 * @result "test.html"
2171 * @cat DOM/Attributes
2175 * Set the href of every matched element.
2177 * @example $("a").href("test2.html");
2178 * @before <a href="test.html">my link</a>
2179 * @result <a href="test2.html">my link</a>
2183 * @param String val Set the property to the specified value.
2184 * @cat DOM/Attributes
2189 * Get the current src of the first matched element.
2191 * @example $("img").src();
2192 * @before <img src="test.jpg" title="my image"/>
2193 * @result "test.jpg"
2197 * @cat DOM/Attributes
2201 * Set the src of every matched element.
2203 * @example $("img").src("test2.jpg");
2204 * @before <img src="test.jpg" title="my image"/>
2205 * @result <img src="test2.jpg" title="my image"/>
2209 * @param String val Set the property to the specified value.
2210 * @cat DOM/Attributes
2215 * Get the current rel of the first matched element.
2217 * @example $("a").rel();
2218 * @before <a href="test.html" rel="nofollow">my link</a>
2219 * @result "nofollow"
2223 * @cat DOM/Attributes
2227 * Set the rel of every matched element.
2229 * @example $("a").rel("nofollow");
2230 * @before <a href="test.html">my link</a>
2231 * @result <a href="test.html" rel="nofollow">my link</a>
2235 * @param String val Set the property to the specified value.
2236 * @cat DOM/Attributes
2243 * Get a set of elements containing the unique parents of the matched
2246 * @example $("p").parent()
2247 * @before <div><p>Hello</p><p>Hello</p></div>
2248 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2252 * @cat DOM/Traversing
2256 * Get a set of elements containing the unique parents of the matched
2257 * set of elements, and filtered by an expression.
2259 * @example $("p").parent(".selected")
2260 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2261 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2265 * @param String expr An expression to filter the parents with
2266 * @cat DOM/Traversing
2268 parent: "a.parentNode",
2271 * Get a set of elements containing the unique ancestors of the matched
2272 * set of elements (except for the root element).
2274 * @example $("span").parents()
2275 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2276 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2280 * @cat DOM/Traversing
2284 * Get a set of elements containing the unique ancestors of the matched
2285 * set of elements, and filtered by an expression.
2287 * @example $("span").parents("p")
2288 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2289 * @result [ <p><span>Hello</span></p> ]
2293 * @param String expr An expression to filter the ancestors with
2294 * @cat DOM/Traversing
2296 parents: jQuery.parents,
2299 * Get a set of elements containing the unique next siblings of each of the
2300 * matched set of elements.
2302 * It only returns the very next sibling, not all next siblings.
2304 * @example $("p").next()
2305 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2306 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2310 * @cat DOM/Traversing
2314 * Get a set of elements containing the unique next siblings of each of the
2315 * matched set of elements, and filtered by an expression.
2317 * It only returns the very next sibling, not all next siblings.
2319 * @example $("p").next(".selected")
2320 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2321 * @result [ <p class="selected">Hello Again</p> ]
2325 * @param String expr An expression to filter the next Elements with
2326 * @cat DOM/Traversing
2328 next: "jQuery.nth(a,1,'nextSibling')",
2331 * Get a set of elements containing the unique previous siblings of each of the
2332 * matched set of elements.
2334 * It only returns the immediately previous sibling, not all previous siblings.
2336 * @example $("p").prev()
2337 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2338 * @result [ <div><span>Hello Again</span></div> ]
2342 * @cat DOM/Traversing
2346 * Get a set of elements containing the unique previous siblings of each of the
2347 * matched set of elements, and filtered by an expression.
2349 * It only returns the immediately previous sibling, not all previous siblings.
2351 * @example $("p").prev(".selected")
2352 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2353 * @result [ <div><span>Hello</span></div> ]
2357 * @param String expr An expression to filter the previous Elements with
2358 * @cat DOM/Traversing
2360 prev: "jQuery.nth(a,1,'previousSibling')",
2363 * Get a set of elements containing all of the unique siblings of each of the
2364 * matched set of elements.
2366 * @example $("div").siblings()
2367 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2368 * @result [ <p>Hello</p>, <p>And Again</p> ]
2372 * @cat DOM/Traversing
2376 * Get a set of elements containing all of the unique siblings of each of the
2377 * matched set of elements, and filtered by an expression.
2379 * @example $("div").siblings(".selected")
2380 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2381 * @result [ <p class="selected">Hello Again</p> ]
2385 * @param String expr An expression to filter the sibling Elements with
2386 * @cat DOM/Traversing
2388 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
2391 * Get a set of elements containing all of the unique children of each of the
2392 * matched set of elements.
2394 * @example $("div").children()
2395 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2396 * @result [ <span>Hello Again</span> ]
2400 * @cat DOM/Traversing
2404 * Get a set of elements containing all of the unique children of each of the
2405 * matched set of elements, and filtered by an expression.
2407 * @example $("div").children(".selected")
2408 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2409 * @result [ <p class="selected">Hello Again</p> ]
2413 * @param String expr An expression to filter the child Elements with
2414 * @cat DOM/Traversing
2416 children: "jQuery.sibling(a.firstChild)"
2422 * Remove an attribute from each of the matched elements.
2424 * @example $("input").removeAttr("disabled")
2425 * @before <input disabled="disabled"/>
2430 * @param String name The name of the attribute to remove.
2433 removeAttr: function( key ) {
2434 jQuery.attr( this, key, "" );
2435 this.removeAttribute( key );
2439 * Displays each of the set of matched elements if they are hidden.
2441 * @example $("p").show()
2442 * @before <p style="display: none">Hello</p>
2443 * @result [ <p style="display: block">Hello</p> ]
2450 this.style.display = this.oldblock ? this.oldblock : "";
2451 if ( jQuery.css(this,"display") == "none" )
2452 this.style.display = "block";
2456 * Hides each of the set of matched elements if they are shown.
2458 * @example $("p").hide()
2459 * @before <p>Hello</p>
2460 * @result [ <p style="display: none">Hello</p> ]
2462 * var pass = true, div = $("div");
2463 * div.hide().each(function(){
2464 * if ( this.style.display != "none" ) pass = false;
2466 * ok( pass, "Hide" );
2473 this.oldblock = this.oldblock || jQuery.css(this,"display");
2474 if ( this.oldblock == "none" )
2475 this.oldblock = "block";
2476 this.style.display = "none";
2480 * Toggles each of the set of matched elements. If they are shown,
2481 * toggle makes them hidden. If they are hidden, toggle
2484 * @example $("p").toggle()
2485 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2486 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2493 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2497 * Adds the specified class to each of the set of matched elements.
2499 * @example $("p").addClass("selected")
2500 * @before <p>Hello</p>
2501 * @result [ <p class="selected">Hello</p> ]
2505 * @param String class A CSS class to add to the elements
2508 addClass: function(c){
2509 jQuery.className.add(this,c);
2513 * Removes all or the specified class from the set of matched elements.
2515 * @example $("p").removeClass()
2516 * @before <p class="selected">Hello</p>
2517 * @result [ <p>Hello</p> ]
2519 * @example $("p").removeClass("selected")
2520 * @before <p class="selected first">Hello</p>
2521 * @result [ <p class="first">Hello</p> ]
2525 * @param String class (optional) A CSS class to remove from the elements
2528 removeClass: function(c){
2529 jQuery.className.remove(this,c);
2533 * Adds the specified class if it is not present, removes it if it is
2536 * @example $("p").toggleClass("selected")
2537 * @before <p>Hello</p><p class="selected">Hello Again</p>
2538 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2542 * @param String class A CSS class with which to toggle the elements
2545 toggleClass: function( c ){
2546 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2550 * Removes all matched elements from the DOM. This does NOT remove them from the
2551 * jQuery object, allowing you to use the matched elements further.
2553 * @example $("p").remove();
2554 * @before <p>Hello</p> how are <p>you?</p>
2559 * @cat DOM/Manipulation
2563 * Removes only elements (out of the list of matched elements) that match
2564 * the specified jQuery expression. This does NOT remove them from the
2565 * jQuery object, allowing you to use the matched elements further.
2567 * @example $("p").remove(".hello");
2568 * @before <p class="hello">Hello</p> how are <p>you?</p>
2569 * @result how are <p>you?</p>
2573 * @param String expr A jQuery expression to filter elements by.
2574 * @cat DOM/Manipulation
2576 remove: function(a){
2577 if ( !a || jQuery.filter( a, [this] ).r )
2578 this.parentNode.removeChild( this );
2582 * Removes all child nodes from the set of matched elements.
2584 * @example $("p").empty()
2585 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2586 * @result [ <p></p> ]
2590 * @cat DOM/Manipulation
2593 while ( this.firstChild )
2594 this.removeChild( this.firstChild );