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) {
25 // Shortcut for document ready
26 if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function
27 return jQuery(document).ready(a);
29 // Make sure that a selection was provided
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 this.set( 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 ) );
58 // See if an extra function was provided
59 var fn = arguments[ arguments.length - 1 ];
61 // If so, execute it in context
62 if ( fn && typeof fn == "function" )
68 // Map over the $ in case of overwrite
69 if ( typeof $ != "undefined" )
72 // Map the jQuery namespace to the '$' one
76 * This function accepts a string containing a CSS or
77 * basic XPath selector which is then used to match a set of elements.
79 * The core functionality of jQuery centers around this function.
80 * Everything in jQuery is based upon this, or uses this in some way.
81 * The most basic use of this function is to pass in an expression
82 * (usually consisting of CSS or XPath), which then finds all matching
85 * By default, $() looks for DOM elements within the context of the
86 * current HTML document.
88 * @example $("div > p")
89 * @desc This finds all p elements that are children of a div element.
90 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
91 * @result [ <p>two</p> ]
93 * @example $("input:radio", document.forms[0])
94 * @desc Searches for all inputs of type radio within the first form in the document
96 * @example $("div", xml.responseXML)
97 * @desc This finds all div elements within the specified XML document.
100 * @param String expr An expression to search with
101 * @param Element context (optional) A DOM Element, or Document, representing the base context.
105 * @see $(Element<Array>)
109 * This function accepts a string of raw HTML.
111 * The HTML string is different from the traditional selectors in that
112 * it creates the DOM elements representing that HTML string, on the fly,
113 * to be (assumedly) inserted into the document later.
115 * @example $("<div><p>Hello</p></div>").appendTo("#body")
116 * @desc Creates a div element (and all of its contents) dynamically,
117 * and appends it to the element with the ID of body. Internally, an
118 * element is created and it's innerHTML property set to the given markup.
119 * It is therefore both quite flexible and limited.
122 * @param String html A string of HTML to create on the fly.
128 * Wrap jQuery functionality around a specific DOM Element.
129 * This function also accepts XML Documents and Window objects
130 * as valid arguments (even though they are not DOM Elements).
132 * @example $(document).find("div > p")
133 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
134 * @result [ <p>two</p> ]
136 * @example $(document.body).background( "black" );
137 * @desc Sets the background color of the page to black.
140 * @param Element elem A DOM element to be encapsulated by a jQuery object.
146 * Wrap jQuery functionality around a set of DOM Elements.
148 * @example $( myForm.elements ).hide()
149 * @desc Hides all the input elements within a form
152 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
158 * A shorthand for $(document).ready(), allowing you to bind a function
159 * to be executed when the DOM document has finished loading. This function
160 * behaves just like $(document).ready(), in that it should be used to wrap
161 * all of the other $() operations on your page. While this function is,
162 * technically, chainable - there really isn't much use for chaining against it.
163 * You can have as many $(document).ready events on your page as you like.
165 * See ready(Function) for details about the ready event.
167 * @example $(function(){
168 * // Document is ready
170 * @desc Executes the function when the DOM is ready to be used.
173 * @param Function fn The function to execute when the DOM is ready.
179 * A means of creating a cloned copy of a jQuery object. This function
180 * copies the set of matched elements from one jQuery object and creates
181 * another, new, jQuery object containing the same elements.
183 * @example var div = $("div");
184 * $( div ).find("p");
185 * @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).
188 * @param jQuery obj The jQuery object to be cloned.
193 jQuery.fn = jQuery.prototype = {
195 * The current version of jQuery.
206 * The number of elements currently matched.
208 * @example $("img").length;
209 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
219 * The number of elements currently matched.
221 * @example $("img").size();
222 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
234 * Access all matched elements. This serves as a backwards-compatible
235 * way of accessing all matched elements (other than the jQuery object
236 * itself, which is, in fact, an array of elements).
238 * @example $("img").get();
239 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
240 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
243 * @type Array<Element>
248 * Access a single matched element. num is used to access the
249 * Nth element matched.
251 * @example $("img").get(1);
252 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
253 * @result [ <img src="test1.jpg"/> ]
257 * @param Number num Access the element in the Nth position.
260 get: function( num ) {
261 return num == undefined ?
263 // Return a 'clean' array
264 jQuery.makeArray( this ) :
266 // Return just the object
271 * Set the jQuery object to an array of elements.
273 * @example $("img").set([ document.body ]);
274 * @result $("img").set() == [ document.body ]
279 * @param Elements elems An array of elements
282 set: function( array ) {
283 // Use a tricky hack to make the jQuery object
284 // look and feel like an array
286 [].push.apply( this, array );
291 * Execute a function within the context of every matched element.
292 * This means that every time the passed-in function is executed
293 * (which is once for every element matched) the 'this' keyword
294 * points to the specific element.
296 * Additionally, the function, when executed, is passed a single
297 * argument representing the position of the element in the matched
300 * @example $("img").each(function(i){
301 * this.src = "test" + i + ".jpg";
303 * @before <img/> <img/>
304 * @result <img src="test0.jpg"/> <img src="test1.jpg"/>
305 * @desc Iterates over two images and sets their src property
309 * @param Function fn A function to execute
312 each: function( fn, args ) {
313 return jQuery.each( this, fn, args );
317 * Searches every matched element for the object and returns
318 * the index of the element, if found, starting with zero.
319 * Returns -1 if the object wasn't found.
321 * @example $("*").index(document.getElementById('foobar'))
322 * @before <div id="foobar"></div><b></b><span id="foo"></span>
325 * @example $("*").index(document.getElementById('foo'))
326 * @before <div id="foobar"></div><b></b><span id="foo"></span>
329 * @example $("*").index(document.getElementById('bar'))
330 * @before <div id="foobar"></div><b></b><span id="foo"></span>
335 * @param Object obj Object to search for
338 index: function( obj ) {
340 this.each(function(i){
341 if ( this == obj ) pos = i;
347 * Access a property on the first matched element.
348 * This method makes it easy to retrieve a property value
349 * from the first matched element.
351 * @example $("img").attr("src");
352 * @before <img src="test.jpg"/>
357 * @param String name The name of the property to access.
362 * Set a hash of key/value object properties to all matched elements.
363 * This serves as the best way to set a large number of properties
364 * on all matched elements.
366 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
368 * @result <img src="test.jpg" alt="Test Image"/>
372 * @param Hash prop A set of key/value pairs to set as object properties.
377 * Set a single property to a value, on all matched elements.
379 * Note that you can't set the name property of input elements in IE.
380 * Use $(html) or $().append(html) or $().html(html) to create elements
381 * on the fly including the name property.
383 * @example $("img").attr("src","test.jpg");
385 * @result <img src="test.jpg"/>
389 * @param String key The name of the property to set.
390 * @param Object value The value to set the property to.
393 attr: function( key, value, type ) {
394 // Check to see if we're setting style values
395 return typeof key != "string" || value != undefined ?
396 this.each(function(){
397 // See if we're setting a hash of styles
398 if ( value == undefined )
399 // Set all the styles
400 for ( var prop in key )
402 type ? this.style : this,
406 // See if we're setting a single key/value style
409 type ? this.style : this,
414 // Look for the case where we're accessing a style value
415 jQuery[ type || "attr" ]( this[0], key );
419 * Access a style property on the first matched element.
420 * This method makes it easy to retrieve a style property value
421 * from the first matched element.
423 * @example $("p").css("color");
424 * @before <p style="color:red;">Test Paragraph.</p>
426 * @desc Retrieves the color style of the first paragraph
428 * @example $("p").css("fontWeight");
429 * @before <p style="font-weight: bold;">Test Paragraph.</p>
431 * @desc Retrieves the font-weight style of the first paragraph.
432 * Note that for all style properties with a dash (like 'font-weight'), you have to
433 * write it in camelCase. In other words: Every time you have a '-' in a
434 * property, remove it and replace the next character with an uppercase
435 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
436 * borderStyle, borderBottomWidth etc.
440 * @param String name The name of the property to access.
445 * Set a hash of key/value style properties to all matched elements.
446 * This serves as the best way to set a large number of style properties
447 * on all matched elements.
449 * @example $("p").css({ color: "red", background: "blue" });
450 * @before <p>Test Paragraph.</p>
451 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
455 * @param Hash prop A set of key/value pairs to set as style properties.
460 * Set a single style property to a value, on all matched elements.
462 * @example $("p").css("color","red");
463 * @before <p>Test Paragraph.</p>
464 * @result <p style="color:red;">Test Paragraph.</p>
465 * @desc Changes the color of all paragraphs to red
469 * @param String key The name of the property to set.
470 * @param Object value The value to set the property to.
473 css: function( key, value ) {
474 return this.attr( key, value, "curCSS" );
478 * Retrieve the text contents of all matched elements. The result is
479 * a string that contains the combined text contents of all matched
480 * elements. This method works on both HTML and XML documents.
482 * @example $("p").text();
483 * @before <p>Test Paragraph.</p>
484 * @result Test Paragraph.
492 * Set the text contents of all matched elements. This has the same
493 * effect as calling .html() with your specified string.
495 * @example $("p").text("Some new text.");
496 * @before <p>Test Paragraph.</p>
497 * @result <p>Some new text.</p>
499 * @param String val The text value to set the contents of the element to.
506 // A surprisingly high number of people expect the
507 // .text() method to do this, so lets do it!
508 if ( typeof e == "string" )
509 return this.html( e );
513 for ( var j = 0, el = e.length; j < el; j++ ) {
514 var r = e[j].childNodes;
515 for ( var i = 0, rl = r.length; i < rl; i++ )
516 if ( r[i].nodeType != 8 )
517 t += r[i].nodeType != 1 ?
518 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
524 * Wrap all matched elements with a structure of other elements.
525 * This wrapping process is most useful for injecting additional
526 * stucture into a document, without ruining the original semantic
527 * qualities of a document.
529 * This works by going through the first element
530 * provided (which is generated, on the fly, from the provided HTML)
531 * and finds the deepest ancestor element within its
532 * structure - it is that element that will en-wrap everything else.
534 * This does not work with elements that contain text. Any necessary text
535 * must be added after the wrapping is done.
537 * @example $("p").wrap("<div class='wrap'></div>");
538 * @before <p>Test Paragraph.</p>
539 * @result <div class='wrap'><p>Test Paragraph.</p></div>
543 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
544 * @cat DOM/Manipulation
548 * Wrap all matched elements with a structure of other elements.
549 * This wrapping process is most useful for injecting additional
550 * stucture into a document, without ruining the original semantic
551 * qualities of a document.
553 * This works by going through the first element
554 * provided and finding the deepest ancestor element within its
555 * structure - it is that element that will en-wrap everything else.
557 * This does not work with elements that contain text. Any necessary text
558 * must be added after the wrapping is done.
560 * @example $("p").wrap( document.getElementById('content') );
561 * @before <p>Test Paragraph.</p><div id="content"></div>
562 * @result <div id="content"><p>Test Paragraph.</p></div>
566 * @param Element elem A DOM element that will be wrapped.
567 * @cat DOM/Manipulation
570 // The elements to wrap the target around
571 var a = jQuery.clean(arguments);
573 // Wrap each of the matched elements individually
574 return this.each(function(){
575 // Clone the structure that we're using to wrap
576 var b = a[0].cloneNode(true);
578 // Insert it before the element to be wrapped
579 this.parentNode.insertBefore( b, this );
581 // Find the deepest point in the wrap structure
582 while ( b.firstChild )
585 // Move the matched element to within the wrap structure
586 b.appendChild( this );
591 * Append any number of elements to the inside of every matched elements,
592 * generated from the provided HTML.
593 * This operation is similar to doing an appendChild to all the
594 * specified elements, adding them into the document.
596 * @example $("p").append("<b>Hello</b>");
597 * @before <p>I would like to say: </p>
598 * @result <p>I would like to say: <b>Hello</b></p>
602 * @param String html A string of HTML, that will be created on the fly and appended to the target.
603 * @cat DOM/Manipulation
607 * Append an element to the inside of all matched elements.
608 * This operation is similar to doing an appendChild to all the
609 * specified elements, adding them into the document.
611 * @example $("p").append( $("#foo")[0] );
612 * @before <p>I would like to say: </p><b id="foo">Hello</b>
613 * @result <p>I would like to say: <b id="foo">Hello</b></p>
617 * @param Element elem A DOM element that will be appended.
618 * @cat DOM/Manipulation
622 * Append any number of elements to the inside of all matched elements.
623 * This operation is similar to doing an appendChild to all the
624 * specified elements, adding them into the document.
626 * @example $("p").append( $("b") );
627 * @before <p>I would like to say: </p><b>Hello</b>
628 * @result <p>I would like to say: <b>Hello</b></p>
632 * @param Array<Element> elems An array of elements, all of which will be appended.
633 * @cat DOM/Manipulation
636 return this.domManip(arguments, true, 1, function(a){
637 this.appendChild( a );
642 * Prepend any number of elements to the inside of every matched elements,
643 * generated from the provided HTML.
644 * This operation is the best way to insert dynamically created elements
645 * inside, at the beginning, of all the matched element.
647 * @example $("p").prepend("<b>Hello</b>");
648 * @before <p>I would like to say: </p>
649 * @result <p><b>Hello</b>I would like to say: </p>
653 * @param String html A string of HTML, that will be created on the fly and appended to the target.
654 * @cat DOM/Manipulation
658 * Prepend an element to the inside of all matched elements.
659 * This operation is the best way to insert an element inside, at the
660 * beginning, of all the matched element.
662 * @example $("p").prepend( $("#foo")[0] );
663 * @before <p>I would like to say: </p><b id="foo">Hello</b>
664 * @result <p><b id="foo">Hello</b>I would like to say: </p>
668 * @param Element elem A DOM element that will be appended.
669 * @cat DOM/Manipulation
673 * Prepend any number of elements to the inside of all matched elements.
674 * This operation is the best way to insert a set of elements inside, at the
675 * beginning, of all the matched element.
677 * @example $("p").prepend( $("b") );
678 * @before <p>I would like to say: </p><b>Hello</b>
679 * @result <p><b>Hello</b>I would like to say: </p>
683 * @param Array<Element> elems An array of elements, all of which will be appended.
684 * @cat DOM/Manipulation
686 prepend: function() {
687 return this.domManip(arguments, true, -1, function(a){
688 this.insertBefore( a, this.firstChild );
693 * Insert any number of dynamically generated elements before each of the
696 * @example $("p").before("<b>Hello</b>");
697 * @before <p>I would like to say: </p>
698 * @result <b>Hello</b><p>I would like to say: </p>
702 * @param String html A string of HTML, that will be created on the fly and appended to the target.
703 * @cat DOM/Manipulation
707 * Insert an element before each of the matched elements.
709 * @example $("p").before( $("#foo")[0] );
710 * @before <p>I would like to say: </p><b id="foo">Hello</b>
711 * @result <b id="foo">Hello</b><p>I would like to say: </p>
715 * @param Element elem A DOM element that will be appended.
716 * @cat DOM/Manipulation
720 * Insert any number of elements before each of the matched elements.
722 * @example $("p").before( $("b") );
723 * @before <p>I would like to say: </p><b>Hello</b>
724 * @result <b>Hello</b><p>I would like to say: </p>
728 * @param Array<Element> elems An array of elements, all of which will be appended.
729 * @cat DOM/Manipulation
732 return this.domManip(arguments, false, 1, function(a){
733 this.parentNode.insertBefore( a, this );
738 * Insert any number of dynamically generated elements after each of the
741 * @example $("p").after("<b>Hello</b>");
742 * @before <p>I would like to say: </p>
743 * @result <p>I would like to say: </p><b>Hello</b>
747 * @param String html A string of HTML, that will be created on the fly and appended to the target.
748 * @cat DOM/Manipulation
752 * Insert an element after each of the matched elements.
754 * @example $("p").after( $("#foo")[0] );
755 * @before <b id="foo">Hello</b><p>I would like to say: </p>
756 * @result <p>I would like to say: </p><b id="foo">Hello</b>
760 * @param Element elem A DOM element that will be appended.
761 * @cat DOM/Manipulation
765 * Insert any number of elements after each of the matched elements.
767 * @example $("p").after( $("b") );
768 * @before <b>Hello</b><p>I would like to say: </p>
769 * @result <p>I would like to say: </p><b>Hello</b>
773 * @param Array<Element> elems An array of elements, all of which will be appended.
774 * @cat DOM/Manipulation
777 return this.domManip(arguments, false, -1, function(a){
778 this.parentNode.insertBefore( a, this.nextSibling );
783 * End the most recent 'destructive' operation, reverting the list of matched elements
784 * back to its previous state. After an end operation, the list of matched elements will
785 * revert to the last state of matched elements.
787 * @example $("p").find("span").end();
788 * @before <p><span>Hello</span>, how are you?</p>
789 * @result $("p").find("span").end() == [ <p>...</p> ]
793 * @cat DOM/Traversing
796 if( !(this.stack && this.stack.length) )
798 return this.set( this.stack.pop() );
802 * Searches for all elements that match the specified expression.
803 * This method is the optimal way of finding additional descendant
804 * elements with which to process.
806 * All searching is done using a jQuery expression. The expression can be
807 * written using CSS 1-3 Selector syntax, or basic XPath.
809 * @example $("p").find("span");
810 * @before <p><span>Hello</span>, how are you?</p>
811 * @result $("p").find("span") == [ <span>Hello</span> ]
815 * @param String expr An expression to search with.
816 * @cat DOM/Traversing
819 return this.pushStack( jQuery.map( this, function(a){
820 return jQuery.find(t,a);
825 * Create cloned copies of all matched DOM Elements. This does
826 * not create a cloned copy of this particular jQuery object,
827 * instead it creates duplicate copies of all DOM Elements.
828 * This is useful for moving copies of the elements to another
829 * location in the DOM.
831 * @example $("b").clone().prependTo("p");
832 * @before <b>Hello</b><p>, how are you?</p>
833 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
837 * @cat DOM/Manipulation
839 clone: function(deep) {
840 return this.pushStack( jQuery.map( this, function(a){
841 return a.cloneNode( deep != undefined ? deep : true );
846 * Removes all elements from the set of matched elements that do not
847 * match the specified expression. This method is used to narrow down
848 * the results of a search.
850 * All searching is done using a jQuery expression. The expression
851 * can be written using CSS 1-3 Selector syntax, or basic XPath.
853 * @example $("p").filter(".selected")
854 * @before <p class="selected">Hello</p><p>How are you?</p>
855 * @result [ <p class="selected">Hello</p> ]
859 * @param String expr An expression to search with.
860 * @cat DOM/Traversing
864 * Removes all elements from the set of matched elements that do not
865 * pass the specified filter. This method is used to narrow down
866 * the results of a search.
868 * The elements to filter are passed as the first argument, their
869 * index inside the set as the second.
871 * @example $("p").filter(function(element, index) {
872 * return $("ol", element).length == 0;
874 * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
875 * @result [ <p>How are you?</p> ]
876 * @desc Remove all elements that have a child ol element
880 * @param Function filter A function to use for filtering
881 * @cat DOM/Traversing
885 * Removes all elements from the set of matched elements that do not
886 * match at least one of the expressions passed to the function. This
887 * method is used when you want to filter the set of matched elements
888 * through more than one expression.
890 * Elements will be retained in the jQuery object if they match at
891 * least one of the expressions passed.
893 * @example $("p").filter([".selected", ":first"])
894 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
895 * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
899 * @param Array<String> exprs A set of expressions to evaluate against
900 * @cat DOM/Traversing
902 filter: function(t) {
903 return this.pushStack(
904 t.constructor == Array &&
905 jQuery.map(this,function(a){
906 for ( var i = 0, tl = t.length; i < tl; i++ )
907 if ( jQuery.filter(t[i],[a]).r.length )
912 t.constructor == Boolean &&
913 ( t ? this.get() : [] ) ||
915 typeof t == "function" &&
916 jQuery.grep( this, t ) ||
918 jQuery.filter(t,this).r, arguments );
922 * Removes the specified Element from the set of matched elements. This
923 * method is used to remove a single Element from a jQuery object.
925 * @example $("p").not( document.getElementById("selected") )
926 * @before <p>Hello</p><p id="selected">Hello Again</p>
927 * @result [ <p>Hello</p> ]
931 * @param Element el An element to remove from the set
932 * @cat DOM/Traversing
936 * Removes elements matching the specified expression from the set
937 * of matched elements. This method is used to remove one or more
938 * elements from a jQuery object.
940 * @example $("p").not("#selected")
941 * @before <p>Hello</p><p id="selected">Hello Again</p>
942 * @result [ <p>Hello</p> ]
946 * @param String expr An expression with which to remove matching elements
947 * @cat DOM/Traversing
950 return this.pushStack( typeof t == "string" ?
951 jQuery.filter(t,this,true).r :
952 jQuery.grep(this,function(a){ return a != t; }), arguments );
956 * Adds the elements matched by the expression to the jQuery object. This
957 * can be used to concatenate the result sets of two expressions.
959 * @example $("p").add("span")
960 * @before <p>Hello</p><p><span>Hello Again</span></p>
961 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
965 * @param String expr An expression whose matched elements are added
966 * @cat DOM/Traversing
970 * Adds each of the Elements in the array to the set of matched elements.
971 * This is used to add a set of Elements to a jQuery object.
973 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
974 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
975 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
979 * @param Array<Element> els An array of Elements to add
980 * @cat DOM/Traversing
984 * Adds a single Element to the set of matched elements. This is used to
985 * add a single Element to a jQuery object.
987 * @example $("p").add( document.getElementById("a") )
988 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
989 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
993 * @param Element el An Element to add
994 * @cat DOM/Traversing
997 return this.pushStack( jQuery.merge(
998 this.get(), typeof t == "string" ?
1000 t.constructor == Array ? t : [t] ), arguments );
1004 * Checks the current selection against an expression and returns true,
1005 * if at least one element of the selection fits the given expression.
1006 * Does return false, if no element fits or the expression is not valid.
1008 * @example $("input[@type='checkbox']").parent().is("form")
1009 * @before <form><input type="checkbox" /></form>
1011 * @desc Returns true, because the parent of the input is a form element
1013 * @example $("input[@type='checkbox']").parent().is("form")
1014 * @before <form><p><input type="checkbox" /></p></form>
1016 * @desc Returns false, because the parent of the input is a p element
1018 * @example $("form").is(null)
1019 * @before <form></form>
1021 * @desc An invalid expression always returns false.
1025 * @param String expr The expression with which to filter
1026 * @cat DOM/Traversing
1028 is: function(expr) {
1029 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1036 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1037 * @param Number dir If dir<0, process args in reverse order.
1038 * @param Function fn The function doing the DOM manipulation.
1042 domManip: function(args, table, dir, fn){
1043 var clone = this.length > 1;
1044 var a = jQuery.clean(args);
1048 return this.each(function(){
1051 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1052 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1054 for ( var i = 0, al = a.length; i < al; i++ )
1055 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1070 pushStack: function(a,args) {
1071 var fn = args && args.length > 1 && args[args.length-1];
1072 var fn2 = args && args.length > 2 && args[args.length-2];
1074 if ( fn && fn.constructor != Function ) fn = null;
1075 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1078 if ( !this.stack ) this.stack = [];
1079 this.stack.push( this.get() );
1082 var old = this.get();
1085 if ( fn2 && a.length || !fn2 )
1086 this.each( fn2 || fn ).set( old );
1088 this.set( old ).each( fn );
1096 * Extends the jQuery object itself. Can be used to add functions into
1097 * the jQuery namespace and to add plugin methods (plugins).
1099 * @example jQuery.fn.extend({
1100 * check: function() {
1101 * return this.each(function() { this.checked = true; });
1103 * uncheck: function() {
1104 * return this.each(function() { this.checked = false; });
1107 * $("input[@type=checkbox]").check();
1108 * $("input[@type=radio]").uncheck();
1109 * @desc Adds two plugin methods.
1111 * @example jQuery.extend({
1112 * min: function(a, b) { return a < b ? a : b; },
1113 * max: function(a, b) { return a > b ? a : b; }
1115 * @desc Adds two functions into the jQuery namespace
1118 * @param Object prop The object that will be merged into the jQuery object
1124 * Extend one object with one or more others, returning the original,
1125 * modified, object. This is a great utility for simple inheritance.
1127 * @example var settings = { validate: false, limit: 5, name: "foo" };
1128 * var options = { validate: true, name: "bar" };
1129 * jQuery.extend(settings, options);
1130 * @result settings == { validate: true, limit: 5, name: "bar" }
1131 * @desc Merge settings and options, modifying settings
1133 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1134 * var options = { validate: true, name: "bar" };
1135 * var settings = jQuery.extend({}, defaults, options);
1136 * @result settings == { validate: true, limit: 5, name: "bar" }
1137 * @desc Merge defaults and options, without modifying the defaults
1140 * @param Object target The object to extend
1141 * @param Object prop1 The object that will be merged into the first.
1142 * @param Object propN (optional) More objects to merge into the first
1146 jQuery.extend = jQuery.fn.extend = function() {
1147 // copy reference to target object
1148 var target = arguments[0],
1151 // extend jQuery itself if only one argument is passed
1152 if ( arguments.length == 1 ) {
1157 while (prop = arguments[a++])
1158 // Extend the base object
1159 for ( var i in prop ) target[i] = prop[i];
1161 // Return the modified object
1173 jQuery.initDone = true;
1175 jQuery.each( jQuery.macros.axis, function(i,n){
1176 jQuery.fn[ i ] = function(a) {
1177 var ret = jQuery.map(this,n);
1178 if ( a && typeof a == "string" )
1179 ret = jQuery.filter(a,ret).r;
1180 return this.pushStack( ret, arguments );
1184 jQuery.each( jQuery.macros.to, function(i,n){
1185 jQuery.fn[ i ] = function(){
1187 return this.each(function(){
1188 for ( var j = 0, al = a.length; j < al; j++ )
1189 jQuery(a[j])[n]( this );
1194 jQuery.each( jQuery.macros.each, function(i,n){
1195 jQuery.fn[ i ] = function() {
1196 return this.each( n, arguments );
1200 jQuery.each( jQuery.macros.filter, function(i,n){
1201 jQuery.fn[ n ] = function(num,fn) {
1202 return this.filter( ":" + n + "(" + num + ")", fn );
1206 jQuery.each( jQuery.macros.attr, function(i,n){
1208 jQuery.fn[ i ] = function(h) {
1209 return h == undefined ?
1210 this.length ? this[0][n] : null :
1215 jQuery.each( jQuery.macros.css, function(i,n){
1216 jQuery.fn[ n ] = function(h) {
1217 return h == undefined ?
1218 ( this.length ? jQuery.css( this[0], n ) : null ) :
1226 * A generic iterator function, which can be used to seemlessly
1227 * iterate over both objects and arrays. This function is not the same
1228 * as $().each() - which is used to iterate, exclusively, over a jQuery
1229 * object. This function can be used to iterate over anything.
1231 * @example $.each( [0,1,2], function(i){
1232 * alert( "Item #" + i + ": " + this );
1234 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1236 * @example $.each( { name: "John", lang: "JS" }, function(i){
1237 * alert( "Name: " + i + ", Value: " + this );
1239 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1242 * @param Object obj The object, or array, to iterate over.
1243 * @param Function fn The function that will be executed on every object.
1247 // args is for internal usage only
1248 each: function( obj, fn, args ) {
1249 if ( obj.length == undefined )
1250 for ( var i in obj )
1251 fn.apply( obj[i], args || [i, obj[i]] );
1253 for ( var i = 0, ol = obj.length; i < ol; i++ )
1254 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1259 add: function( elem, c ){
1260 jQuery.each( c.split(/\s+/), function(i, cur){
1261 if ( !jQuery.className.has( elem.className, cur ) )
1262 elem.className += ( elem.className ? " " : "" ) + cur;
1265 remove: function( elem, c ){
1266 elem.className = c ?
1267 jQuery.grep( elem.className.split(/\s+/), function(cur){
1268 return !jQuery.className.has( c, cur );
1271 has: function( classes, c ){
1272 return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
1277 * Swap in/out style options.
1280 swap: function(e,o,f) {
1281 for ( var i in o ) {
1282 e.style["old"+i] = e.style[i];
1287 e.style[i] = e.style["old"+i];
1290 css: function(e,p) {
1291 if ( p == "height" || p == "width" ) {
1292 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1294 for ( var i = 0, dl = d.length; i < dl; i++ ) {
1295 old["padding" + d[i]] = 0;
1296 old["border" + d[i] + "Width"] = 0;
1299 jQuery.swap( e, old, function() {
1300 if (jQuery.css(e,"display") != "none") {
1301 oHeight = e.offsetHeight;
1302 oWidth = e.offsetWidth;
1304 e = jQuery(e.cloneNode(true))
1305 .find(":radio").removeAttr("checked").end()
1307 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1308 }).appendTo(e.parentNode)[0];
1310 var parPos = jQuery.css(e.parentNode,"position");
1311 if ( parPos == "" || parPos == "static" )
1312 e.parentNode.style.position = "relative";
1314 oHeight = e.clientHeight;
1315 oWidth = e.clientWidth;
1317 if ( parPos == "" || parPos == "static" )
1318 e.parentNode.style.position = "static";
1320 e.parentNode.removeChild(e);
1324 return p == "height" ? oHeight : oWidth;
1327 return jQuery.curCSS( e, p );
1330 curCSS: function(elem, prop, force) {
1333 if (prop == 'opacity' && jQuery.browser.msie)
1334 return jQuery.attr(elem.style, 'opacity');
1336 if (prop == "float" || prop == "cssFloat")
1337 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1339 if (!force && elem.style[prop]) {
1341 ret = elem.style[prop];
1343 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1345 if (prop == "cssFloat" || prop == "styleFloat")
1348 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1349 var cur = document.defaultView.getComputedStyle(elem, null);
1352 ret = cur.getPropertyValue(prop);
1353 else if ( prop == 'display' )
1356 jQuery.swap(elem, { display: 'block' }, function() {
1357 var c = document.defaultView.getComputedStyle(this, '');
1358 ret = c && c.getPropertyValue(prop) || '';
1361 } else if (elem.currentStyle) {
1363 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1364 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1371 clean: function(a) {
1373 for ( var i = 0, al = a.length; i < al; i++ ) {
1375 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
1376 // Trim whitespace, otherwise indexOf won't work as expected
1377 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6),
1378 div = document.createElement("div"), wrap = [0,"",""];
1380 if ( s.substring(0,4) == "<opt" ) // option or optgroup
1381 wrap = [1, "<select>", "</select>"];
1382 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" )
1383 wrap = [1, "<table>", "</table>"];
1384 else if ( s3 == "<tr" )
1385 wrap = [2, "<table><tbody>", "</tbody></table>"];
1386 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above
1387 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1389 // Go to html and back, then peel off extra wrappers
1390 div.innerHTML = wrap[1] + s + wrap[2];
1391 while ( wrap[0]-- ) div = div.firstChild;
1393 // Remove IE's autoinserted <tbody> from table fragments
1394 if ( jQuery.browser.msie ) {
1396 // String was a <table>, *may* have spurious <tbody>
1397 if ( s6 == "<table" && s.indexOf("<tbody") < 0 )
1398 tb = div.firstChild && div.firstChild.childNodes;
1399 // String was a bare <thead> or <tfoot>
1400 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1401 tb = div.childNodes;
1403 for ( var n = tb.length-1; n >= 0 ; --n )
1404 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1405 tb[n].parentNode.removeChild(tb[n]);
1409 arg = div.childNodes;
1413 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1414 for ( var n = 0, argl = arg.length; n < argl; n++ ) // Handles Array, jQuery, DOM NodeList collections
1417 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1423 attr: function(elem, name, value){
1426 "class": "className",
1427 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1428 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1429 innerHTML: "innerHTML",
1430 className: "className",
1432 disabled: "disabled",
1434 readonly: "readOnly",
1435 selected: "selected"
1438 // IE actually uses filters for opacity ... elem is actually elem.style
1439 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1440 // IE has trouble with opacity if it does not have layout
1441 // Force it by setting the zoom level
1444 // Set the alpha filter to set the opacity
1445 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1446 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1448 } else if ( name == "opacity" && jQuery.browser.msie ) {
1449 return elem.filter ?
1450 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1453 // Mozilla doesn't play well with opacity 1
1454 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1457 // Certain attributes only work when accessed via the old DOM 0 way
1459 if ( value != undefined ) elem[fix[name]] = value;
1460 return elem[fix[name]];
1462 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1463 return elem.getAttributeNode(name).nodeValue;
1465 // IE elem.getAttribute passes even for style
1466 } else if ( elem.tagName ) {
1467 if ( value != undefined ) elem.setAttribute( name, value );
1468 return elem.getAttribute( name );
1471 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1472 if ( value != undefined ) elem[name] = value;
1478 * Remove the whitespace from the beginning and end of a string.
1480 * @example $.trim(" hello, how are you? ");
1481 * @result "hello, how are you?"
1485 * @param String str The string to trim.
1489 return t.replace(/^\s+|\s+$/g, "");
1492 makeArray: function( a ) {
1495 if ( a.constructor != Array ) {
1496 for ( var i = 0, al = a.length; i < al; i++ )
1504 inArray: function( b, a ) {
1505 for ( var i = 0, al = a.length; i < al; i++ )
1512 * Merge two arrays together, removing all duplicates. The final order
1513 * or the new array is: All the results from the first array, followed
1514 * by the unique results from the second array.
1516 * @example $.merge( [0,1,2], [2,3,4] )
1517 * @result [0,1,2,3,4]
1519 * @example $.merge( [3,2,1], [4,3,2] )
1524 * @param Array first The first array to merge.
1525 * @param Array second The second array to merge.
1528 merge: function(first, second) {
1529 var r = [].slice.call( first, 0 );
1531 // Now check for duplicates between the two arrays
1532 // and only add the unique items
1533 for ( var i = 0, sl = second.length; i < sl; i++ ) {
1534 // Check for duplicates
1535 if ( jQuery.inArray( second[i], r ) == -1 )
1536 // The item is unique, add it
1537 first.push( second[i] );
1544 * Filter items out of an array, by using a filter function.
1545 * The specified function will be passed two arguments: The
1546 * current array item and the index of the item in the array. The
1547 * function should return 'true' if you wish to keep the item in
1548 * the array, false if it should be removed.
1550 * @example $.grep( [0,1,2], function(i){
1557 * @param Array array The Array to find items in.
1558 * @param Function fn The function to process each item against.
1559 * @param Boolean inv Invert the selection - select the opposite of the function.
1562 grep: function(elems, fn, inv) {
1563 // If a string is passed in for the function, make a function
1564 // for it (a handy shortcut)
1565 if ( typeof fn == "string" )
1566 fn = new Function("a","i","return " + fn);
1570 // Go through the array, only saving the items
1571 // that pass the validator function
1572 for ( var i = 0, el = elems.length; i < el; i++ )
1573 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1574 result.push( elems[i] );
1580 * Translate all items in an array to another array of items.
1581 * The translation function that is provided to this method is
1582 * called for each item in the array and is passed one argument:
1583 * The item to be translated. The function can then return:
1584 * The translated value, 'null' (to remove the item), or
1585 * an array of values - which will be flattened into the full array.
1587 * @example $.map( [0,1,2], function(i){
1592 * @example $.map( [0,1,2], function(i){
1593 * return i > 0 ? i + 1 : null;
1597 * @example $.map( [0,1,2], function(i){
1598 * return [ i, i + 1 ];
1600 * @result [0, 1, 1, 2, 2, 3]
1604 * @param Array array The Array to translate.
1605 * @param Function fn The function to process each item against.
1608 map: function(elems, fn) {
1609 // If a string is passed in for the function, make a function
1610 // for it (a handy shortcut)
1611 if ( typeof fn == "string" )
1612 fn = new Function("a","return " + fn);
1614 var result = [], r = [];
1616 // Go through the array, translating each of the items to their
1617 // new value (or values).
1618 for ( var i = 0, el = elems.length; i < el; i++ ) {
1619 var val = fn(elems[i],i);
1621 if ( val !== null && val != undefined ) {
1622 if ( val.constructor != Array ) val = [val];
1623 result = result.concat( val );
1627 var r = [ result[0] ];
1629 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1630 for ( var j = 0; j < i; j++ )
1631 if ( result[i] == r[j] )
1634 r.push( result[i] );
1642 * Contains flags for the useragent, read from navigator.userAgent.
1643 * Available flags are: safari, opera, msie, mozilla
1644 * This property is available before the DOM is ready, therefore you can
1645 * use it to add ready events only for certain browsers.
1647 * There are situations where object detections is not reliable enough, in that
1648 * cases it makes sense to use browser detection. Simply try to avoid both!
1650 * A combination of browser and object detection yields quite reliable results.
1652 * @example $.browser.msie
1653 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1655 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1656 * @desc Alerts "this is safari!" only for safari browsers
1665 * Wheather the W3C compliant box model is being used.
1673 var b = navigator.userAgent.toLowerCase();
1675 // Figure out what browser is being used
1677 safari: /webkit/.test(b),
1678 opera: /opera/.test(b),
1679 msie: /msie/.test(b) && !/opera/.test(b),
1680 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1683 // Check to see if the W3C box model is being used
1684 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1690 * Append all of the matched elements to another, specified, set of elements.
1691 * This operation is, essentially, the reverse of doing a regular
1692 * $(A).append(B), in that instead of appending B to A, you're appending
1695 * @example $("p").appendTo("#foo");
1696 * @before <p>I would like to say: </p><div id="foo"></div>
1697 * @result <div id="foo"><p>I would like to say: </p></div>
1701 * @param String expr A jQuery expression of elements to match.
1702 * @cat DOM/Manipulation
1707 * Prepend all of the matched elements to another, specified, set of elements.
1708 * This operation is, essentially, the reverse of doing a regular
1709 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1712 * @example $("p").prependTo("#foo");
1713 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1714 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1718 * @param String expr A jQuery expression of elements to match.
1719 * @cat DOM/Manipulation
1721 prependTo: "prepend",
1724 * Insert all of the matched elements before another, specified, set of elements.
1725 * This operation is, essentially, the reverse of doing a regular
1726 * $(A).before(B), in that instead of inserting B before A, you're inserting
1729 * @example $("p").insertBefore("#foo");
1730 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1731 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1733 * @name insertBefore
1735 * @param String expr A jQuery expression of elements to match.
1736 * @cat DOM/Manipulation
1738 insertBefore: "before",
1741 * Insert all of the matched elements after another, specified, set of elements.
1742 * This operation is, essentially, the reverse of doing a regular
1743 * $(A).after(B), in that instead of inserting B after A, you're inserting
1746 * @example $("p").insertAfter("#foo");
1747 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1748 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1752 * @param String expr A jQuery expression of elements to match.
1753 * @cat DOM/Manipulation
1755 insertAfter: "after"
1759 * Get the current CSS width of the first matched element.
1761 * @example $("p").width();
1762 * @before <p>This is just a test.</p>
1771 * Set the CSS width of every matched element. Be sure to include
1772 * the "px" (or other unit of measurement) after the number that you
1773 * specify, otherwise you might get strange results.
1775 * @example $("p").width("20px");
1776 * @before <p>This is just a test.</p>
1777 * @result <p style="width:20px;">This is just a test.</p>
1781 * @param String val Set the CSS property to the specified value.
1786 * Get the current CSS height of the first matched element.
1788 * @example $("p").height();
1789 * @before <p>This is just a test.</p>
1798 * Set the CSS height of every matched element. Be sure to include
1799 * the "px" (or other unit of measurement) after the number that you
1800 * specify, otherwise you might get strange results.
1802 * @example $("p").height("20px");
1803 * @before <p>This is just a test.</p>
1804 * @result <p style="height:20px;">This is just a test.</p>
1808 * @param String val Set the CSS property to the specified value.
1813 * Get the current CSS top of the first matched element.
1815 * @example $("p").top();
1816 * @before <p>This is just a test.</p>
1825 * Set the CSS top of every matched element. Be sure to include
1826 * the "px" (or other unit of measurement) after the number that you
1827 * specify, otherwise you might get strange results.
1829 * @example $("p").top("20px");
1830 * @before <p>This is just a test.</p>
1831 * @result <p style="top:20px;">This is just a test.</p>
1835 * @param String val Set the CSS property to the specified value.
1840 * Get the current CSS left of the first matched element.
1842 * @example $("p").left();
1843 * @before <p>This is just a test.</p>
1852 * Set the CSS left of every matched element. Be sure to include
1853 * the "px" (or other unit of measurement) after the number that you
1854 * specify, otherwise you might get strange results.
1856 * @example $("p").left("20px");
1857 * @before <p>This is just a test.</p>
1858 * @result <p style="left:20px;">This is just a test.</p>
1862 * @param String val Set the CSS property to the specified value.
1867 * Get the current CSS position of the first matched element.
1869 * @example $("p").position();
1870 * @before <p>This is just a test.</p>
1879 * Set the CSS position of every matched element.
1881 * @example $("p").position("relative");
1882 * @before <p>This is just a test.</p>
1883 * @result <p style="position:relative;">This is just a test.</p>
1887 * @param String val Set the CSS property to the specified value.
1892 * Get the current CSS float of the first matched element.
1894 * @example $("p").float();
1895 * @before <p>This is just a test.</p>
1904 * Set the CSS float of every matched element.
1906 * @example $("p").float("left");
1907 * @before <p>This is just a test.</p>
1908 * @result <p style="float:left;">This is just a test.</p>
1912 * @param String val Set the CSS property to the specified value.
1917 * Get the current CSS overflow of the first matched element.
1919 * @example $("p").overflow();
1920 * @before <p>This is just a test.</p>
1929 * Set the CSS overflow of every matched element.
1931 * @example $("p").overflow("auto");
1932 * @before <p>This is just a test.</p>
1933 * @result <p style="overflow:auto;">This is just a test.</p>
1937 * @param String val Set the CSS property to the specified value.
1942 * Get the current CSS color of the first matched element.
1944 * @example $("p").color();
1945 * @before <p>This is just a test.</p>
1954 * Set the CSS color of every matched element.
1956 * @example $("p").color("blue");
1957 * @before <p>This is just a test.</p>
1958 * @result <p style="color:blue;">This is just a test.</p>
1962 * @param String val Set the CSS property to the specified value.
1967 * Get the current CSS background of the first matched element.
1969 * @example $("p").background();
1970 * @before <p style="background:blue;">This is just a test.</p>
1979 * Set the CSS background of every matched element.
1981 * @example $("p").background("blue");
1982 * @before <p>This is just a test.</p>
1983 * @result <p style="background:blue;">This is just a test.</p>
1987 * @param String val Set the CSS property to the specified value.
1991 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1994 * Reduce the set of matched elements to a single element.
1995 * The position of the element in the set of matched elements
1996 * starts at 0 and goes to length - 1.
1998 * @example $("p").eq(1)
1999 * @before <p>This is just a test.</p><p>So is this</p>
2000 * @result [ <p>So is this</p> ]
2004 * @param Number pos The index of the element that you wish to limit to.
2009 * Reduce the set of matched elements to all elements before a given position.
2010 * The position of the element in the set of matched elements
2011 * starts at 0 and goes to length - 1.
2013 * @example $("p").lt(1)
2014 * @before <p>This is just a test.</p><p>So is this</p>
2015 * @result [ <p>This is just a test.</p> ]
2019 * @param Number pos Reduce the set to all elements below this position.
2024 * Reduce the set of matched elements to all elements after a given position.
2025 * The position of the element in the set of matched elements
2026 * starts at 0 and goes to length - 1.
2028 * @example $("p").gt(0)
2029 * @before <p>This is just a test.</p><p>So is this</p>
2030 * @result [ <p>So is this</p> ]
2034 * @param Number pos Reduce the set to all elements after this position.
2039 * Filter the set of elements to those that contain the specified text.
2041 * @example $("p").contains("test")
2042 * @before <p>This is just a test.</p><p>So is this</p>
2043 * @result [ <p>This is just a test.</p> ]
2047 * @param String str The string that will be contained within the text of an element.
2048 * @cat DOM/Traversing
2051 filter: [ "eq", "lt", "gt", "contains" ],
2055 * Get the current value of the first matched element.
2057 * @example $("input").val();
2058 * @before <input type="text" value="some text"/>
2059 * @result "some text"
2063 * @cat DOM/Attributes
2067 * Set the value of every matched element.
2069 * @example $("input").val("test");
2070 * @before <input type="text" value="some text"/>
2071 * @result <input type="text" value="test"/>
2075 * @param String val Set the property to the specified value.
2076 * @cat DOM/Attributes
2081 * Get the html contents of the first matched element.
2082 * This property is not available on XML documents.
2084 * @example $("div").html();
2085 * @before <div><input/></div>
2090 * @cat DOM/Attributes
2094 * Set the html contents of every matched element.
2095 * This property is not available on XML documents.
2097 * @example $("div").html("<b>new stuff</b>");
2098 * @before <div><input/></div>
2099 * @result <div><b>new stuff</b></div>
2103 * @param String val Set the html contents to the specified value.
2104 * @cat DOM/Attributes
2109 * Get the current id of the first matched element.
2111 * @example $("input").id();
2112 * @before <input type="text" id="test" value="some text"/>
2117 * @cat DOM/Attributes
2121 * Set the id of every matched element.
2123 * @example $("input").id("newid");
2124 * @before <input type="text" id="test" value="some text"/>
2125 * @result <input type="text" id="newid" value="some text"/>
2129 * @param String val Set the property to the specified value.
2130 * @cat DOM/Attributes
2135 * Get the current title of the first matched element.
2137 * @example $("img").title();
2138 * @before <img src="test.jpg" title="my image"/>
2139 * @result "my image"
2143 * @cat DOM/Attributes
2147 * Set the title of every matched element.
2149 * @example $("img").title("new title");
2150 * @before <img src="test.jpg" title="my image"/>
2151 * @result <img src="test.jpg" title="new image"/>
2155 * @param String val Set the property to the specified value.
2156 * @cat DOM/Attributes
2161 * Get the current name of the first matched element.
2163 * @example $("input").name();
2164 * @before <input type="text" name="username"/>
2165 * @result "username"
2169 * @cat DOM/Attributes
2173 * Set the name of every matched element.
2175 * @example $("input").name("user");
2176 * @before <input type="text" name="username"/>
2177 * @result <input type="text" name="user"/>
2181 * @param String val Set the property to the specified value.
2182 * @cat DOM/Attributes
2187 * Get the current href of the first matched element.
2189 * @example $("a").href();
2190 * @before <a href="test.html">my link</a>
2191 * @result "test.html"
2195 * @cat DOM/Attributes
2199 * Set the href of every matched element.
2201 * @example $("a").href("test2.html");
2202 * @before <a href="test.html">my link</a>
2203 * @result <a href="test2.html">my link</a>
2207 * @param String val Set the property to the specified value.
2208 * @cat DOM/Attributes
2213 * Get the current src of the first matched element.
2215 * @example $("img").src();
2216 * @before <img src="test.jpg" title="my image"/>
2217 * @result "test.jpg"
2221 * @cat DOM/Attributes
2225 * Set the src of every matched element.
2227 * @example $("img").src("test2.jpg");
2228 * @before <img src="test.jpg" title="my image"/>
2229 * @result <img src="test2.jpg" title="my image"/>
2233 * @param String val Set the property to the specified value.
2234 * @cat DOM/Attributes
2239 * Get the current rel of the first matched element.
2241 * @example $("a").rel();
2242 * @before <a href="test.html" rel="nofollow">my link</a>
2243 * @result "nofollow"
2247 * @cat DOM/Attributes
2251 * Set the rel of every matched element.
2253 * @example $("a").rel("nofollow");
2254 * @before <a href="test.html">my link</a>
2255 * @result <a href="test.html" rel="nofollow">my link</a>
2259 * @param String val Set the property to the specified value.
2260 * @cat DOM/Attributes
2267 * Get a set of elements containing the unique parents of the matched
2270 * @example $("p").parent()
2271 * @before <div><p>Hello</p><p>Hello</p></div>
2272 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2276 * @cat DOM/Traversing
2280 * Get a set of elements containing the unique parents of the matched
2281 * set of elements, and filtered by an expression.
2283 * @example $("p").parent(".selected")
2284 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2285 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2289 * @param String expr An expression to filter the parents with
2290 * @cat DOM/Traversing
2292 parent: "a.parentNode",
2295 * Get a set of elements containing the unique ancestors of the matched
2296 * set of elements (except for the root element).
2298 * @example $("span").parents()
2299 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2300 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2304 * @cat DOM/Traversing
2308 * Get a set of elements containing the unique ancestors of the matched
2309 * set of elements, and filtered by an expression.
2311 * @example $("span").parents("p")
2312 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2313 * @result [ <p><span>Hello</span></p> ]
2317 * @param String expr An expression to filter the ancestors with
2318 * @cat DOM/Traversing
2320 parents: jQuery.parents,
2323 * Get a set of elements containing the unique next siblings of each of the
2324 * matched set of elements.
2326 * It only returns the very next sibling, not all next siblings.
2328 * @example $("p").next()
2329 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2330 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2334 * @cat DOM/Traversing
2338 * Get a set of elements containing the unique next siblings of each of the
2339 * matched set of elements, and filtered by an expression.
2341 * It only returns the very next sibling, not all next siblings.
2343 * @example $("p").next(".selected")
2344 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2345 * @result [ <p class="selected">Hello Again</p> ]
2349 * @param String expr An expression to filter the next Elements with
2350 * @cat DOM/Traversing
2352 next: "jQuery.nth(a,1,'nextSibling')",
2355 * Get a set of elements containing the unique previous siblings of each of the
2356 * matched set of elements.
2358 * It only returns the immediately previous sibling, not all previous siblings.
2360 * @example $("p").prev()
2361 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2362 * @result [ <div><span>Hello Again</span></div> ]
2366 * @cat DOM/Traversing
2370 * Get a set of elements containing the unique previous siblings of each of the
2371 * matched set of elements, and filtered by an expression.
2373 * It only returns the immediately previous sibling, not all previous siblings.
2375 * @example $("p").prev(".selected")
2376 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2377 * @result [ <div><span>Hello</span></div> ]
2381 * @param String expr An expression to filter the previous Elements with
2382 * @cat DOM/Traversing
2384 prev: "jQuery.nth(a,1,'previousSibling')",
2387 * Get a set of elements containing all of the unique siblings of each of the
2388 * matched set of elements.
2390 * @example $("div").siblings()
2391 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2392 * @result [ <p>Hello</p>, <p>And Again</p> ]
2396 * @cat DOM/Traversing
2400 * Get a set of elements containing all of the unique siblings of each of the
2401 * matched set of elements, and filtered by an expression.
2403 * @example $("div").siblings(".selected")
2404 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2405 * @result [ <p class="selected">Hello Again</p> ]
2409 * @param String expr An expression to filter the sibling Elements with
2410 * @cat DOM/Traversing
2412 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
2415 * Get a set of elements containing all of the unique children of each of the
2416 * matched set of elements.
2418 * @example $("div").children()
2419 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2420 * @result [ <span>Hello Again</span> ]
2424 * @cat DOM/Traversing
2428 * Get a set of elements containing all of the unique children of each of the
2429 * matched set of elements, and filtered by an expression.
2431 * @example $("div").children(".selected")
2432 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2433 * @result [ <p class="selected">Hello Again</p> ]
2437 * @param String expr An expression to filter the child Elements with
2438 * @cat DOM/Traversing
2440 children: "jQuery.sibling(a.firstChild)"
2446 * Remove an attribute from each of the matched elements.
2448 * @example $("input").removeAttr("disabled")
2449 * @before <input disabled="disabled"/>
2454 * @param String name The name of the attribute to remove.
2457 removeAttr: function( key ) {
2458 jQuery.attr( this, key, "" );
2459 this.removeAttribute( key );
2463 * Displays each of the set of matched elements if they are hidden.
2465 * @example $("p").show()
2466 * @before <p style="display: none">Hello</p>
2467 * @result [ <p style="display: block">Hello</p> ]
2474 this.style.display = this.oldblock ? this.oldblock : "";
2475 if ( jQuery.css(this,"display") == "none" )
2476 this.style.display = "block";
2480 * Hides each of the set of matched elements if they are shown.
2482 * @example $("p").hide()
2483 * @before <p>Hello</p>
2484 * @result [ <p style="display: none">Hello</p> ]
2486 * var pass = true, div = $("div");
2487 * div.hide().each(function(){
2488 * if ( this.style.display != "none" ) pass = false;
2490 * ok( pass, "Hide" );
2497 this.oldblock = this.oldblock || jQuery.css(this,"display");
2498 if ( this.oldblock == "none" )
2499 this.oldblock = "block";
2500 this.style.display = "none";
2504 * Toggles each of the set of matched elements. If they are shown,
2505 * toggle makes them hidden. If they are hidden, toggle
2508 * @example $("p").toggle()
2509 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2510 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2517 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2521 * Adds the specified class to each of the set of matched elements.
2523 * @example $("p").addClass("selected")
2524 * @before <p>Hello</p>
2525 * @result [ <p class="selected">Hello</p> ]
2529 * @param String class A CSS class to add to the elements
2532 addClass: function(c){
2533 jQuery.className.add(this,c);
2537 * Removes all or the specified class from the set of matched elements.
2539 * @example $("p").removeClass()
2540 * @before <p class="selected">Hello</p>
2541 * @result [ <p>Hello</p> ]
2543 * @example $("p").removeClass("selected")
2544 * @before <p class="selected first">Hello</p>
2545 * @result [ <p class="first">Hello</p> ]
2549 * @param String class (optional) A CSS class to remove from the elements
2552 removeClass: function(c){
2553 jQuery.className.remove(this,c);
2557 * Adds the specified class if it is not present, removes it if it is
2560 * @example $("p").toggleClass("selected")
2561 * @before <p>Hello</p><p class="selected">Hello Again</p>
2562 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2566 * @param String class A CSS class with which to toggle the elements
2569 toggleClass: function( c ){
2570 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2574 * Removes all matched elements from the DOM. This does NOT remove them from the
2575 * jQuery object, allowing you to use the matched elements further.
2577 * @example $("p").remove();
2578 * @before <p>Hello</p> how are <p>you?</p>
2583 * @cat DOM/Manipulation
2587 * Removes only elements (out of the list of matched elements) that match
2588 * the specified jQuery expression. This does NOT remove them from the
2589 * jQuery object, allowing you to use the matched elements further.
2591 * @example $("p").remove(".hello");
2592 * @before <p class="hello">Hello</p> how are <p>you?</p>
2593 * @result how are <p>you?</p>
2597 * @param String expr A jQuery expression to filter elements by.
2598 * @cat DOM/Manipulation
2600 remove: function(a){
2601 if ( !a || jQuery.filter( a, [this] ).r )
2602 this.parentNode.removeChild( this );
2606 * Removes all child nodes from the set of matched elements.
2608 * @example $("p").empty()
2609 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2610 * @result [ <p></p> ]
2614 * @cat DOM/Manipulation
2617 while ( this.firstChild )
2618 this.removeChild( this.firstChild );