2 * jQuery - 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
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * @test ok( Function.prototype.apply, "Function.apply()" );
20 * @test ok( document.getElementById, "getElementById" );
21 * @test ok( document.getElementsByTagName, "getElementsByTagName" );
22 * @test ok( RegExp, "RegExp" );
23 * @test ok( jQuery, "jQuery" );
24 * @test ok( $, "$()" );
31 function jQuery(a,c) {
33 // Shortcut for document ready (because $(document).each() is silly)
34 if ( a && a.constructor == Function && jQuery.fn.ready )
35 return jQuery(document).ready(a);
37 // Make sure that a selection was provided
38 a = a || jQuery.context || document;
40 // Watch for when a jQuery object is passed as the selector
42 return jQuery( jQuery.merge( a, [] ) );
44 // Watch for when a jQuery object is passed at the context
46 return jQuery( c ).find(a);
48 // If the context is global, return a new object
50 return new jQuery(a,c);
52 // Handle HTML strings
53 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
54 if ( m ) a = jQuery.clean( [ m[1] ] );
56 // Watch for when an array is passed in
57 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
58 // Assume that it is an array of DOM Elements
59 jQuery.merge( a, [] ) :
61 // Find the matching elements and save them for later
62 jQuery.find( a, c ) );
64 // See if an extra function was provided
65 var fn = arguments[ arguments.length - 1 ];
67 // If so, execute it in context
68 if ( fn && fn.constructor == Function )
72 // Map over the $ in case of overwrite
73 if ( typeof $ != "undefined" )
77 * This function accepts a string containing a CSS selector,
78 * basic XPath, or raw HTML, which is then used to match a set of elements.
79 * The HTML string is different from the traditional selectors in that
80 * it creates the DOM elements representing that HTML string, on the fly,
81 * to be (assumedly) inserted into the document later.
83 * The core functionality of jQuery centers around this function.
84 * Everything in jQuery is based upon this, or uses this in some way.
85 * The most basic use of this function is to pass in an expression
86 * (usually consisting of CSS or XPath), which then finds all matching
87 * elements and remembers them for later use.
89 * By default, $() looks for DOM elements within the context of the
90 * current HTML document.
92 * @example $("div > p")
93 * @desc This finds all p elements that are children of a div element.
94 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
95 * @result [ <p>two</p> ]
97 * @example $("<div><p>Hello</p></div>").appendTo("#body")
98 * @desc Creates a div element (and all of its contents) dynamically, and appends it to the element with the ID of body.
101 * @param String expr An expression to search with, or a string of HTML to create on the fly.
107 * This function accepts a string containing a CSS selector, or
108 * basic XPath, which is then used to match a set of elements with the
109 * context of the specified DOM element, or document
111 * @example $("div", xml.responseXML)
112 * @desc This finds all div elements within the specified XML document.
115 * @param String expr An expression to search with.
116 * @param Element context A DOM Element, or Document, representing the base context.
122 * Wrap jQuery functionality around a specific DOM Element.
123 * This function also accepts XML Documents and Window objects
124 * as valid arguments (even though they are not DOM Elements).
126 * @example $(document).find("div > p")
127 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
128 * @result [ <p>two</p> ]
130 * @example $(document).ready( loaded );
131 * @desc Executes the "loaded" function when the DOM is ready to
135 * @param Element elem A DOM element to be encapsulated by a jQuery object.
141 * Wrap jQuery functionality around a set of DOM Elements.
143 * @example $( myForm.elements ).hide()
144 * @desc Hides all the input elements within a form
147 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
153 * A shorthand for $(document).ready(), allowing you to bind a function
154 * to be executed when the DOM document has finished loading.
156 * @example $( loaded )
157 * @desc Executes the function "loaded" when the DOM is ready to be used.
160 * @param Function fn The function to execute when the DOM is ready.
166 * A means of creating a duplicate copy of a jQuery object.
168 * @example var div = $("div");
170 * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div'.
173 * @param jQuery obj The jQuery object to be cloned.
178 // Map the jQuery namespace to the '$' one
181 jQuery.fn = jQuery.prototype = {
183 * The current SVN version of jQuery.
194 * The number of elements currently matched.
196 * @example $("img").length;
197 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
200 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
209 * The number of elements currently matched.
211 * @example $("img").size();
212 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
215 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
226 * Access all matched elements. This serves as a backwards-compatible
227 * way of accessing all matched elements (other than the jQuery object
228 * itself, which is, in fact, an array of elements).
230 * @example $("img").get();
231 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
232 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
234 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
237 * @type Array<Element>
242 * Access a single matched element. num is used to access the
243 * Nth element matched.
245 * @example $("img").get(1);
246 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
247 * @result [ <img src="test1.jpg"/> ]
249 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
253 * @param Number num Access the element in the Nth position.
258 * Set the jQuery object to an array of elements.
260 * @example $("img").get([ document.body ]);
261 * @result $("img").get() == [ document.body ]
266 * @param Elements elems An array of elements
269 get: function( num ) {
270 // Watch for when an array (of elements) is passed in
271 if ( num && num.constructor == Array ) {
273 // Use a tricky hack to make the jQuery object
274 // look and feel like an array
276 [].push.apply( this, num );
280 return num == undefined ?
282 // Return a 'clean' array
283 jQuery.merge( this, [] ) :
285 // Return just the object
290 * Execute a function within the context of every matched element.
291 * This means that every time the passed-in function is executed
292 * (which is once for every element matched) the 'this' keyword
293 * points to the specific element.
295 * Additionally, the function, when executed, is passed a single
296 * argument representing the position of the element in the matched
299 * @example $("img").each(function(){
300 * this.src = "test.jpg";
302 * @before <img/> <img/>
303 * @result <img src="test.jpg"/> <img src="test.jpg"/>
305 * @example $("img").each(function(i){
306 * alert( "Image #" + i + " is " + this );
308 * @before <img/> <img/>
309 * @result <img src="test.jpg"/> <img src="test.jpg"/>
311 * @test var div = $("div");
312 * div.each(function(){this.foo = 'zoo';});
314 * for ( var i = 0; i < div.size(); i++ ) {
315 * if ( div.get(i).foo != "zoo" ) pass = false;
317 * ok( pass, "Execute a function, Relative" );
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>
345 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
346 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
347 * var inputElements = $('#radio1,#radio2,#check1,#check2');
348 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
349 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
350 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
351 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
352 * ok( inputElements.index(window) == -1, "Check for not found index" );
353 * ok( inputElements.index(document) == -1, "Check for not found index" );
357 * @param Object obj Object to search for
360 index: function( obj ) {
362 this.each(function(i){
363 if ( this == obj ) pos = i;
369 * Access a property on the first matched element.
370 * This method makes it easy to retrieve a property value
371 * from the first matched element.
373 * @example $("img").attr("src");
374 * @before <img src="test.jpg"/>
377 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
378 * @test ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
379 * @test ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
380 * @test ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
384 * @param String name The name of the property to access.
389 * Set a hash of key/value object properties to all matched elements.
390 * This serves as the best way to set a large number of properties
391 * on all matched elements.
393 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
395 * @result <img src="test.jpg" alt="Test Image"/>
397 * @test var pass = true;
398 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
399 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
401 * ok( pass, "Set Multiple Attributes" );
405 * @param Hash prop A set of key/value pairs to set as object properties.
410 * Set a single property to a value, on all matched elements.
412 * @example $("img").attr("src","test.jpg");
414 * @result <img src="test.jpg"/>
416 * @test var div = $("div");
417 * div.attr("foo", "bar");
419 * for ( var i = 0; i < div.size(); i++ ) {
420 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
422 * ok( pass, "Set Attribute" );
426 * @param String key The name of the property to set.
427 * @param Object value The value to set the property to.
430 attr: function( key, value, type ) {
431 // Check to see if we're setting style values
432 return key.constructor != String || value != undefined ?
433 this.each(function(){
434 // See if we're setting a hash of styles
435 if ( value == undefined )
436 // Set all the styles
437 for ( var prop in key )
439 type ? this.style : this,
443 // See if we're setting a single key/value style
446 type ? this.style : this,
451 // Look for the case where we're accessing a style value
452 jQuery[ type || "attr" ]( this[0], key );
456 * Access a style property on the first matched element.
457 * This method makes it easy to retrieve a style property value
458 * from the first matched element.
460 * @example $("p").css("color");
461 * @before <p style="color:red;">Test Paragraph.</p>
464 * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
468 * @param String name The name of the property to access.
473 * Set a hash of key/value style properties to all matched elements.
474 * This serves as the best way to set a large number of style properties
475 * on all matched elements.
477 * @example $("p").css({ color: "red", background: "blue" });
478 * @before <p>Test Paragraph.</p>
479 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
481 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
482 * $('#foo').css({display: 'none'});
483 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
484 * $('#foo').css({display: 'block'});
485 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
489 * @param Hash prop A set of key/value pairs to set as style properties.
494 * Set a single style property to a value, on all matched elements.
496 * @example $("p").css("color","red");
497 * @before <p>Test Paragraph.</p>
498 * @result <p style="color:red;">Test Paragraph.</p>
500 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
501 * $('#foo').css('display', 'none');
502 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
503 * $('#foo').css('display', 'block');
504 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
508 * @param String key The name of the property to set.
509 * @param Object value The value to set the property to.
512 css: function( key, value ) {
513 return this.attr( key, value, "curCSS" );
517 * Retrieve the text contents of all matched elements. The result is
518 * a string that contains the combined text contents of all matched
519 * elements. This method works on both HTML and XML documents.
521 * @example $("p").text();
522 * @before <p>Test Paragraph.</p>
523 * @result Test Paragraph.
525 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
526 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
535 for ( var j = 0; j < e.length; j++ ) {
536 var r = e[j].childNodes;
537 for ( var i = 0; i < r.length; i++ )
538 if ( r[i].nodeType != 8 )
539 t += r[i].nodeType != 1 ?
540 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
546 * Wrap all matched elements with a structure of other elements.
547 * This wrapping process is most useful for injecting additional
548 * stucture into a document, without ruining the original semantic
549 * qualities of a document.
551 * This works by going through the first element
552 * provided (which is generated, on the fly, from the provided HTML)
553 * and finds the deepest ancestor element within its
554 * structure - it is that element that will en-wrap everything else.
556 * @example $("p").wrap("<div class='wrap'></div>");
557 * @before <p>Test Paragraph.</p>
558 * @result <div class='wrap'><p>Test Paragraph.</p></div>
560 * @test var defaultText = 'Try them out:'
561 * var result = $('#first').wrap('<div class="red">xx<span></span>yy</div>').text()
562 * ok( 'xx' + defaultText + 'yy' == result, 'Check for wrapping' );
563 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
567 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
568 * @cat DOM/Manipulation
572 * Wrap all matched elements with a structure of other elements.
573 * This wrapping process is most useful for injecting additional
574 * stucture into a document, without ruining the original semantic
575 * qualities of a document.
577 * This works by going through the first element
578 * provided and finding the deepest ancestor element within its
579 * structure - it is that element that will en-wrap everything else.
581 * @example $("p").wrap("<div class='wrap'></div>");
582 * @before <p>Test Paragraph.</p>
583 * @result <div class='wrap'><p>Test Paragraph.</p></div>
587 * @param Element elem A DOM element that will be wrapped.
588 * @cat DOM/Manipulation
591 // The elements to wrap the target around
592 var a = jQuery.clean(arguments);
594 // Wrap each of the matched elements individually
595 return this.each(function(){
596 // Clone the structure that we're using to wrap
597 var b = a[0].cloneNode(true);
599 // Insert it before the element to be wrapped
600 this.parentNode.insertBefore( b, this );
602 // Find he deepest point in the wrap structure
603 while ( b.firstChild )
606 // Move the matched element to within the wrap structure
607 b.appendChild( this );
612 * Append any number of elements to the inside of every matched elements,
613 * generated from the provided HTML.
614 * This operation is similar to doing an appendChild to all the
615 * specified elements, adding them into the document.
617 * @example $("p").append("<b>Hello</b>");
618 * @before <p>I would like to say: </p>
619 * @result <p>I would like to say: <b>Hello</b></p>
621 * @test var defaultText = 'Try them out:'
622 * var result = $('#first').append('<b>buga</b>');
623 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
627 * @param String html A string of HTML, that will be created on the fly and appended to the target.
628 * @cat DOM/Manipulation
632 * Append an element to the inside of all matched elements.
633 * This operation is similar to doing an appendChild to all the
634 * specified elements, adding them into the document.
636 * @example $("p").append( $("#foo")[0] );
637 * @before <p>I would like to say: </p><b id="foo">Hello</b>
638 * @result <p>I would like to say: <b id="foo">Hello</b></p>
640 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
641 * $('#sap').append(document.getElementById('first'));
642 * ok( expected == $('#sap').text(), "Check for appending of element" );
646 * @param Element elem A DOM element that will be appended.
647 * @cat DOM/Manipulation
651 * Append any number of elements to the inside of all matched elements.
652 * This operation is similar to doing an appendChild to all the
653 * specified elements, adding them into the document.
655 * @example $("p").append( $("b") );
656 * @before <p>I would like to say: </p><b>Hello</b>
657 * @result <p>I would like to say: <b>Hello</b></p>
659 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
660 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
661 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
665 * @param Array<Element> elems An array of elements, all of which will be appended.
666 * @cat DOM/Manipulation
669 return this.domManip(arguments, true, 1, function(a){
670 this.appendChild( a );
675 * Prepend any number of elements to the inside of every matched elements,
676 * generated from the provided HTML.
677 * This operation is the best way to insert dynamically created elements
678 * inside, at the beginning, of all the matched element.
680 * @example $("p").prepend("<b>Hello</b>");
681 * @before <p>I would like to say: </p>
682 * @result <p><b>Hello</b>I would like to say: </p>
684 * @test var defaultText = 'Try them out:'
685 * var result = $('#first').prepend('<b>buga</b>');
686 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
690 * @param String html A string of HTML, that will be created on the fly and appended to the target.
691 * @cat DOM/Manipulation
695 * Prepend an element to the inside of all matched elements.
696 * This operation is the best way to insert an element inside, at the
697 * beginning, of all the matched element.
699 * @example $("p").prepend( $("#foo")[0] );
700 * @before <p>I would like to say: </p><b id="foo">Hello</b>
701 * @result <p><b id="foo">Hello</b>I would like to say: </p>
703 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
704 * $('#sap').prepend(document.getElementById('first'));
705 * ok( expected == $('#sap').text(), "Check for prepending of element" );
709 * @param Element elem A DOM element that will be appended.
710 * @cat DOM/Manipulation
714 * Prepend any number of elements to the inside of all matched elements.
715 * This operation is the best way to insert a set of elements inside, at the
716 * beginning, of all the matched element.
718 * @example $("p").prepend( $("b") );
719 * @before <p>I would like to say: </p><b>Hello</b>
720 * @result <p><b>Hello</b>I would like to say: </p>
722 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
723 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
724 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
728 * @param Array<Element> elems An array of elements, all of which will be appended.
729 * @cat DOM/Manipulation
731 prepend: function() {
732 return this.domManip(arguments, true, -1, function(a){
733 this.insertBefore( a, this.firstChild );
738 * Insert any number of dynamically generated elements before each of the
741 * @example $("p").before("<b>Hello</b>");
742 * @before <p>I would like to say: </p>
743 * @result <b>Hello</b><p>I would like to say: </p>
745 * @test var expected = 'This is a normal link: bugaYahoo';
746 * $('#yahoo').before('<b>buga</b>');
747 * ok( expected == $('#en').text(), 'Insert String before' );
751 * @param String html A string of HTML, that will be created on the fly and appended to the target.
752 * @cat DOM/Manipulation
756 * Insert an element before each of the matched elements.
758 * @example $("p").before( $("#foo")[0] );
759 * @before <p>I would like to say: </p><b id="foo">Hello</b>
760 * @result <b id="foo">Hello</b><p>I would like to say: </p>
762 * @test var expected = "This is a normal link: Try them out:Yahoo";
763 * $('#yahoo').before(document.getElementById('first'));
764 * ok( expected == $('#en').text(), "Insert element before" );
768 * @param Element elem A DOM element that will be appended.
769 * @cat DOM/Manipulation
773 * Insert any number of elements before each of the matched elements.
775 * @example $("p").before( $("b") );
776 * @before <p>I would like to say: </p><b>Hello</b>
777 * @result <b>Hello</b><p>I would like to say: </p>
779 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
780 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
781 * ok( expected == $('#en').text(), "Insert array of elements before" );
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 );
795 * Insert any number of dynamically generated elements after each of the
798 * @example $("p").after("<b>Hello</b>");
799 * @before <p>I would like to say: </p>
800 * @result <p>I would like to say: </p><b>Hello</b>
802 * @test var expected = 'This is a normal link: Yahoobuga';
803 * $('#yahoo').after('<b>buga</b>');
804 * ok( expected == $('#en').text(), 'Insert String after' );
808 * @param String html A string of HTML, that will be created on the fly and appended to the target.
809 * @cat DOM/Manipulation
813 * Insert an element after each of the matched elements.
815 * @example $("p").after( $("#foo")[0] );
816 * @before <b id="foo">Hello</b><p>I would like to say: </p>
817 * @result <p>I would like to say: </p><b id="foo">Hello</b>
819 * @test var expected = "This is a normal link: YahooTry them out:";
820 * $('#yahoo').after(document.getElementById('first'));
821 * ok( expected == $('#en').text(), "Insert element after" );
825 * @param Element elem A DOM element that will be appended.
826 * @cat DOM/Manipulation
830 * Insert any number of elements after each of the matched elements.
832 * @example $("p").after( $("b") );
833 * @before <b>Hello</b><p>I would like to say: </p>
834 * @result <p>I would like to say: </p><b>Hello</b>
836 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
837 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
838 * ok( expected == $('#en').text(), "Insert array of elements after" );
842 * @param Array<Element> elems An array of elements, all of which will be appended.
843 * @cat DOM/Manipulation
846 return this.domManip(arguments, false, -1, function(a){
847 this.parentNode.insertBefore( a, this.nextSibling );
852 * End the most recent 'destructive' operation, reverting the list of matched elements
853 * back to its previous state. After an end operation, the list of matched elements will
854 * revert to the last state of matched elements.
856 * @example $("p").find("span").end();
857 * @before <p><span>Hello</span>, how are you?</p>
858 * @result $("p").find("span").end() == [ <p>...</p> ]
860 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
864 * @cat DOM/Traversing
867 return this.get( this.stack.pop() );
871 * Searches for all elements that match the specified expression.
872 * This method is the optimal way of finding additional descendant
873 * elements with which to process.
875 * All searching is done using a jQuery expression. The expression can be
876 * written using CSS 1-3 Selector syntax, or basic XPath.
878 * @example $("p").find("span");
879 * @before <p><span>Hello</span>, how are you?</p>
880 * @result $("p").find("span") == [ <span>Hello</span> ]
882 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
886 * @param String expr An expression to search with.
887 * @cat DOM/Traversing
890 return this.pushStack( jQuery.map( this, function(a){
891 return jQuery.find(t,a);
896 * Create cloned copies of all matched DOM Elements. This does
897 * not create a cloned copy of this particular jQuery object,
898 * instead it creates duplicate copies of all DOM Elements.
899 * This is useful for moving copies of the elements to another
900 * location in the DOM.
902 * @example $("b").clone().prependTo("p");
903 * @before <b>Hello</b><p>, how are you?</p>
904 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
906 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
907 * var clone = $('#yahoo').clone();
908 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
909 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
913 * @cat DOM/Manipulation
915 clone: function(deep) {
916 return this.pushStack( jQuery.map( this, function(a){
917 return a.cloneNode( deep != undefined ? deep : true );
922 * Removes all elements from the set of matched elements that do not
923 * match the specified expression. This method is used to narrow down
924 * the results of a search.
926 * All searching is done using a jQuery expression. The expression
927 * can be written using CSS 1-3 Selector syntax, or basic XPath.
929 * @example $("p").filter(".selected")
930 * @before <p class="selected">Hello</p><p>How are you?</p>
931 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
935 * @param String expr An expression to search with.
936 * @cat DOM/Traversing
940 * Removes all elements from the set of matched elements that do not
941 * match at least one of the expressions passed to the function. This
942 * method is used when you want to filter the set of matched elements
943 * through more than one expression.
945 * Elements will be retained in the jQuery object if they match at
946 * least one of the expressions passed.
948 * @example $("p").filter([".selected", ":first"])
949 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
950 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
954 * @param Array<String> exprs A set of expressions to evaluate against
955 * @cat DOM/Traversing
957 filter: function(t) {
958 return this.pushStack(
959 t.constructor == Array &&
960 jQuery.map(this,function(a){
961 for ( var i = 0; i < t.length; i++ )
962 if ( jQuery.filter(t[i],[a]).r.length )
966 t.constructor == Boolean &&
967 ( t ? this.get() : [] ) ||
969 t.constructor == Function &&
970 jQuery.grep( this, t ) ||
972 jQuery.filter(t,this).r, arguments );
976 * Removes the specified Element from the set of matched elements. This
977 * method is used to remove a single Element from a jQuery object.
979 * @example $("p").not( document.getElementById("selected") )
980 * @before <p>Hello</p><p id="selected">Hello Again</p>
981 * @result [ <p>Hello</p> ]
985 * @param Element el An element to remove from the set
986 * @cat DOM/Traversing
990 * Removes elements matching the specified expression from the set
991 * of matched elements. This method is used to remove one or more
992 * elements from a jQuery object.
994 * @example $("p").not("#selected")
995 * @before <p>Hello</p><p id="selected">Hello Again</p>
996 * @result [ <p>Hello</p> ]
997 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
1001 * @param String expr An expression with which to remove matching elements
1002 * @cat DOM/Traversing
1005 return this.pushStack( t.constructor == String ?
1006 jQuery.filter(t,this,false).r :
1007 jQuery.grep(this,function(a){ return a != t; }), arguments );
1011 * Adds the elements matched by the expression to the jQuery object. This
1012 * can be used to concatenate the result sets of two expressions.
1014 * @example $("p").add("span")
1015 * @before <p>Hello</p><p><span>Hello Again</span></p>
1016 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1020 * @param String expr An expression whose matched elements are added
1021 * @cat DOM/Traversing
1025 * Adds each of the Elements in the array to the set of matched elements.
1026 * This is used to add a set of Elements to a jQuery object.
1028 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1029 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1030 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1034 * @param Array<Element> els An array of Elements to add
1035 * @cat DOM/Traversing
1039 * Adds a single Element to the set of matched elements. This is used to
1040 * add a single Element to a jQuery object.
1042 * @example $("p").add( document.getElementById("a") )
1043 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1044 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1048 * @param Element el An Element to add
1049 * @cat DOM/Traversing
1052 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1053 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1057 * Checks the current selection against an expression and returns true,
1058 * if the selection fits the given expression. Does return false, if the
1059 * selection does not fit or the expression is not valid.
1061 * @example $("input[@type='checkbox']").parent().is("form")
1062 * @before <form><input type="checkbox" /></form>
1064 * @desc Returns true, because the parent of the input is a form element
1066 * @example $("input[@type='checkbox']").parent().is("form")
1067 * @before <form><p><input type="checkbox" /></p></form>
1069 * @desc Returns false, because the parent of the input is a p element
1071 * @example $("form").is(null)
1072 * @before <form></form>
1074 * @desc An invalid expression always returns false.
1076 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1077 * @test ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1078 * @test ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1079 * @test ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1080 * @test ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1081 * @test ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1082 * @test ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1083 * @test ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1084 * @test ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1085 * @test ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1086 * @test ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1087 * @test ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1088 * @test ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1089 * @test ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1090 * @test ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1091 * @test ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1092 * @test ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1093 * @test ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1094 * @test ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1095 * @test ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1096 * @test ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1097 * @test ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1101 * @param String expr The expression with which to filter
1102 * @cat DOM/Traversing
1104 is: function(expr) {
1105 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1114 * @param Boolean table
1116 * @param Function fn The function doing the DOM manipulation.
1120 domManip: function(args, table, dir, fn){
1121 var clone = this.size() > 1;
1122 var a = jQuery.clean(args);
1124 return this.each(function(){
1127 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
1128 var tbody = this.getElementsByTagName("tbody");
1130 if ( !tbody.length ) {
1131 obj = document.createElement("tbody");
1132 this.appendChild( obj );
1137 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1138 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1139 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1154 pushStack: function(a,args) {
1155 var fn = args && args[args.length-1];
1157 if ( !fn || fn.constructor != Function ) {
1158 if ( !this.stack ) this.stack = [];
1159 this.stack.push( this.get() );
1162 var old = this.get();
1164 if ( fn.constructor == Function )
1184 * Extend one object with another, returning the original,
1185 * modified, object. This is a great utility for simple inheritance.
1187 * @example var settings = { validate: false, limit: 5, name: "foo" };
1188 * var options = { validate: true, name: "bar" };
1189 * jQuery.extend(settings, options);
1190 * @result settings == { validate: true, limit: 5, name: "bar" }
1192 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1193 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1194 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1195 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1196 * jQuery.extend(settings, options);
1197 * isSet( settings, merged, "Check if extended: settings must be extended" );
1198 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1201 * @param Object obj The object to extend
1202 * @param Object prop The object that will be merged into the first.
1206 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1207 if ( !prop ) { prop = obj; obj = this; }
1208 for ( var i in prop ) obj[i] = prop[i];
1220 jQuery.initDone = true;
1222 jQuery.each( jQuery.macros.axis, function(i,n){
1223 jQuery.fn[ i ] = function(a) {
1224 var ret = jQuery.map(this,n);
1225 if ( a && a.constructor == String )
1226 ret = jQuery.filter(a,ret).r;
1227 return this.pushStack( ret, arguments );
1231 jQuery.each( jQuery.macros.to, function(i,n){
1232 jQuery.fn[ i ] = function(){
1234 return this.each(function(){
1235 for ( var j = 0; j < a.length; j++ )
1236 jQuery(a[j])[n]( this );
1241 jQuery.each( jQuery.macros.each, function(i,n){
1242 jQuery.fn[ i ] = function() {
1243 return this.each( n, arguments );
1247 jQuery.each( jQuery.macros.filter, function(i,n){
1248 jQuery.fn[ n ] = function(num,fn) {
1249 return this.filter( ":" + n + "(" + num + ")", fn );
1253 jQuery.each( jQuery.macros.attr, function(i,n){
1255 jQuery.fn[ i ] = function(h) {
1256 return h == undefined ?
1257 this.length ? this[0][n] : null :
1262 jQuery.each( jQuery.macros.css, function(i,n){
1263 jQuery.fn[ n ] = function(h) {
1264 return h == undefined ?
1265 ( this.length ? jQuery.css( this[0], n ) : null ) :
1273 * A generic iterator function, which can be used to seemlessly
1274 * iterate over both objects and arrays.
1277 * @param Object obj The object, or array, to iterate over.
1278 * @param Object fn The function that will be executed on every object.
1282 each: function( obj, fn, args ) {
1283 if ( obj.length == undefined )
1284 for ( var i in obj )
1285 fn.apply( obj[i], args || [i, obj[i]] );
1287 for ( var i = 0; i < obj.length; i++ )
1288 fn.apply( obj[i], args || [i, obj[i]] );
1294 if (jQuery.className.has(o,c)) return;
1295 o.className += ( o.className ? " " : "" ) + c;
1297 remove: function(o,c){
1298 o.className = !c ? "" :
1299 o.className.replace(
1300 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
1302 has: function(e,a) {
1303 if ( e.className != undefined )
1305 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1310 * Swap in/out style options.
1313 swap: function(e,o,f) {
1314 for ( var i in o ) {
1315 e.style["old"+i] = e.style[i];
1320 e.style[i] = e.style["old"+i];
1323 css: function(e,p) {
1324 if ( p == "height" || p == "width" ) {
1325 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1327 for ( var i in d ) {
1328 old["padding" + d[i]] = 0;
1329 old["border" + d[i] + "Width"] = 0;
1332 jQuery.swap( e, old, function() {
1333 if (jQuery.css(e,"display") != "none") {
1334 oHeight = e.offsetHeight;
1335 oWidth = e.offsetWidth;
1337 e = jQuery(e.cloneNode(true)).css({
1338 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1339 }).appendTo(e.parentNode)[0];
1341 var parPos = jQuery.css(e.parentNode,"position");
1342 if ( parPos == "" || parPos == "static" )
1343 e.parentNode.style.position = "relative";
1345 oHeight = e.clientHeight;
1346 oWidth = e.clientWidth;
1348 if ( parPos == "" || parPos == "static" )
1349 e.parentNode.style.position = "static";
1351 e.parentNode.removeChild(e);
1355 return p == "height" ? oHeight : oWidth;
1356 } else if ( p == "opacity" && jQuery.browser.msie )
1357 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1359 return jQuery.curCSS( e, p );
1362 curCSS: function(elem, prop, force) {
1365 if (!force && elem.style[prop]) {
1367 ret = elem.style[prop];
1369 } else if (elem.currentStyle) {
1371 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1372 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1374 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1376 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1377 var cur = document.defaultView.getComputedStyle(elem, null);
1380 ret = cur.getPropertyValue(prop);
1381 else if ( prop == 'display' )
1384 jQuery.swap(elem, { display: 'block' }, function() {
1385 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1393 clean: function(a) {
1395 for ( var i = 0; i < a.length; i++ ) {
1396 if ( a[i].constructor == String ) {
1400 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1402 a[i] = "<table>" + a[i] + "</table>";
1403 } else if ( !a[i].indexOf("<tr") ) {
1405 a[i] = "<table>" + a[i] + "</table>";
1406 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1408 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1411 var div = document.createElement("div");
1412 div.innerHTML = a[i];
1415 div = div.firstChild;
1416 if ( table != "thead" ) div = div.firstChild;
1417 if ( table == "td" ) div = div.firstChild;
1420 for ( var j = 0; j < div.childNodes.length; j++ )
1421 r.push( div.childNodes[j] );
1422 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1423 for ( var k = 0; k < a[i].length; k++ )
1425 else if ( a[i] !== null )
1426 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1432 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1433 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1441 last: "i==r.length-1",
1446 "nth-child": "jQuery.sibling(a,m[3]).cur",
1447 "first-child": "jQuery.sibling(a,0).cur",
1448 "last-child": "jQuery.sibling(a,0).last",
1449 "only-child": "jQuery.sibling(a).length==1",
1452 parent: "a.childNodes.length",
1453 empty: "!a.childNodes.length",
1456 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1459 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1460 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1463 enabled: "!a.disabled",
1464 disabled: "a.disabled",
1465 checked: "a.checked",
1466 selected: "a.selected"
1468 ".": "jQuery.className.has(a,m[2])",
1472 "^=": "!z.indexOf(m[4])",
1473 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1474 "*=": "z.indexOf(m[4])>=0",
1477 "[": "jQuery.find(m[2],a).length"
1481 "\\.\\.|/\\.\\.", "a.parentNode",
1482 ">|/", "jQuery.sibling(a.firstChild)",
1483 "\\+", "jQuery.sibling(a).next",
1486 var s = jQuery.sibling(a);
1488 for ( var i = s.n; i < s.length; i++ )
1496 * @test t( "Element Selector", "div", ["main","foo"] );
1497 * @test t( "Element Selector", "body", ["body"] );
1498 * @test t( "Element Selector", "html", ["html"] );
1499 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1500 * @test t( "Parent Element", "div div", ["foo"] );
1502 * @test t( "ID Selector", "#body", ["body"] );
1503 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1504 * @test t( "ID Selector w/ Element", "ul#first", [] );
1506 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1507 * @test t( "Class Selector", ".blog.link", ["simon"] );
1508 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1509 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1511 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1512 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1513 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1514 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1516 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1517 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1518 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1519 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1520 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1521 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1522 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1523 * @test t( "Adjacent", "a + a", ["groups"] );
1524 * @test t( "Adjacent", "a +a", ["groups"] );
1525 * @test t( "Adjacent", "a+ a", ["groups"] );
1526 * @test t( "Adjacent", "a+a", ["groups"] );
1527 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1528 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1529 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1530 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1531 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1532 * @test t( "Attribute Exists", "[@title]", ["google"] );
1533 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1534 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1535 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1536 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1537 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1538 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1540 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1541 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1542 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1543 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1544 * @test t( "Last Child", "p:last-child", ["sap"] );
1545 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1546 * @test t( "Empty", "ul:empty", ["firstUL"] );
1547 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1548 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1549 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1550 * @test t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1551 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1552 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1553 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1554 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1556 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1557 * @test t( "All Div Elements", "//div", ["main","foo"] );
1558 * @test t( "Absolute Path", "/html/body", ["body"] );
1559 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1560 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1561 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1562 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1563 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1564 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1565 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1566 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1567 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1568 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1569 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1571 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1572 * @test t( "First Element", "p:first", ["firstp"] );
1573 * @test t( "Last Element", "p:last", ["first"] );
1574 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1575 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1576 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1577 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1578 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1579 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1580 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1581 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1584 * @type Array<Element>
1588 find: function( t, context ) {
1589 // Make sure that the context is a DOM Element
1590 if ( context && context.nodeType == undefined )
1593 // Set the correct context (if none is provided)
1594 context = context || jQuery.context || document;
1596 if ( t.constructor != String ) return [t];
1598 if ( !t.indexOf("//") ) {
1599 context = context.documentElement;
1600 t = t.substr(2,t.length);
1601 } else if ( !t.indexOf("/") ) {
1602 context = context.documentElement;
1603 t = t.substr(1,t.length);
1604 // FIX Assume the root element is right :(
1605 if ( t.indexOf("/") >= 1 )
1606 t = t.substr(t.indexOf("/"),t.length);
1609 var ret = [context];
1613 while ( t.length > 0 && last != t ) {
1617 t = jQuery.trim(t).replace( /^\/\//i, "" );
1619 var foundToken = false;
1621 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1622 if ( foundToken ) continue;
1624 var re = new RegExp("^(" + jQuery.token[i] + ")");
1628 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1629 t = jQuery.trim( t.replace( re, "" ) );
1634 if ( !foundToken ) {
1635 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1636 if ( ret[0] == context ) ret.shift();
1637 done = jQuery.merge( done, ret );
1638 r = ret = [context];
1639 t = " " + t.substr(1,t.length);
1641 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1642 var m = re2.exec(t);
1644 if ( m[1] == "#" ) {
1645 // Ummm, should make this work in all XML docs
1646 var oid = document.getElementById(m[2]);
1647 r = ret = oid ? [oid] : [];
1648 t = t.replace( re2, "" );
1650 if ( !m[2] || m[1] == "." ) m[2] = "*";
1652 for ( var i = 0; i < ret.length; i++ )
1653 r = jQuery.merge( r,
1655 jQuery.getAll(ret[i]) :
1656 ret[i].getElementsByTagName(m[2])
1664 var val = jQuery.filter(t,r);
1666 t = jQuery.trim(val.t);
1670 if ( ret && ret[0] == context ) ret.shift();
1671 done = jQuery.merge( done, ret );
1676 getAll: function(o,r) {
1678 var s = o.childNodes;
1679 for ( var i = 0; i < s.length; i++ )
1680 if ( s[i].nodeType == 1 ) {
1682 jQuery.getAll( s[i], r );
1687 attr: function(elem, name, value){
1690 "class": "className",
1691 "float": "cssFloat",
1692 innerHTML: "innerHTML",
1693 className: "className",
1695 disabled: "disabled",
1700 if ( value != undefined ) elem[fix[name]] = value;
1701 return elem[fix[name]];
1702 } else if ( elem.getAttribute ) {
1703 if ( value != undefined ) elem.setAttribute( name, value );
1704 return elem.getAttribute( name, 2 );
1706 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1707 if ( value != undefined ) elem[name] = value;
1712 // The regular expressions that power the parsing engine
1714 // Match: [@value='test'], [@foo]
1715 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1717 // Match: [div], [div p]
1720 // Match: :contains('foo')
1721 [ "(:)S\\(Q\\)", 0 ],
1723 // Match: :even, :last-chlid
1727 filter: function(t,r,not) {
1728 // Figure out if we're doing regular, or inverse, filtering
1729 var g = not !== false ? jQuery.grep :
1730 function(a,f) {return jQuery.grep(a,f,true);};
1732 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1734 var p = jQuery.parse;
1736 for ( var i = 0; i < p.length; i++ ) {
1737 var re = new RegExp( "^" + p[i][0]
1739 // Look for a string-like sequence
1740 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1742 // Look for something (optionally) enclosed with quotes
1743 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1745 var m = re.exec( t );
1748 // Re-organize the match
1750 m = ["", m[1], m[3], m[2], m[4]];
1752 // Remove what we just matched
1753 t = t.replace( re, "" );
1759 // :not() is a special case that can be optomized by
1760 // keeping it out of the expression list
1761 if ( m[1] == ":" && m[2] == "not" )
1762 r = jQuery.filter(m[3],r,false).r;
1764 // Otherwise, find the expression to execute
1766 var f = jQuery.expr[m[1]];
1767 if ( f.constructor != String )
1768 f = jQuery.expr[m[1]][m[2]];
1770 // Build a custom macro to enclose it
1771 eval("f = function(a,i){" +
1772 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1773 "return " + f + "}");
1775 // Execute it against the current filter
1780 // Return an array of filtered elements (r)
1781 // and the modified expression string (t)
1782 return { r: r, t: t };
1786 * Remove the whitespace from the beginning and end of a string.
1790 * @param String str The string to trim.
1794 return t.replace(/^\s+|\s+$/g, "");
1798 * All ancestors of a given element.
1802 * @type Array<Element>
1803 * @param Element elem The element to find the ancestors of.
1804 * @cat DOM/Traversing
1806 parents: function( elem ){
1808 var cur = elem.parentNode;
1809 while ( cur && cur != document ) {
1810 matched.push( cur );
1811 cur = cur.parentNode;
1817 * All elements on a specified axis.
1822 * @param Element elem The element to find all the siblings of (including itself).
1823 * @cat DOM/Traversing
1825 sibling: function(elem, pos, not) {
1828 var siblings = elem.parentNode.childNodes;
1829 for ( var i = 0; i < siblings.length; i++ ) {
1830 if ( not === true && siblings[i] == elem ) continue;
1832 if ( siblings[i].nodeType == 1 )
1833 elems.push( siblings[i] );
1834 if ( siblings[i] == elem )
1835 elems.n = elems.length - 1;
1838 return jQuery.extend( elems, {
1839 last: elems.n == elems.length - 1,
1840 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1841 prev: elems[elems.n - 1],
1842 next: elems[elems.n + 1]
1847 * Merge two arrays together, removing all duplicates.
1851 * @param Array a The first array to merge.
1852 * @param Array b The second array to merge.
1855 merge: function(first, second) {
1858 // Move b over to the new array (this helps to avoid
1859 // StaticNodeList instances)
1860 for ( var k = 0; k < first.length; k++ )
1861 result[k] = first[k];
1863 // Now check for duplicates between a and b and only
1864 // add the unique items
1865 for ( var i = 0; i < second.length; i++ ) {
1866 var noCollision = true;
1868 // The collision-checking process
1869 for ( var j = 0; j < first.length; j++ )
1870 if ( second[i] == first[j] )
1871 noCollision = false;
1873 // If the item is unique, add it
1875 result.push( second[i] );
1882 * Remove items that aren't matched in an array. The function passed
1883 * in to this method will be passed two arguments: 'a' (which is the
1884 * array item) and 'i' (which is the index of the item in the array).
1888 * @param Array array The Array to find items in.
1889 * @param Function fn The function to process each item against.
1890 * @param Boolean inv Invert the selection - select the opposite of the function.
1893 grep: function(elems, fn, inv) {
1894 // If a string is passed in for the function, make a function
1895 // for it (a handy shortcut)
1896 if ( fn.constructor == String )
1897 fn = new Function("a","i","return " + fn);
1901 // Go through the array, only saving the items
1902 // that pass the validator function
1903 for ( var i = 0; i < elems.length; i++ )
1904 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1905 result.push( elems[i] );
1911 * Translate all items in array to another array of items. The translation function
1912 * that is provided to this method is passed one argument: 'a' (the item to be
1913 * translated). If an array is returned, that array is mapped out and merged into
1914 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1915 * from the array. Both of these changes imply that the size of the array may not
1916 * be the same size upon completion, as it was when it started.
1920 * @param Array array The Array to translate.
1921 * @param Function fn The function to process each item against.
1924 map: function(elems, fn) {
1925 // If a string is passed in for the function, make a function
1926 // for it (a handy shortcut)
1927 if ( fn.constructor == String )
1928 fn = new Function("a","return " + fn);
1932 // Go through the array, translating each of the items to their
1933 // new value (or values).
1934 for ( var i = 0; i < elems.length; i++ ) {
1935 var val = fn(elems[i],i);
1937 if ( val !== null && val != undefined ) {
1938 if ( val.constructor != Array ) val = [val];
1939 result = jQuery.merge( result, val );
1947 * A number of helper functions used for managing events.
1948 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1952 // Bind an event to an element
1953 // Original by Dean Edwards
1954 add: function(element, type, handler) {
1955 // For whatever reason, IE has trouble passing the window object
1956 // around, causing it to be cloned in the process
1957 if ( jQuery.browser.msie && element.setInterval != undefined )
1960 // Make sure that the function being executed has a unique ID
1961 if ( !handler.guid )
1962 handler.guid = this.guid++;
1964 // Init the element's event structure
1965 if (!element.events)
1966 element.events = {};
1968 // Get the current list of functions bound to this event
1969 var handlers = element.events[type];
1971 // If it hasn't been initialized yet
1973 // Init the event handler queue
1974 handlers = element.events[type] = {};
1976 // Remember an existing handler, if it's already there
1977 if (element["on" + type])
1978 handlers[0] = element["on" + type];
1981 // Add the function to the element's handler list
1982 handlers[handler.guid] = handler;
1984 // And bind the global event handler to the element
1985 element["on" + type] = this.handle;
1987 // Remember the function in a global list (for triggering)
1988 if (!this.global[type])
1989 this.global[type] = [];
1990 this.global[type].push( element );
1996 // Detach an event or set of events from an element
1997 remove: function(element, type, handler) {
1999 if (type && element.events[type])
2001 delete element.events[type][handler.guid];
2003 for ( var i in element.events[type] )
2004 delete element.events[type][i];
2006 for ( var j in element.events )
2007 this.remove( element, j );
2010 trigger: function(type,data,element) {
2011 // Touch up the incoming data
2014 // Handle a global trigger
2016 var g = this.global[type];
2018 for ( var i = 0; i < g.length; i++ )
2019 this.trigger( type, data, g[i] );
2021 // Handle triggering a single element
2022 } else if ( element["on" + type] ) {
2023 // Pass along a fake event
2024 data.unshift( this.fix({ type: type, target: element }) );
2026 // Trigger the event
2027 element["on" + type].apply( element, data );
2031 handle: function(event) {
2032 if ( typeof jQuery == "undefined" ) return;
2034 event = event || jQuery.event.fix( window.event );
2036 // If no correct event was found, fail
2037 if ( !event ) return;
2039 var returnValue = true;
2041 var c = this.events[event.type];
2043 for ( var j in c ) {
2044 if ( c[j].apply( this, [event] ) === false ) {
2045 event.preventDefault();
2046 event.stopPropagation();
2047 returnValue = false;
2054 fix: function(event) {
2056 event.preventDefault = function() {
2057 this.returnValue = false;
2060 event.stopPropagation = function() {
2061 this.cancelBubble = true;
2072 var b = navigator.userAgent.toLowerCase();
2074 // Figure out what browser is being used
2076 safari: /webkit/.test(b),
2077 opera: /opera/.test(b),
2078 msie: /msie/.test(b) && !/opera/.test(b),
2079 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2082 // Check to see if the W3C box model is being used
2083 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2089 * Append all of the matched elements to another, specified, set of elements.
2090 * This operation is, essentially, the reverse of doing a regular
2091 * $(A).append(B), in that instead of appending B to A, you're appending
2094 * @example $("p").appendTo("#foo");
2095 * @before <p>I would like to say: </p><div id="foo"></div>
2096 * @result <div id="foo"><p>I would like to say: </p></div>
2100 * @param String expr A jQuery expression of elements to match.
2101 * @cat DOM/Manipulation
2106 * Prepend all of the matched elements to another, specified, set of elements.
2107 * This operation is, essentially, the reverse of doing a regular
2108 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2111 * @example $("p").prependTo("#foo");
2112 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2113 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2117 * @param String expr A jQuery expression of elements to match.
2118 * @cat DOM/Manipulation
2120 prependTo: "prepend",
2123 * Insert all of the matched elements before another, specified, set of elements.
2124 * This operation is, essentially, the reverse of doing a regular
2125 * $(A).before(B), in that instead of inserting B before A, you're inserting
2128 * @example $("p").insertBefore("#foo");
2129 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2130 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2132 * @name insertBefore
2134 * @param String expr A jQuery expression of elements to match.
2135 * @cat DOM/Manipulation
2137 insertBefore: "before",
2140 * Insert all of the matched elements after another, specified, set of elements.
2141 * This operation is, essentially, the reverse of doing a regular
2142 * $(A).after(B), in that instead of inserting B after A, you're inserting
2145 * @example $("p").insertAfter("#foo");
2146 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2147 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2151 * @param String expr A jQuery expression of elements to match.
2152 * @cat DOM/Manipulation
2154 insertAfter: "after"
2158 * Get the current CSS width of the first matched element.
2160 * @example $("p").width();
2161 * @before <p>This is just a test.</p>
2170 * Set the CSS width of every matched element. Be sure to include
2171 * the "px" (or other unit of measurement) after the number that you
2172 * specify, otherwise you might get strange results.
2174 * @example $("p").width("20px");
2175 * @before <p>This is just a test.</p>
2176 * @result <p style="width:20px;">This is just a test.</p>
2180 * @param String val Set the CSS property to the specified value.
2185 * Get the current CSS height of the first matched element.
2187 * @example $("p").height();
2188 * @before <p>This is just a test.</p>
2197 * Set the CSS height of every matched element. Be sure to include
2198 * the "px" (or other unit of measurement) after the number that you
2199 * specify, otherwise you might get strange results.
2201 * @example $("p").height("20px");
2202 * @before <p>This is just a test.</p>
2203 * @result <p style="height:20px;">This is just a test.</p>
2207 * @param String val Set the CSS property to the specified value.
2212 * Get the current CSS top of the first matched element.
2214 * @example $("p").top();
2215 * @before <p>This is just a test.</p>
2224 * Set the CSS top of every matched element. Be sure to include
2225 * the "px" (or other unit of measurement) after the number that you
2226 * specify, otherwise you might get strange results.
2228 * @example $("p").top("20px");
2229 * @before <p>This is just a test.</p>
2230 * @result <p style="top:20px;">This is just a test.</p>
2234 * @param String val Set the CSS property to the specified value.
2239 * Get the current CSS left of the first matched element.
2241 * @example $("p").left();
2242 * @before <p>This is just a test.</p>
2251 * Set the CSS left of every matched element. Be sure to include
2252 * the "px" (or other unit of measurement) after the number that you
2253 * specify, otherwise you might get strange results.
2255 * @example $("p").left("20px");
2256 * @before <p>This is just a test.</p>
2257 * @result <p style="left:20px;">This is just a test.</p>
2261 * @param String val Set the CSS property to the specified value.
2266 * Get the current CSS position of the first matched element.
2268 * @example $("p").position();
2269 * @before <p>This is just a test.</p>
2278 * Set the CSS position of every matched element.
2280 * @example $("p").position("relative");
2281 * @before <p>This is just a test.</p>
2282 * @result <p style="position:relative;">This is just a test.</p>
2286 * @param String val Set the CSS property to the specified value.
2291 * Get the current CSS float of the first matched element.
2293 * @example $("p").float();
2294 * @before <p>This is just a test.</p>
2303 * Set the CSS float of every matched element.
2305 * @example $("p").float("left");
2306 * @before <p>This is just a test.</p>
2307 * @result <p style="float:left;">This is just a test.</p>
2311 * @param String val Set the CSS property to the specified value.
2316 * Get the current CSS overflow of the first matched element.
2318 * @example $("p").overflow();
2319 * @before <p>This is just a test.</p>
2328 * Set the CSS overflow of every matched element.
2330 * @example $("p").overflow("auto");
2331 * @before <p>This is just a test.</p>
2332 * @result <p style="overflow:auto;">This is just a test.</p>
2336 * @param String val Set the CSS property to the specified value.
2341 * Get the current CSS color of the first matched element.
2343 * @example $("p").color();
2344 * @before <p>This is just a test.</p>
2353 * Set the CSS color of every matched element.
2355 * @example $("p").color("blue");
2356 * @before <p>This is just a test.</p>
2357 * @result <p style="color:blue;">This is just a test.</p>
2361 * @param String val Set the CSS property to the specified value.
2366 * Get the current CSS background of the first matched element.
2368 * @example $("p").background();
2369 * @before <p style="background:blue;">This is just a test.</p>
2378 * Set the CSS background of every matched element.
2380 * @example $("p").background("blue");
2381 * @before <p>This is just a test.</p>
2382 * @result <p style="background:blue;">This is just a test.</p>
2386 * @param String val Set the CSS property to the specified value.
2390 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2393 * Reduce the set of matched elements to a single element.
2394 * The position of the element in the set of matched elements
2395 * starts at 0 and goes to length - 1.
2397 * @example $("p").eq(1)
2398 * @before <p>This is just a test.</p><p>So is this</p>
2399 * @result [ <p>So is this</p> ]
2403 * @param Number pos The index of the element that you wish to limit to.
2408 * Reduce the set of matched elements to all elements before a given position.
2409 * The position of the element in the set of matched elements
2410 * starts at 0 and goes to length - 1.
2412 * @example $("p").lt(1)
2413 * @before <p>This is just a test.</p><p>So is this</p>
2414 * @result [ <p>This is just a test.</p> ]
2418 * @param Number pos Reduce the set to all elements below this position.
2423 * Reduce the set of matched elements to all elements after a given position.
2424 * The position of the element in the set of matched elements
2425 * starts at 0 and goes to length - 1.
2427 * @example $("p").gt(0)
2428 * @before <p>This is just a test.</p><p>So is this</p>
2429 * @result [ <p>So is this</p> ]
2433 * @param Number pos Reduce the set to all elements after this position.
2438 * Filter the set of elements to those that contain the specified text.
2440 * @example $("p").contains("test")
2441 * @before <p>This is just a test.</p><p>So is this</p>
2442 * @result [ <p>This is just a test.</p> ]
2446 * @param String str The string that will be contained within the text of an element.
2447 * @cat DOM/Traversing
2450 filter: [ "eq", "lt", "gt", "contains" ],
2454 * Get the current value of the first matched element.
2456 * @example $("input").val();
2457 * @before <input type="text" value="some text"/>
2458 * @result "some text"
2460 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2461 * @test ok( !$("#text1").val() == "", "Check for value of input element" );
2465 * @cat DOM/Attributes
2469 * Set the value of every matched element.
2471 * @example $("input").value("test");
2472 * @before <input type="text" value="some text"/>
2473 * @result <input type="text" value="test"/>
2475 * @test document.getElementById('text1').value = "bla";
2476 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2477 * $("#text1").val('test');
2478 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2482 * @param String val Set the property to the specified value.
2483 * @cat DOM/Attributes
2488 * Get the html contents of the first matched element.
2490 * @example $("div").html();
2491 * @before <div><input/></div>
2496 * @cat DOM/Attributes
2500 * Set the html contents of every matched element.
2502 * @example $("div").html("<b>new stuff</b>");
2503 * @before <div><input/></div>
2504 * @result <div><b>new stuff</b></div>
2506 * @test var div = $("div");
2507 * div.html("<b>test</b>");
2509 * for ( var i = 0; i < div.size(); i++ ) {
2510 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2512 * ok( pass, "Set HTML" );
2516 * @param String val Set the html contents to the specified value.
2517 * @cat DOM/Attributes
2522 * Get the current id of the first matched element.
2524 * @example $("input").id();
2525 * @before <input type="text" id="test" value="some text"/>
2530 * @cat DOM/Attributes
2534 * Set the id of every matched element.
2536 * @example $("input").id("newid");
2537 * @before <input type="text" id="test" value="some text"/>
2538 * @result <input type="text" id="newid" value="some text"/>
2542 * @param String val Set the property to the specified value.
2543 * @cat DOM/Attributes
2548 * Get the current title of the first matched element.
2550 * @example $("img").title();
2551 * @before <img src="test.jpg" title="my image"/>
2552 * @result "my image"
2556 * @cat DOM/Attributes
2560 * Set the title of every matched element.
2562 * @example $("img").title("new title");
2563 * @before <img src="test.jpg" title="my image"/>
2564 * @result <img src="test.jpg" title="new image"/>
2568 * @param String val Set the property to the specified value.
2569 * @cat DOM/Attributes
2574 * Get the current name of the first matched element.
2576 * @example $("input").name();
2577 * @before <input type="text" name="username"/>
2578 * @result "username"
2582 * @cat DOM/Attributes
2586 * Set the name of every matched element.
2588 * @example $("input").name("user");
2589 * @before <input type="text" name="username"/>
2590 * @result <input type="text" name="user"/>
2594 * @param String val Set the property to the specified value.
2595 * @cat DOM/Attributes
2600 * Get the current href of the first matched element.
2602 * @example $("a").href();
2603 * @before <a href="test.html">my link</a>
2604 * @result "test.html"
2608 * @cat DOM/Attributes
2612 * Set the href of every matched element.
2614 * @example $("a").href("test2.html");
2615 * @before <a href="test.html">my link</a>
2616 * @result <a href="test2.html">my link</a>
2620 * @param String val Set the property to the specified value.
2621 * @cat DOM/Attributes
2626 * Get the current src of the first matched element.
2628 * @example $("img").src();
2629 * @before <img src="test.jpg" title="my image"/>
2630 * @result "test.jpg"
2634 * @cat DOM/Attributes
2638 * Set the src of every matched element.
2640 * @example $("img").src("test2.jpg");
2641 * @before <img src="test.jpg" title="my image"/>
2642 * @result <img src="test2.jpg" title="my image"/>
2646 * @param String val Set the property to the specified value.
2647 * @cat DOM/Attributes
2652 * Get the current rel of the first matched element.
2654 * @example $("a").rel();
2655 * @before <a href="test.html" rel="nofollow">my link</a>
2656 * @result "nofollow"
2660 * @cat DOM/Attributes
2664 * Set the rel of every matched element.
2666 * @example $("a").rel("nofollow");
2667 * @before <a href="test.html">my link</a>
2668 * @result <a href="test.html" rel="nofollow">my link</a>
2672 * @param String val Set the property to the specified value.
2673 * @cat DOM/Attributes
2680 * Get a set of elements containing the unique parents of the matched
2683 * @example $("p").parent()
2684 * @before <div><p>Hello</p><p>Hello</p></div>
2685 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2689 * @cat DOM/Traversing
2693 * Get a set of elements containing the unique parents of the matched
2694 * set of elements, and filtered by an expression.
2696 * @example $("p").parent(".selected")
2697 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2698 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2702 * @param String expr An expression to filter the parents with
2703 * @cat DOM/Traversing
2705 parent: "a.parentNode",
2708 * Get a set of elements containing the unique ancestors of the matched
2709 * set of elements (except for the root element).
2711 * @example $("span").ancestors()
2712 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2713 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2717 * @cat DOM/Traversing
2721 * Get a set of elements containing the unique ancestors of the matched
2722 * set of elements, and filtered by an expression.
2724 * @example $("span").ancestors("p")
2725 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2726 * @result [ <p><span>Hello</span></p> ]
2730 * @param String expr An expression to filter the ancestors with
2731 * @cat DOM/Traversing
2733 ancestors: jQuery.parents,
2736 * Get a set of elements containing the unique ancestors of the matched
2737 * set of elements (except for the root element).
2739 * @example $("span").ancestors()
2740 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2741 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2745 * @cat DOM/Traversing
2749 * Get a set of elements containing the unique ancestors of the matched
2750 * set of elements, and filtered by an expression.
2752 * @example $("span").ancestors("p")
2753 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2754 * @result [ <p><span>Hello</span></p> ]
2758 * @param String expr An expression to filter the ancestors with
2759 * @cat DOM/Traversing
2761 parents: jQuery.parents,
2764 * Get a set of elements containing the unique next siblings of each of the
2765 * matched set of elements.
2767 * It only returns the very next sibling, not all next siblings.
2769 * @example $("p").next()
2770 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2771 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2775 * @cat DOM/Traversing
2779 * Get a set of elements containing the unique next siblings of each of the
2780 * matched set of elements, and filtered by an expression.
2782 * It only returns the very next sibling, not all next siblings.
2784 * @example $("p").next(".selected")
2785 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2786 * @result [ <p class="selected">Hello Again</p> ]
2790 * @param String expr An expression to filter the next Elements with
2791 * @cat DOM/Traversing
2793 next: "jQuery.sibling(a).next",
2796 * Get a set of elements containing the unique previous siblings of each of the
2797 * matched set of elements.
2799 * It only returns the immediately previous sibling, not all previous siblings.
2801 * @example $("p").previous()
2802 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2803 * @result [ <div><span>Hello Again</span></div> ]
2807 * @cat DOM/Traversing
2811 * Get a set of elements containing the unique previous siblings of each of the
2812 * matched set of elements, and filtered by an expression.
2814 * It only returns the immediately previous sibling, not all previous siblings.
2816 * @example $("p").previous(".selected")
2817 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2818 * @result [ <div><span>Hello</span></div> ]
2822 * @param String expr An expression to filter the previous Elements with
2823 * @cat DOM/Traversing
2825 prev: "jQuery.sibling(a).prev",
2828 * Get a set of elements containing all of the unique siblings of each of the
2829 * matched set of elements.
2831 * @example $("div").siblings()
2832 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2833 * @result [ <p>Hello</p>, <p>And Again</p> ]
2837 * @cat DOM/Traversing
2841 * Get a set of elements containing all of the unique siblings of each of the
2842 * matched set of elements, and filtered by an expression.
2844 * @example $("div").siblings(".selected")
2845 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2846 * @result [ <p class="selected">Hello Again</p> ]
2850 * @param String expr An expression to filter the sibling Elements with
2851 * @cat DOM/Traversing
2853 siblings: jQuery.sibling,
2857 * Get a set of elements containing all of the unique children of each of the
2858 * matched set of elements.
2860 * @example $("div").children()
2861 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2862 * @result [ <span>Hello Again</span> ]
2866 * @cat DOM/Traversing
2870 * Get a set of elements containing all of the unique children of each of the
2871 * matched set of elements, and filtered by an expression.
2873 * @example $("div").children(".selected")
2874 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2875 * @result [ <p class="selected">Hello Again</p> ]
2879 * @param String expr An expression to filter the child Elements with
2880 * @cat DOM/Traversing
2882 children: "jQuery.sibling(a.firstChild)"
2888 * Remove an attribute from each of the matched elements.
2890 * @example $("input").removeAttr("disabled")
2891 * @before <input disabled="disabled"/>
2896 * @param String name The name of the attribute to remove.
2899 removeAttr: function( key ) {
2900 this.removeAttribute( key );
2904 * Displays each of the set of matched elements if they are hidden.
2906 * @example $("p").show()
2907 * @before <p style="display: none">Hello</p>
2908 * @result [ <p style="display: block">Hello</p> ]
2910 * @test var pass = true, div = $("div");
2911 * div.show().each(function(){
2912 * if ( this.style.display == "none" ) pass = false;
2914 * ok( pass, "Show" );
2921 this.style.display = this.oldblock ? this.oldblock : "";
2922 if ( jQuery.css(this,"display") == "none" )
2923 this.style.display = "block";
2927 * Hides each of the set of matched elements if they are shown.
2929 * @example $("p").hide()
2930 * @before <p>Hello</p>
2931 * @result [ <p style="display: none">Hello</p> ]
2933 * var pass = true, div = $("div");
2934 * div.hide().each(function(){
2935 * if ( this.style.display != "none" ) pass = false;
2937 * ok( pass, "Hide" );
2944 this.oldblock = this.oldblock || jQuery.css(this,"display");
2945 if ( this.oldblock == "none" )
2946 this.oldblock = "block";
2947 this.style.display = "none";
2951 * Toggles each of the set of matched elements. If they are shown,
2952 * toggle makes them hidden. If they are hidden, toggle
2955 * @example $("p").toggle()
2956 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2957 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2964 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2968 * Adds the specified class to each of the set of matched elements.
2970 * @example $("p").addClass("selected")
2971 * @before <p>Hello</p>
2972 * @result [ <p class="selected">Hello</p> ]
2974 * @test var div = $("div");
2975 * div.addClass("test");
2977 * for ( var i = 0; i < div.size(); i++ ) {
2978 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2980 * ok( pass, "Add Class" );
2984 * @param String class A CSS class to add to the elements
2987 addClass: function(c){
2988 jQuery.className.add(this,c);
2992 * Removes the specified class from the set of matched elements.
2994 * @example $("p").removeClass("selected")
2995 * @before <p class="selected">Hello</p>
2996 * @result [ <p>Hello</p> ]
2998 * @test var div = $("div").addClass("test");
2999 * div.removeClass("test");
3001 * for ( var i = 0; i < div.size(); i++ ) {
3002 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3004 * ok( pass, "Remove Class" );
3008 * @param String class A CSS class to remove from the elements
3011 removeClass: function(c){
3012 jQuery.className.remove(this,c);
3016 * Adds the specified class if it is present, removes it if it is
3019 * @example $("p").toggleClass("selected")
3020 * @before <p>Hello</p><p class="selected">Hello Again</p>
3021 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3025 * @param String class A CSS class with which to toggle the elements
3028 toggleClass: function( c ){
3029 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3033 * Removes all matched elements from the DOM. This does NOT remove them from the
3034 * jQuery object, allowing you to use the matched elements further.
3036 * @example $("p").remove();
3037 * @before <p>Hello</p> how are <p>you?</p>
3042 * @cat DOM/Manipulation
3046 * Removes only elements (out of the list of matched elements) that match
3047 * the specified jQuery expression. This does NOT remove them from the
3048 * jQuery object, allowing you to use the matched elements further.
3050 * @example $("p").remove(".hello");
3051 * @before <p class="hello">Hello</p> how are <p>you?</p>
3052 * @result how are <p>you?</p>
3056 * @param String expr A jQuery expression to filter elements by.
3057 * @cat DOM/Manipulation
3059 remove: function(a){
3060 if ( !a || jQuery.filter( a, [this] ).r )
3061 this.parentNode.removeChild( this );
3065 * Removes all child nodes from the set of matched elements.
3067 * @example $("p").empty()
3068 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3069 * @result [ <p></p> ]
3073 * @cat DOM/Manipulation
3076 while ( this.firstChild )
3077 this.removeChild( this.firstChild );
3081 * Binds a particular event (like click) to a each of a set of match elements.
3083 * @example $("p").bind( "click", function() { alert("Hello"); } )
3084 * @before <p>Hello</p>
3085 * @result [ <p>Hello</p> ]
3087 * Cancel a default action and prevent it from bubbling by returning false
3088 * from your function.
3090 * @example $("form").bind( "submit", function() { return false; } )
3092 * Cancel a default action by using the preventDefault method.
3094 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
3096 * Stop an event from bubbling by using the stopPropogation method.
3098 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
3102 * @param String type An event type
3103 * @param Function fn A function to bind to the event on each of the set of matched elements
3106 bind: function( type, fn ) {
3107 if ( fn.constructor == String )
3108 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3109 jQuery.event.add( this, type, fn );
3113 * The opposite of bind, removes a bound event from each of the matched
3114 * elements. You must pass the identical function that was used in the original
3117 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3118 * @before <p onclick="alert('Hello');">Hello</p>
3119 * @result [ <p>Hello</p> ]
3123 * @param String type An event type
3124 * @param Function fn A function to unbind from the event on each of the set of matched elements
3129 * Removes all bound events of a particular type from each of the matched
3132 * @example $("p").unbind( "click" )
3133 * @before <p onclick="alert('Hello');">Hello</p>
3134 * @result [ <p>Hello</p> ]
3138 * @param String type An event type
3143 * Removes all bound events from each of the matched elements.
3145 * @example $("p").unbind()
3146 * @before <p onclick="alert('Hello');">Hello</p>
3147 * @result [ <p>Hello</p> ]
3153 unbind: function( type, fn ) {
3154 jQuery.event.remove( this, type, fn );
3158 * Trigger a type of event on every matched element.
3160 * @example $("p").trigger("click")
3161 * @before <p click="alert('hello')">Hello</p>
3162 * @result alert('hello')
3166 * @param String type An event type to trigger.
3169 trigger: function( type, data ) {
3170 jQuery.event.trigger( type, data, this );