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.body).background( "black" );
131 * @desc Sets the background color of the page to black.
134 * @param Element elem A DOM element to be encapsulated by a jQuery object.
140 * Wrap jQuery functionality around a set of DOM Elements.
142 * @example $( myForm.elements ).hide()
143 * @desc Hides all the input elements within a form
146 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
152 * A shorthand for $(document).ready(), allowing you to bind a function
153 * to be executed when the DOM document has finished loading. This function
154 * behaves just like $(document).ready(), in that it should be used to wrap
155 * all of the other $() operations on your page. While this function is,
156 * technically, chainable - there really isn't much use for chaining against it.
158 * @example $(function(){
159 * // Document is ready
161 * @desc Executes the function when the DOM is ready to be used.
164 * @param Function fn The function to execute when the DOM is ready.
170 * A means of creating a cloned copy of a jQuery object. This function
171 * copies the set of matched elements from one jQuery object and creates
172 * another, new, jQuery object containing the same elements.
174 * @example var div = $("div");
175 * $( div ).find("p");
176 * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div' (as would normally be the case if a simple div.find("p") was done).
179 * @param jQuery obj The jQuery object to be cloned.
184 // Map the jQuery namespace to the '$' one
187 jQuery.fn = jQuery.prototype = {
189 * The current SVN version of jQuery.
200 * The number of elements currently matched.
202 * @example $("img").length;
203 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
206 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
215 * The number of elements currently matched.
217 * @example $("img").size();
218 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
221 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
232 * Access all matched elements. This serves as a backwards-compatible
233 * way of accessing all matched elements (other than the jQuery object
234 * itself, which is, in fact, an array of elements).
236 * @example $("img").get();
237 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
238 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
240 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
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"/> ]
255 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
259 * @param Number num Access the element in the Nth position.
264 * Set the jQuery object to an array of elements.
266 * @example $("img").get([ document.body ]);
267 * @result $("img").get() == [ document.body ]
272 * @param Elements elems An array of elements
275 get: function( num ) {
276 // Watch for when an array (of elements) is passed in
277 if ( num && num.constructor == Array ) {
279 // Use a tricky hack to make the jQuery object
280 // look and feel like an array
282 [].push.apply( this, num );
286 return num == undefined ?
288 // Return a 'clean' array
289 jQuery.merge( this, [] ) :
291 // Return just the object
296 * Execute a function within the context of every matched element.
297 * This means that every time the passed-in function is executed
298 * (which is once for every element matched) the 'this' keyword
299 * points to the specific element.
301 * Additionally, the function, when executed, is passed a single
302 * argument representing the position of the element in the matched
305 * @example $("img").each(function(){
306 * this.src = "test.jpg";
308 * @before <img/> <img/>
309 * @result <img src="test.jpg"/> <img src="test.jpg"/>
311 * @example $("img").each(function(i){
312 * alert( "Image #" + i + " is " + this );
314 * @before <img/> <img/>
315 * @result <img src="test.jpg"/> <img src="test.jpg"/>
317 * @test var div = $("div");
318 * div.each(function(){this.foo = 'zoo';});
320 * for ( var i = 0; i < div.size(); i++ ) {
321 * if ( div.get(i).foo != "zoo" ) pass = false;
323 * ok( pass, "Execute a function, Relative" );
327 * @param Function fn A function to execute
330 each: function( fn, args ) {
331 return jQuery.each( this, fn, args );
335 * Searches every matched element for the object and returns
336 * the index of the element, if found, starting with zero.
337 * Returns -1 if the object wasn't found.
339 * @example $("*").index(document.getElementById('foobar'))
340 * @before <div id="foobar"></div><b></b><span id="foo"></span>
343 * @example $("*").index(document.getElementById('foo'))
344 * @before <div id="foobar"></div><b></b><span id="foo"></span>
347 * @example $("*").index(document.getElementById('bar'))
348 * @before <div id="foobar"></div><b></b><span id="foo"></span>
351 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
352 * @test ok( $([window, document]).index(document) == 1, "Check for index of elements" );
353 * @test var inputElements = $('#radio1,#radio2,#check1,#check2');
354 * @test ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
355 * @test ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
356 * @test ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
357 * @test ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
358 * @test ok( inputElements.index(window) == -1, "Check for not found index" );
359 * @test ok( inputElements.index(document) == -1, "Check for not found index" );
363 * @param Object obj Object to search for
366 index: function( obj ) {
368 this.each(function(i){
369 if ( this == obj ) pos = i;
375 * Access a property on the first matched element.
376 * This method makes it easy to retrieve a property value
377 * from the first matched element.
379 * @example $("img").attr("src");
380 * @before <img src="test.jpg"/>
383 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
384 * @test ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
385 * @test ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
386 * @test ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
390 * @param String name The name of the property to access.
395 * Set a hash of key/value object properties to all matched elements.
396 * This serves as the best way to set a large number of properties
397 * on all matched elements.
399 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
401 * @result <img src="test.jpg" alt="Test Image"/>
403 * @test var pass = true;
404 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
405 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
407 * ok( pass, "Set Multiple Attributes" );
411 * @param Hash prop A set of key/value pairs to set as object properties.
416 * Set a single property to a value, on all matched elements.
418 * @example $("img").attr("src","test.jpg");
420 * @result <img src="test.jpg"/>
422 * @test var div = $("div");
423 * div.attr("foo", "bar");
425 * for ( var i = 0; i < div.size(); i++ ) {
426 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
428 * ok( pass, "Set Attribute" );
432 * @param String key The name of the property to set.
433 * @param Object value The value to set the property to.
436 attr: function( key, value, type ) {
437 // Check to see if we're setting style values
438 return key.constructor != String || value != undefined ?
439 this.each(function(){
440 // See if we're setting a hash of styles
441 if ( value == undefined )
442 // Set all the styles
443 for ( var prop in key )
445 type ? this.style : this,
449 // See if we're setting a single key/value style
452 type ? this.style : this,
457 // Look for the case where we're accessing a style value
458 jQuery[ type || "attr" ]( this[0], key );
462 * Access a style property on the first matched element.
463 * This method makes it easy to retrieve a style property value
464 * from the first matched element.
466 * @example $("p").css("color");
467 * @before <p style="color:red;">Test Paragraph.</p>
469 * @desc Retrieves the color style of the first paragraph
471 * @example $("p").css("fontWeight");
472 * @before <p style="font-weight: bold;">Test Paragraph.</p>
474 * @desc Retrieves the font-weight style of the first paragraph.
475 * Note that for all style properties with a dash (like 'font-weight'), you have to
476 * write it in camelCase. In other words: Every time you have a '-' in a
477 * property, remove it and replace the next character with an uppercase
478 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
479 * borderStyle, borderBottomWidth etc.
481 * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
485 * @param String name The name of the property to access.
490 * Set a hash of key/value style properties to all matched elements.
491 * This serves as the best way to set a large number of style properties
492 * on all matched elements.
494 * @example $("p").css({ color: "red", background: "blue" });
495 * @before <p>Test Paragraph.</p>
496 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
498 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
499 * @test $('#foo').css({display: 'none'});
500 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
501 * @test $('#foo').css({display: 'block'});
502 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
506 * @param Hash prop A set of key/value pairs to set as style properties.
511 * Set a single style property to a value, on all matched elements.
513 * @example $("p").css("color","red");
514 * @before <p>Test Paragraph.</p>
515 * @result <p style="color:red;">Test Paragraph.</p>
516 * @desc Changes the color of all paragraphs to red
519 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
520 * @test $('#foo').css('display', 'none');
521 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
522 * @test $('#foo').css('display', 'block');
523 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
527 * @param String key The name of the property to set.
528 * @param Object value The value to set the property to.
531 css: function( key, value ) {
532 return this.attr( key, value, "curCSS" );
536 * Retrieve the text contents of all matched elements. The result is
537 * a string that contains the combined text contents of all matched
538 * elements. This method works on both HTML and XML documents.
540 * @example $("p").text();
541 * @before <p>Test Paragraph.</p>
542 * @result Test Paragraph.
544 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
545 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
554 for ( var j = 0; j < e.length; j++ ) {
555 var r = e[j].childNodes;
556 for ( var i = 0; i < r.length; i++ )
557 if ( r[i].nodeType != 8 )
558 t += r[i].nodeType != 1 ?
559 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
565 * Wrap all matched elements with a structure of other elements.
566 * This wrapping process is most useful for injecting additional
567 * stucture into a document, without ruining the original semantic
568 * qualities of a document.
570 * This works by going through the first element
571 * provided (which is generated, on the fly, from the provided HTML)
572 * and finds the deepest ancestor element within its
573 * structure - it is that element that will en-wrap everything else.
575 * @example $("p").wrap("<div class='wrap'></div>");
576 * @before <p>Test Paragraph.</p>
577 * @result <div class='wrap'><p>Test Paragraph.</p></div>
579 * @test var defaultText = 'Try them out:'
580 * @test var result = $('#first').wrap('<div class="red">xx<span></span>yy</div>').text()
581 * ok( 'xx' + defaultText + 'yy' == result, 'Check for wrapping' );
582 * @test ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
586 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
587 * @cat DOM/Manipulation
591 * Wrap all matched elements with a structure of other elements.
592 * This wrapping process is most useful for injecting additional
593 * stucture into a document, without ruining the original semantic
594 * qualities of a document.
596 * This works by going through the first element
597 * provided and finding the deepest ancestor element within its
598 * structure - it is that element that will en-wrap everything else.
600 * @example $("p").wrap("<div class='wrap'></div>");
601 * @before <p>Test Paragraph.</p>
602 * @result <div class='wrap'><p>Test Paragraph.</p></div>
606 * @param Element elem A DOM element that will be wrapped.
607 * @cat DOM/Manipulation
610 // The elements to wrap the target around
611 var a = jQuery.clean(arguments);
613 // Wrap each of the matched elements individually
614 return this.each(function(){
615 // Clone the structure that we're using to wrap
616 var b = a[0].cloneNode(true);
618 // Insert it before the element to be wrapped
619 this.parentNode.insertBefore( b, this );
621 // Find he deepest point in the wrap structure
622 while ( b.firstChild )
625 // Move the matched element to within the wrap structure
626 b.appendChild( this );
631 * Append any number of elements to the inside of every matched elements,
632 * generated from the provided HTML.
633 * This operation is similar to doing an appendChild to all the
634 * specified elements, adding them into the document.
636 * @example $("p").append("<b>Hello</b>");
637 * @before <p>I would like to say: </p>
638 * @result <p>I would like to say: <b>Hello</b></p>
640 * @test var defaultText = 'Try them out:'
641 * var result = $('#first').append('<b>buga</b>');
642 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
646 * @param String html A string of HTML, that will be created on the fly and appended to the target.
647 * @cat DOM/Manipulation
651 * Append an element 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( $("#foo")[0] );
656 * @before <p>I would like to say: </p><b id="foo">Hello</b>
657 * @result <p>I would like to say: <b id="foo">Hello</b></p>
659 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
660 * $('#sap').append(document.getElementById('first'));
661 * ok( expected == $('#sap').text(), "Check for appending of element" );
665 * @param Element elem A DOM element that will be appended.
666 * @cat DOM/Manipulation
670 * Append any number of elements to the inside of all matched elements.
671 * This operation is similar to doing an appendChild to all the
672 * specified elements, adding them into the document.
674 * @example $("p").append( $("b") );
675 * @before <p>I would like to say: </p><b>Hello</b>
676 * @result <p>I would like to say: <b>Hello</b></p>
678 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
679 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
680 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
684 * @param Array<Element> elems An array of elements, all of which will be appended.
685 * @cat DOM/Manipulation
688 return this.domManip(arguments, true, 1, function(a){
689 this.appendChild( a );
694 * Prepend any number of elements to the inside of every matched elements,
695 * generated from the provided HTML.
696 * This operation is the best way to insert dynamically created elements
697 * inside, at the beginning, of all the matched element.
699 * @example $("p").prepend("<b>Hello</b>");
700 * @before <p>I would like to say: </p>
701 * @result <p><b>Hello</b>I would like to say: </p>
703 * @test var defaultText = 'Try them out:'
704 * var result = $('#first').prepend('<b>buga</b>');
705 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
709 * @param String html A string of HTML, that will be created on the fly and appended to the target.
710 * @cat DOM/Manipulation
714 * Prepend an element to the inside of all matched elements.
715 * This operation is the best way to insert an element inside, at the
716 * beginning, of all the matched element.
718 * @example $("p").prepend( $("#foo")[0] );
719 * @before <p>I would like to say: </p><b id="foo">Hello</b>
720 * @result <p><b id="foo">Hello</b>I would like to say: </p>
722 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
723 * $('#sap').prepend(document.getElementById('first'));
724 * ok( expected == $('#sap').text(), "Check for prepending of element" );
728 * @param Element elem A DOM element that will be appended.
729 * @cat DOM/Manipulation
733 * Prepend any number of elements to the inside of all matched elements.
734 * This operation is the best way to insert a set of elements inside, at the
735 * beginning, of all the matched element.
737 * @example $("p").prepend( $("b") );
738 * @before <p>I would like to say: </p><b>Hello</b>
739 * @result <p><b>Hello</b>I would like to say: </p>
741 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
742 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
743 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
747 * @param Array<Element> elems An array of elements, all of which will be appended.
748 * @cat DOM/Manipulation
750 prepend: function() {
751 return this.domManip(arguments, true, -1, function(a){
752 this.insertBefore( a, this.firstChild );
757 * Insert any number of dynamically generated elements before each of the
760 * @example $("p").before("<b>Hello</b>");
761 * @before <p>I would like to say: </p>
762 * @result <b>Hello</b><p>I would like to say: </p>
764 * @test var expected = 'This is a normal link: bugaYahoo';
765 * $('#yahoo').before('<b>buga</b>');
766 * ok( expected == $('#en').text(), 'Insert String before' );
770 * @param String html A string of HTML, that will be created on the fly and appended to the target.
771 * @cat DOM/Manipulation
775 * Insert an element before each of the matched elements.
777 * @example $("p").before( $("#foo")[0] );
778 * @before <p>I would like to say: </p><b id="foo">Hello</b>
779 * @result <b id="foo">Hello</b><p>I would like to say: </p>
781 * @test var expected = "This is a normal link: Try them out:Yahoo";
782 * $('#yahoo').before(document.getElementById('first'));
783 * ok( expected == $('#en').text(), "Insert element before" );
787 * @param Element elem A DOM element that will be appended.
788 * @cat DOM/Manipulation
792 * Insert any number of elements before each of the matched elements.
794 * @example $("p").before( $("b") );
795 * @before <p>I would like to say: </p><b>Hello</b>
796 * @result <b>Hello</b><p>I would like to say: </p>
798 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
799 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
800 * ok( expected == $('#en').text(), "Insert array of elements before" );
804 * @param Array<Element> elems An array of elements, all of which will be appended.
805 * @cat DOM/Manipulation
808 return this.domManip(arguments, false, 1, function(a){
809 this.parentNode.insertBefore( a, this );
814 * Insert any number of dynamically generated elements after each of the
817 * @example $("p").after("<b>Hello</b>");
818 * @before <p>I would like to say: </p>
819 * @result <p>I would like to say: </p><b>Hello</b>
821 * @test var expected = 'This is a normal link: Yahoobuga';
822 * $('#yahoo').after('<b>buga</b>');
823 * ok( expected == $('#en').text(), 'Insert String after' );
827 * @param String html A string of HTML, that will be created on the fly and appended to the target.
828 * @cat DOM/Manipulation
832 * Insert an element after each of the matched elements.
834 * @example $("p").after( $("#foo")[0] );
835 * @before <b id="foo">Hello</b><p>I would like to say: </p>
836 * @result <p>I would like to say: </p><b id="foo">Hello</b>
838 * @test var expected = "This is a normal link: YahooTry them out:";
839 * $('#yahoo').after(document.getElementById('first'));
840 * ok( expected == $('#en').text(), "Insert element after" );
844 * @param Element elem A DOM element that will be appended.
845 * @cat DOM/Manipulation
849 * Insert any number of elements after each of the matched elements.
851 * @example $("p").after( $("b") );
852 * @before <b>Hello</b><p>I would like to say: </p>
853 * @result <p>I would like to say: </p><b>Hello</b>
855 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
856 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
857 * ok( expected == $('#en').text(), "Insert array of elements after" );
861 * @param Array<Element> elems An array of elements, all of which will be appended.
862 * @cat DOM/Manipulation
865 return this.domManip(arguments, false, -1, function(a){
866 this.parentNode.insertBefore( a, this.nextSibling );
871 * End the most recent 'destructive' operation, reverting the list of matched elements
872 * back to its previous state. After an end operation, the list of matched elements will
873 * revert to the last state of matched elements.
875 * @example $("p").find("span").end();
876 * @before <p><span>Hello</span>, how are you?</p>
877 * @result $("p").find("span").end() == [ <p>...</p> ]
879 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
883 * @cat DOM/Traversing
886 return this.get( this.stack.pop() );
890 * Searches for all elements that match the specified expression.
891 * This method is the optimal way of finding additional descendant
892 * elements with which to process.
894 * All searching is done using a jQuery expression. The expression can be
895 * written using CSS 1-3 Selector syntax, or basic XPath.
897 * @example $("p").find("span");
898 * @before <p><span>Hello</span>, how are you?</p>
899 * @result $("p").find("span") == [ <span>Hello</span> ]
901 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
905 * @param String expr An expression to search with.
906 * @cat DOM/Traversing
909 return this.pushStack( jQuery.map( this, function(a){
910 return jQuery.find(t,a);
915 * Create cloned copies of all matched DOM Elements. This does
916 * not create a cloned copy of this particular jQuery object,
917 * instead it creates duplicate copies of all DOM Elements.
918 * This is useful for moving copies of the elements to another
919 * location in the DOM.
921 * @example $("b").clone().prependTo("p");
922 * @before <b>Hello</b><p>, how are you?</p>
923 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
925 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
926 * var clone = $('#yahoo').clone();
927 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
928 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
932 * @cat DOM/Manipulation
934 clone: function(deep) {
935 return this.pushStack( jQuery.map( this, function(a){
936 return a.cloneNode( deep != undefined ? deep : true );
941 * Removes all elements from the set of matched elements that do not
942 * match the specified expression. This method is used to narrow down
943 * the results of a search.
945 * All searching is done using a jQuery expression. The expression
946 * can be written using CSS 1-3 Selector syntax, or basic XPath.
948 * @example $("p").filter(".selected")
949 * @before <p class="selected">Hello</p><p>How are you?</p>
950 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
954 * @param String expr An expression to search with.
955 * @cat DOM/Traversing
959 * Removes all elements from the set of matched elements that do not
960 * match at least one of the expressions passed to the function. This
961 * method is used when you want to filter the set of matched elements
962 * through more than one expression.
964 * Elements will be retained in the jQuery object if they match at
965 * least one of the expressions passed.
967 * @example $("p").filter([".selected", ":first"])
968 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
969 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
973 * @param Array<String> exprs A set of expressions to evaluate against
974 * @cat DOM/Traversing
976 filter: function(t) {
977 return this.pushStack(
978 t.constructor == Array &&
979 jQuery.map(this,function(a){
980 for ( var i = 0; i < t.length; i++ )
981 if ( jQuery.filter(t[i],[a]).r.length )
985 t.constructor == Boolean &&
986 ( t ? this.get() : [] ) ||
988 t.constructor == Function &&
989 jQuery.grep( this, t ) ||
991 jQuery.filter(t,this).r, arguments );
995 * Removes the specified Element from the set of matched elements. This
996 * method is used to remove a single Element from a jQuery object.
998 * @example $("p").not( document.getElementById("selected") )
999 * @before <p>Hello</p><p id="selected">Hello Again</p>
1000 * @result [ <p>Hello</p> ]
1004 * @param Element el An element to remove from the set
1005 * @cat DOM/Traversing
1009 * Removes elements matching the specified expression from the set
1010 * of matched elements. This method is used to remove one or more
1011 * elements from a jQuery object.
1013 * @example $("p").not("#selected")
1014 * @before <p>Hello</p><p id="selected">Hello Again</p>
1015 * @result [ <p>Hello</p> ]
1016 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
1020 * @param String expr An expression with which to remove matching elements
1021 * @cat DOM/Traversing
1024 return this.pushStack( t.constructor == String ?
1025 jQuery.filter(t,this,false).r :
1026 jQuery.grep(this,function(a){ return a != t; }), arguments );
1030 * Adds the elements matched by the expression to the jQuery object. This
1031 * can be used to concatenate the result sets of two expressions.
1033 * @example $("p").add("span")
1034 * @before <p>Hello</p><p><span>Hello Again</span></p>
1035 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1039 * @param String expr An expression whose matched elements are added
1040 * @cat DOM/Traversing
1044 * Adds each of the Elements in the array to the set of matched elements.
1045 * This is used to add a set of Elements to a jQuery object.
1047 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1048 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1049 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1053 * @param Array<Element> els An array of Elements to add
1054 * @cat DOM/Traversing
1058 * Adds a single Element to the set of matched elements. This is used to
1059 * add a single Element to a jQuery object.
1061 * @example $("p").add( document.getElementById("a") )
1062 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1063 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1067 * @param Element el An Element to add
1068 * @cat DOM/Traversing
1071 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1072 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1076 * Checks the current selection against an expression and returns true,
1077 * if the selection fits the given expression. Does return false, if the
1078 * selection does not fit or the expression is not valid.
1080 * @example $("input[@type='checkbox']").parent().is("form")
1081 * @before <form><input type="checkbox" /></form>
1083 * @desc Returns true, because the parent of the input is a form element
1085 * @example $("input[@type='checkbox']").parent().is("form")
1086 * @before <form><p><input type="checkbox" /></p></form>
1088 * @desc Returns false, because the parent of the input is a p element
1090 * @example $("form").is(null)
1091 * @before <form></form>
1093 * @desc An invalid expression always returns false.
1095 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1096 * @test ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1097 * @test ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1098 * @test ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1099 * @test ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1100 * @test ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1101 * @test ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1102 * @test ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1103 * @test ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1104 * @test ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1105 * @test ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1106 * @test ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1107 * @test ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1108 * @test ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1109 * @test ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1110 * @test ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1111 * @test ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1112 * @test ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1113 * @test ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1114 * @test ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1115 * @test ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1116 * @test ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1120 * @param String expr The expression with which to filter
1121 * @cat DOM/Traversing
1123 is: function(expr) {
1124 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1133 * @param Boolean table
1135 * @param Function fn The function doing the DOM manipulation.
1139 domManip: function(args, table, dir, fn){
1140 var clone = this.size() > 1;
1141 var a = jQuery.clean(args);
1143 return this.each(function(){
1146 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
1147 var tbody = this.getElementsByTagName("tbody");
1149 if ( !tbody.length ) {
1150 obj = document.createElement("tbody");
1151 this.appendChild( obj );
1156 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1157 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1158 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1173 pushStack: function(a,args) {
1174 var fn = args && args[args.length-1];
1176 if ( !fn || fn.constructor != Function ) {
1177 if ( !this.stack ) this.stack = [];
1178 this.stack.push( this.get() );
1181 var old = this.get();
1183 if ( fn.constructor == Function )
1203 * Extend one object with another, returning the original,
1204 * modified, object. This is a great utility for simple inheritance.
1206 * @example var settings = { validate: false, limit: 5, name: "foo" };
1207 * var options = { validate: true, name: "bar" };
1208 * jQuery.extend(settings, options);
1209 * @result settings == { validate: true, limit: 5, name: "bar" }
1211 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1212 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1213 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1214 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1215 * jQuery.extend(settings, options);
1216 * isSet( settings, merged, "Check if extended: settings must be extended" );
1217 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1220 * @param Object obj The object to extend
1221 * @param Object prop The object that will be merged into the first.
1225 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1226 if ( !prop ) { prop = obj; obj = this; }
1227 for ( var i in prop ) obj[i] = prop[i];
1239 jQuery.initDone = true;
1241 jQuery.each( jQuery.macros.axis, function(i,n){
1242 jQuery.fn[ i ] = function(a) {
1243 var ret = jQuery.map(this,n);
1244 if ( a && a.constructor == String )
1245 ret = jQuery.filter(a,ret).r;
1246 return this.pushStack( ret, arguments );
1250 jQuery.each( jQuery.macros.to, function(i,n){
1251 jQuery.fn[ i ] = function(){
1253 return this.each(function(){
1254 for ( var j = 0; j < a.length; j++ )
1255 jQuery(a[j])[n]( this );
1260 jQuery.each( jQuery.macros.each, function(i,n){
1261 jQuery.fn[ i ] = function() {
1262 return this.each( n, arguments );
1266 jQuery.each( jQuery.macros.filter, function(i,n){
1267 jQuery.fn[ n ] = function(num,fn) {
1268 return this.filter( ":" + n + "(" + num + ")", fn );
1272 jQuery.each( jQuery.macros.attr, function(i,n){
1274 jQuery.fn[ i ] = function(h) {
1275 return h == undefined ?
1276 this.length ? this[0][n] : null :
1281 jQuery.each( jQuery.macros.css, function(i,n){
1282 jQuery.fn[ n ] = function(h) {
1283 return h == undefined ?
1284 ( this.length ? jQuery.css( this[0], n ) : null ) :
1292 * A generic iterator function, which can be used to seemlessly
1293 * iterate over both objects and arrays. This function is not the same
1294 * as $().each() - which is used to iterate, exclusively, over a jQuery
1295 * object. This function can be used to iterate over anything.
1297 * @example $.each( [0,1,2], function(i){
1298 * alert( "Item #" + i + ": " + this );
1300 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1302 * @example $.each( { name: "John", lang: "JS" }, function(i){
1303 * alert( "Name: " + i + ", Value: " + this );
1305 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1308 * @param Object obj The object, or array, to iterate over.
1309 * @param Function fn The function that will be executed on every object.
1313 each: function( obj, fn, args ) {
1314 if ( obj.length == undefined )
1315 for ( var i in obj )
1316 fn.apply( obj[i], args || [i, obj[i]] );
1318 for ( var i = 0; i < obj.length; i++ )
1319 fn.apply( obj[i], args || [i, obj[i]] );
1325 if (jQuery.className.has(o,c)) return;
1326 o.className += ( o.className ? " " : "" ) + c;
1328 remove: function(o,c){
1329 o.className = !c ? "" :
1330 o.className.replace(
1331 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
1333 has: function(e,a) {
1334 if ( e.className != undefined )
1336 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1341 * Swap in/out style options.
1344 swap: function(e,o,f) {
1345 for ( var i in o ) {
1346 e.style["old"+i] = e.style[i];
1351 e.style[i] = e.style["old"+i];
1354 css: function(e,p) {
1355 if ( p == "height" || p == "width" ) {
1356 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1358 for ( var i in d ) {
1359 old["padding" + d[i]] = 0;
1360 old["border" + d[i] + "Width"] = 0;
1363 jQuery.swap( e, old, function() {
1364 if (jQuery.css(e,"display") != "none") {
1365 oHeight = e.offsetHeight;
1366 oWidth = e.offsetWidth;
1368 e = jQuery(e.cloneNode(true)).css({
1369 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1370 }).appendTo(e.parentNode)[0];
1372 var parPos = jQuery.css(e.parentNode,"position");
1373 if ( parPos == "" || parPos == "static" )
1374 e.parentNode.style.position = "relative";
1376 oHeight = e.clientHeight;
1377 oWidth = e.clientWidth;
1379 if ( parPos == "" || parPos == "static" )
1380 e.parentNode.style.position = "static";
1382 e.parentNode.removeChild(e);
1386 return p == "height" ? oHeight : oWidth;
1387 } else if ( p == "opacity" && jQuery.browser.msie )
1388 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1390 return jQuery.curCSS( e, p );
1393 curCSS: function(elem, prop, force) {
1396 if (!force && elem.style[prop]) {
1398 ret = elem.style[prop];
1400 } else if (elem.currentStyle) {
1402 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1403 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1405 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1407 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1408 var cur = document.defaultView.getComputedStyle(elem, null);
1411 ret = cur.getPropertyValue(prop);
1412 else if ( prop == 'display' )
1415 jQuery.swap(elem, { display: 'block' }, function() {
1416 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1424 clean: function(a) {
1426 for ( var i = 0; i < a.length; i++ ) {
1427 if ( a[i].constructor == String ) {
1431 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1433 a[i] = "<table>" + a[i] + "</table>";
1434 } else if ( !a[i].indexOf("<tr") ) {
1436 a[i] = "<table>" + a[i] + "</table>";
1437 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1439 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1442 var div = document.createElement("div");
1443 div.innerHTML = a[i];
1446 div = div.firstChild;
1447 if ( table != "thead" ) div = div.firstChild;
1448 if ( table == "td" ) div = div.firstChild;
1451 for ( var j = 0; j < div.childNodes.length; j++ )
1452 r.push( div.childNodes[j] );
1453 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1454 for ( var k = 0; k < a[i].length; k++ )
1456 else if ( a[i] !== null )
1457 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1463 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1464 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1472 last: "i==r.length-1",
1477 "nth-child": "jQuery.sibling(a,m[3]).cur",
1478 "first-child": "jQuery.sibling(a,0).cur",
1479 "last-child": "jQuery.sibling(a,0).last",
1480 "only-child": "jQuery.sibling(a).length==1",
1483 parent: "a.childNodes.length",
1484 empty: "!a.childNodes.length",
1487 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1490 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1491 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1494 enabled: "!a.disabled",
1495 disabled: "a.disabled",
1496 checked: "a.checked",
1497 selected: "a.selected"
1499 ".": "jQuery.className.has(a,m[2])",
1503 "^=": "!z.indexOf(m[4])",
1504 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1505 "*=": "z.indexOf(m[4])>=0",
1508 "[": "jQuery.find(m[2],a).length"
1512 "\\.\\.|/\\.\\.", "a.parentNode",
1513 ">|/", "jQuery.sibling(a.firstChild)",
1514 "\\+", "jQuery.sibling(a).next",
1517 var s = jQuery.sibling(a);
1519 for ( var i = s.n; i < s.length; i++ )
1527 * @test t( "Element Selector", "div", ["main","foo"] );
1528 * @test t( "Element Selector", "body", ["body"] );
1529 * @test t( "Element Selector", "html", ["html"] );
1530 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1531 * @test t( "Parent Element", "div div", ["foo"] );
1533 * @test t( "ID Selector", "#body", ["body"] );
1534 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1535 * @test t( "ID Selector w/ Element", "ul#first", [] );
1537 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1538 * @test t( "Class Selector", ".blog.link", ["simon"] );
1539 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1540 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1542 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1543 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1544 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1545 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1547 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1548 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1549 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1550 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1551 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1552 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1553 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1554 * @test t( "Adjacent", "a + a", ["groups"] );
1555 * @test t( "Adjacent", "a +a", ["groups"] );
1556 * @test t( "Adjacent", "a+ a", ["groups"] );
1557 * @test t( "Adjacent", "a+a", ["groups"] );
1558 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1559 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1560 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1561 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1562 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1563 * @test t( "Attribute Exists", "[@title]", ["google"] );
1564 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1565 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1566 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1567 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1568 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1569 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1571 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1572 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1573 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1574 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1575 * @test t( "Last Child", "p:last-child", ["sap"] );
1576 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1577 * @test t( "Empty", "ul:empty", ["firstUL"] );
1578 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1579 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1580 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1581 * @test t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1582 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1583 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1584 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1585 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1587 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1588 * @test t( "All Div Elements", "//div", ["main","foo"] );
1589 * @test t( "Absolute Path", "/html/body", ["body"] );
1590 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1591 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1592 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1593 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1594 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1595 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1596 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1597 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1598 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1599 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1600 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1602 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1603 * @test t( "First Element", "p:first", ["firstp"] );
1604 * @test t( "Last Element", "p:last", ["first"] );
1605 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1606 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1607 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1608 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1609 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1610 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1611 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1612 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1615 * @type Array<Element>
1619 find: function( t, context ) {
1620 // Make sure that the context is a DOM Element
1621 if ( context && context.nodeType == undefined )
1624 // Set the correct context (if none is provided)
1625 context = context || jQuery.context || document;
1627 if ( t.constructor != String ) return [t];
1629 if ( !t.indexOf("//") ) {
1630 context = context.documentElement;
1631 t = t.substr(2,t.length);
1632 } else if ( !t.indexOf("/") ) {
1633 context = context.documentElement;
1634 t = t.substr(1,t.length);
1635 // FIX Assume the root element is right :(
1636 if ( t.indexOf("/") >= 1 )
1637 t = t.substr(t.indexOf("/"),t.length);
1640 var ret = [context];
1644 while ( t.length > 0 && last != t ) {
1648 t = jQuery.trim(t).replace( /^\/\//i, "" );
1650 var foundToken = false;
1652 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1653 if ( foundToken ) continue;
1655 var re = new RegExp("^(" + jQuery.token[i] + ")");
1659 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1660 t = jQuery.trim( t.replace( re, "" ) );
1665 if ( !foundToken ) {
1666 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1667 if ( ret[0] == context ) ret.shift();
1668 done = jQuery.merge( done, ret );
1669 r = ret = [context];
1670 t = " " + t.substr(1,t.length);
1672 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1673 var m = re2.exec(t);
1675 if ( m[1] == "#" ) {
1676 // Ummm, should make this work in all XML docs
1677 var oid = document.getElementById(m[2]);
1678 r = ret = oid ? [oid] : [];
1679 t = t.replace( re2, "" );
1681 if ( !m[2] || m[1] == "." ) m[2] = "*";
1683 for ( var i = 0; i < ret.length; i++ )
1684 r = jQuery.merge( r,
1686 jQuery.getAll(ret[i]) :
1687 ret[i].getElementsByTagName(m[2])
1695 var val = jQuery.filter(t,r);
1697 t = jQuery.trim(val.t);
1701 if ( ret && ret[0] == context ) ret.shift();
1702 done = jQuery.merge( done, ret );
1707 getAll: function(o,r) {
1709 var s = o.childNodes;
1710 for ( var i = 0; i < s.length; i++ )
1711 if ( s[i].nodeType == 1 ) {
1713 jQuery.getAll( s[i], r );
1718 attr: function(elem, name, value){
1721 "class": "className",
1722 "float": "cssFloat",
1723 innerHTML: "innerHTML",
1724 className: "className",
1726 disabled: "disabled",
1731 if ( value != undefined ) elem[fix[name]] = value;
1732 return elem[fix[name]];
1733 } else if ( elem.getAttribute ) {
1734 if ( value != undefined ) elem.setAttribute( name, value );
1735 return elem.getAttribute( name, 2 );
1737 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1738 if ( value != undefined ) elem[name] = value;
1743 // The regular expressions that power the parsing engine
1745 // Match: [@value='test'], [@foo]
1746 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1748 // Match: [div], [div p]
1751 // Match: :contains('foo')
1752 [ "(:)S\\(Q\\)", 0 ],
1754 // Match: :even, :last-chlid
1758 filter: function(t,r,not) {
1759 // Figure out if we're doing regular, or inverse, filtering
1760 var g = not !== false ? jQuery.grep :
1761 function(a,f) {return jQuery.grep(a,f,true);};
1763 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1765 var p = jQuery.parse;
1767 for ( var i = 0; i < p.length; i++ ) {
1768 var re = new RegExp( "^" + p[i][0]
1770 // Look for a string-like sequence
1771 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1773 // Look for something (optionally) enclosed with quotes
1774 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1776 var m = re.exec( t );
1779 // Re-organize the match
1781 m = ["", m[1], m[3], m[2], m[4]];
1783 // Remove what we just matched
1784 t = t.replace( re, "" );
1790 // :not() is a special case that can be optomized by
1791 // keeping it out of the expression list
1792 if ( m[1] == ":" && m[2] == "not" )
1793 r = jQuery.filter(m[3],r,false).r;
1795 // Otherwise, find the expression to execute
1797 var f = jQuery.expr[m[1]];
1798 if ( f.constructor != String )
1799 f = jQuery.expr[m[1]][m[2]];
1801 // Build a custom macro to enclose it
1802 eval("f = function(a,i){" +
1803 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1804 "return " + f + "}");
1806 // Execute it against the current filter
1811 // Return an array of filtered elements (r)
1812 // and the modified expression string (t)
1813 return { r: r, t: t };
1817 * Remove the whitespace from the beginning and end of a string.
1819 * @example $.trim(" hello, how are you? ");
1820 * @result "hello, how are you?"
1824 * @param String str The string to trim.
1828 return t.replace(/^\s+|\s+$/g, "");
1832 * All ancestors of a given element.
1836 * @type Array<Element>
1837 * @param Element elem The element to find the ancestors of.
1838 * @cat DOM/Traversing
1840 parents: function( elem ){
1842 var cur = elem.parentNode;
1843 while ( cur && cur != document ) {
1844 matched.push( cur );
1845 cur = cur.parentNode;
1851 * All elements on a specified axis.
1856 * @param Element elem The element to find all the siblings of (including itself).
1857 * @cat DOM/Traversing
1859 sibling: function(elem, pos, not) {
1862 var siblings = elem.parentNode.childNodes;
1863 for ( var i = 0; i < siblings.length; i++ ) {
1864 if ( not === true && siblings[i] == elem ) continue;
1866 if ( siblings[i].nodeType == 1 )
1867 elems.push( siblings[i] );
1868 if ( siblings[i] == elem )
1869 elems.n = elems.length - 1;
1872 return jQuery.extend( elems, {
1873 last: elems.n == elems.length - 1,
1874 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1875 prev: elems[elems.n - 1],
1876 next: elems[elems.n + 1]
1881 * Merge two arrays together, removing all duplicates. The final order
1882 * or the new array is: All the results from the first array, followed
1883 * by the unique results from the second array.
1885 * @example $.merge( [0,1,2], [2,3,4] )
1886 * @result [0,1,2,3,4]
1888 * @example $.merge( [3,2,1], [4,3,2] )
1893 * @param Array first The first array to merge.
1894 * @param Array second The second array to merge.
1897 merge: function(first, second) {
1900 // Move b over to the new array (this helps to avoid
1901 // StaticNodeList instances)
1902 for ( var k = 0; k < first.length; k++ )
1903 result[k] = first[k];
1905 // Now check for duplicates between a and b and only
1906 // add the unique items
1907 for ( var i = 0; i < second.length; i++ ) {
1908 var noCollision = true;
1910 // The collision-checking process
1911 for ( var j = 0; j < first.length; j++ )
1912 if ( second[i] == first[j] )
1913 noCollision = false;
1915 // If the item is unique, add it
1917 result.push( second[i] );
1924 * Filter items out of an array, by using a filter function.
1925 * The specified function will be passed two arguments: The
1926 * current array item and the index of the item in the array. The
1927 * function should return 'true' if you wish to keep the item in
1928 * the array, false if it should be removed.
1930 * @example $.grep( [0,1,2], function(i){
1937 * @param Array array The Array to find items in.
1938 * @param Function fn The function to process each item against.
1939 * @param Boolean inv Invert the selection - select the opposite of the function.
1942 grep: function(elems, fn, inv) {
1943 // If a string is passed in for the function, make a function
1944 // for it (a handy shortcut)
1945 if ( fn.constructor == String )
1946 fn = new Function("a","i","return " + fn);
1950 // Go through the array, only saving the items
1951 // that pass the validator function
1952 for ( var i = 0; i < elems.length; i++ )
1953 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1954 result.push( elems[i] );
1960 * Translate all items in an array to another array of items.
1961 * The translation function that is provided to this method is
1962 * called for each item in the array and is passed one argument:
1963 * The item to be translated. The function can then return:
1964 * The translated value, 'null' (to remove the item), or
1965 * an array of values - which will be flattened into the full array.
1967 * @example $.map( [0,1,2], function(i){
1972 * @example $.map( [0,1,2], function(i){
1973 * return i > 0 ? i + 1 : null;
1977 * @example $.map( [0,1,2], function(i){
1978 * return [ i, i + 1 ];
1980 * @result [0, 1, 1, 2, 2, 3]
1984 * @param Array array The Array to translate.
1985 * @param Function fn The function to process each item against.
1988 map: function(elems, fn) {
1989 // If a string is passed in for the function, make a function
1990 // for it (a handy shortcut)
1991 if ( fn.constructor == String )
1992 fn = new Function("a","return " + fn);
1996 // Go through the array, translating each of the items to their
1997 // new value (or values).
1998 for ( var i = 0; i < elems.length; i++ ) {
1999 var val = fn(elems[i],i);
2001 if ( val !== null && val != undefined ) {
2002 if ( val.constructor != Array ) val = [val];
2003 result = jQuery.merge( result, val );
2011 * A number of helper functions used for managing events.
2012 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2016 // Bind an event to an element
2017 // Original by Dean Edwards
2018 add: function(element, type, handler) {
2019 // For whatever reason, IE has trouble passing the window object
2020 // around, causing it to be cloned in the process
2021 if ( jQuery.browser.msie && element.setInterval != undefined )
2024 // Make sure that the function being executed has a unique ID
2025 if ( !handler.guid )
2026 handler.guid = this.guid++;
2028 // Init the element's event structure
2029 if (!element.events)
2030 element.events = {};
2032 // Get the current list of functions bound to this event
2033 var handlers = element.events[type];
2035 // If it hasn't been initialized yet
2037 // Init the event handler queue
2038 handlers = element.events[type] = {};
2040 // Remember an existing handler, if it's already there
2041 if (element["on" + type])
2042 handlers[0] = element["on" + type];
2045 // Add the function to the element's handler list
2046 handlers[handler.guid] = handler;
2048 // And bind the global event handler to the element
2049 element["on" + type] = this.handle;
2051 // Remember the function in a global list (for triggering)
2052 if (!this.global[type])
2053 this.global[type] = [];
2054 this.global[type].push( element );
2060 // Detach an event or set of events from an element
2061 remove: function(element, type, handler) {
2063 if (type && element.events[type])
2065 delete element.events[type][handler.guid];
2067 for ( var i in element.events[type] )
2068 delete element.events[type][i];
2070 for ( var j in element.events )
2071 this.remove( element, j );
2074 trigger: function(type,data,element) {
2075 // Touch up the incoming data
2078 // Handle a global trigger
2080 var g = this.global[type];
2082 for ( var i = 0; i < g.length; i++ )
2083 this.trigger( type, data, g[i] );
2085 // Handle triggering a single element
2086 } else if ( element["on" + type] ) {
2087 // Pass along a fake event
2088 data.unshift( this.fix({ type: type, target: element }) );
2090 // Trigger the event
2091 element["on" + type].apply( element, data );
2095 handle: function(event) {
2096 if ( typeof jQuery == "undefined" ) return;
2098 event = event || jQuery.event.fix( window.event );
2100 // If no correct event was found, fail
2101 if ( !event ) return;
2103 var returnValue = true;
2105 var c = this.events[event.type];
2107 for ( var j in c ) {
2108 if ( c[j].apply( this, [event] ) === false ) {
2109 event.preventDefault();
2110 event.stopPropagation();
2111 returnValue = false;
2118 fix: function(event) {
2120 event.preventDefault = function() {
2121 this.returnValue = false;
2124 event.stopPropagation = function() {
2125 this.cancelBubble = true;
2136 var b = navigator.userAgent.toLowerCase();
2138 // Figure out what browser is being used
2140 safari: /webkit/.test(b),
2141 opera: /opera/.test(b),
2142 msie: /msie/.test(b) && !/opera/.test(b),
2143 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2146 // Check to see if the W3C box model is being used
2147 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2153 * Append all of the matched elements to another, specified, set of elements.
2154 * This operation is, essentially, the reverse of doing a regular
2155 * $(A).append(B), in that instead of appending B to A, you're appending
2158 * @example $("p").appendTo("#foo");
2159 * @before <p>I would like to say: </p><div id="foo"></div>
2160 * @result <div id="foo"><p>I would like to say: </p></div>
2164 * @param String expr A jQuery expression of elements to match.
2165 * @cat DOM/Manipulation
2170 * Prepend all of the matched elements to another, specified, set of elements.
2171 * This operation is, essentially, the reverse of doing a regular
2172 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2175 * @example $("p").prependTo("#foo");
2176 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2177 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2181 * @param String expr A jQuery expression of elements to match.
2182 * @cat DOM/Manipulation
2184 prependTo: "prepend",
2187 * Insert all of the matched elements before another, specified, set of elements.
2188 * This operation is, essentially, the reverse of doing a regular
2189 * $(A).before(B), in that instead of inserting B before A, you're inserting
2192 * @example $("p").insertBefore("#foo");
2193 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2194 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2196 * @name insertBefore
2198 * @param String expr A jQuery expression of elements to match.
2199 * @cat DOM/Manipulation
2201 insertBefore: "before",
2204 * Insert all of the matched elements after another, specified, set of elements.
2205 * This operation is, essentially, the reverse of doing a regular
2206 * $(A).after(B), in that instead of inserting B after A, you're inserting
2209 * @example $("p").insertAfter("#foo");
2210 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2211 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2215 * @param String expr A jQuery expression of elements to match.
2216 * @cat DOM/Manipulation
2218 insertAfter: "after"
2222 * Get the current CSS width of the first matched element.
2224 * @example $("p").width();
2225 * @before <p>This is just a test.</p>
2234 * Set the CSS width of every matched element. Be sure to include
2235 * the "px" (or other unit of measurement) after the number that you
2236 * specify, otherwise you might get strange results.
2238 * @example $("p").width("20px");
2239 * @before <p>This is just a test.</p>
2240 * @result <p style="width:20px;">This is just a test.</p>
2244 * @param String val Set the CSS property to the specified value.
2249 * Get the current CSS height of the first matched element.
2251 * @example $("p").height();
2252 * @before <p>This is just a test.</p>
2261 * Set the CSS height of every matched element. Be sure to include
2262 * the "px" (or other unit of measurement) after the number that you
2263 * specify, otherwise you might get strange results.
2265 * @example $("p").height("20px");
2266 * @before <p>This is just a test.</p>
2267 * @result <p style="height:20px;">This is just a test.</p>
2271 * @param String val Set the CSS property to the specified value.
2276 * Get the current CSS top of the first matched element.
2278 * @example $("p").top();
2279 * @before <p>This is just a test.</p>
2288 * Set the CSS top of every matched element. Be sure to include
2289 * the "px" (or other unit of measurement) after the number that you
2290 * specify, otherwise you might get strange results.
2292 * @example $("p").top("20px");
2293 * @before <p>This is just a test.</p>
2294 * @result <p style="top:20px;">This is just a test.</p>
2298 * @param String val Set the CSS property to the specified value.
2303 * Get the current CSS left of the first matched element.
2305 * @example $("p").left();
2306 * @before <p>This is just a test.</p>
2315 * Set the CSS left of every matched element. Be sure to include
2316 * the "px" (or other unit of measurement) after the number that you
2317 * specify, otherwise you might get strange results.
2319 * @example $("p").left("20px");
2320 * @before <p>This is just a test.</p>
2321 * @result <p style="left:20px;">This is just a test.</p>
2325 * @param String val Set the CSS property to the specified value.
2330 * Get the current CSS position of the first matched element.
2332 * @example $("p").position();
2333 * @before <p>This is just a test.</p>
2342 * Set the CSS position of every matched element.
2344 * @example $("p").position("relative");
2345 * @before <p>This is just a test.</p>
2346 * @result <p style="position:relative;">This is just a test.</p>
2350 * @param String val Set the CSS property to the specified value.
2355 * Get the current CSS float of the first matched element.
2357 * @example $("p").float();
2358 * @before <p>This is just a test.</p>
2367 * Set the CSS float of every matched element.
2369 * @example $("p").float("left");
2370 * @before <p>This is just a test.</p>
2371 * @result <p style="float:left;">This is just a test.</p>
2375 * @param String val Set the CSS property to the specified value.
2380 * Get the current CSS overflow of the first matched element.
2382 * @example $("p").overflow();
2383 * @before <p>This is just a test.</p>
2392 * Set the CSS overflow of every matched element.
2394 * @example $("p").overflow("auto");
2395 * @before <p>This is just a test.</p>
2396 * @result <p style="overflow:auto;">This is just a test.</p>
2400 * @param String val Set the CSS property to the specified value.
2405 * Get the current CSS color of the first matched element.
2407 * @example $("p").color();
2408 * @before <p>This is just a test.</p>
2417 * Set the CSS color of every matched element.
2419 * @example $("p").color("blue");
2420 * @before <p>This is just a test.</p>
2421 * @result <p style="color:blue;">This is just a test.</p>
2425 * @param String val Set the CSS property to the specified value.
2430 * Get the current CSS background of the first matched element.
2432 * @example $("p").background();
2433 * @before <p style="background:blue;">This is just a test.</p>
2442 * Set the CSS background of every matched element.
2444 * @example $("p").background("blue");
2445 * @before <p>This is just a test.</p>
2446 * @result <p style="background:blue;">This is just a test.</p>
2450 * @param String val Set the CSS property to the specified value.
2454 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2457 * Reduce the set of matched elements to a single element.
2458 * The position of the element in the set of matched elements
2459 * starts at 0 and goes to length - 1.
2461 * @example $("p").eq(1)
2462 * @before <p>This is just a test.</p><p>So is this</p>
2463 * @result [ <p>So is this</p> ]
2467 * @param Number pos The index of the element that you wish to limit to.
2472 * Reduce the set of matched elements to all elements before a given position.
2473 * The position of the element in the set of matched elements
2474 * starts at 0 and goes to length - 1.
2476 * @example $("p").lt(1)
2477 * @before <p>This is just a test.</p><p>So is this</p>
2478 * @result [ <p>This is just a test.</p> ]
2482 * @param Number pos Reduce the set to all elements below this position.
2487 * Reduce the set of matched elements to all elements after a given position.
2488 * The position of the element in the set of matched elements
2489 * starts at 0 and goes to length - 1.
2491 * @example $("p").gt(0)
2492 * @before <p>This is just a test.</p><p>So is this</p>
2493 * @result [ <p>So is this</p> ]
2497 * @param Number pos Reduce the set to all elements after this position.
2502 * Filter the set of elements to those that contain the specified text.
2504 * @example $("p").contains("test")
2505 * @before <p>This is just a test.</p><p>So is this</p>
2506 * @result [ <p>This is just a test.</p> ]
2510 * @param String str The string that will be contained within the text of an element.
2511 * @cat DOM/Traversing
2514 filter: [ "eq", "lt", "gt", "contains" ],
2518 * Get the current value of the first matched element.
2520 * @example $("input").val();
2521 * @before <input type="text" value="some text"/>
2522 * @result "some text"
2524 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2525 * @test ok( !$("#text1").val() == "", "Check for value of input element" );
2529 * @cat DOM/Attributes
2533 * Set the value of every matched element.
2535 * @example $("input").value("test");
2536 * @before <input type="text" value="some text"/>
2537 * @result <input type="text" value="test"/>
2539 * @test document.getElementById('text1').value = "bla";
2540 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2541 * $("#text1").val('test');
2542 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2546 * @param String val Set the property to the specified value.
2547 * @cat DOM/Attributes
2552 * Get the html contents of the first matched element.
2554 * @example $("div").html();
2555 * @before <div><input/></div>
2560 * @cat DOM/Attributes
2564 * Set the html contents of every matched element.
2566 * @example $("div").html("<b>new stuff</b>");
2567 * @before <div><input/></div>
2568 * @result <div><b>new stuff</b></div>
2570 * @test var div = $("div");
2571 * div.html("<b>test</b>");
2573 * for ( var i = 0; i < div.size(); i++ ) {
2574 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2576 * ok( pass, "Set HTML" );
2580 * @param String val Set the html contents to the specified value.
2581 * @cat DOM/Attributes
2586 * Get the current id of the first matched element.
2588 * @example $("input").id();
2589 * @before <input type="text" id="test" value="some text"/>
2594 * @cat DOM/Attributes
2598 * Set the id of every matched element.
2600 * @example $("input").id("newid");
2601 * @before <input type="text" id="test" value="some text"/>
2602 * @result <input type="text" id="newid" value="some text"/>
2606 * @param String val Set the property to the specified value.
2607 * @cat DOM/Attributes
2612 * Get the current title of the first matched element.
2614 * @example $("img").title();
2615 * @before <img src="test.jpg" title="my image"/>
2616 * @result "my image"
2620 * @cat DOM/Attributes
2624 * Set the title of every matched element.
2626 * @example $("img").title("new title");
2627 * @before <img src="test.jpg" title="my image"/>
2628 * @result <img src="test.jpg" title="new image"/>
2632 * @param String val Set the property to the specified value.
2633 * @cat DOM/Attributes
2638 * Get the current name of the first matched element.
2640 * @example $("input").name();
2641 * @before <input type="text" name="username"/>
2642 * @result "username"
2646 * @cat DOM/Attributes
2650 * Set the name of every matched element.
2652 * @example $("input").name("user");
2653 * @before <input type="text" name="username"/>
2654 * @result <input type="text" name="user"/>
2658 * @param String val Set the property to the specified value.
2659 * @cat DOM/Attributes
2664 * Get the current href of the first matched element.
2666 * @example $("a").href();
2667 * @before <a href="test.html">my link</a>
2668 * @result "test.html"
2672 * @cat DOM/Attributes
2676 * Set the href of every matched element.
2678 * @example $("a").href("test2.html");
2679 * @before <a href="test.html">my link</a>
2680 * @result <a href="test2.html">my link</a>
2684 * @param String val Set the property to the specified value.
2685 * @cat DOM/Attributes
2690 * Get the current src of the first matched element.
2692 * @example $("img").src();
2693 * @before <img src="test.jpg" title="my image"/>
2694 * @result "test.jpg"
2698 * @cat DOM/Attributes
2702 * Set the src of every matched element.
2704 * @example $("img").src("test2.jpg");
2705 * @before <img src="test.jpg" title="my image"/>
2706 * @result <img src="test2.jpg" title="my image"/>
2710 * @param String val Set the property to the specified value.
2711 * @cat DOM/Attributes
2716 * Get the current rel of the first matched element.
2718 * @example $("a").rel();
2719 * @before <a href="test.html" rel="nofollow">my link</a>
2720 * @result "nofollow"
2724 * @cat DOM/Attributes
2728 * Set the rel of every matched element.
2730 * @example $("a").rel("nofollow");
2731 * @before <a href="test.html">my link</a>
2732 * @result <a href="test.html" rel="nofollow">my link</a>
2736 * @param String val Set the property to the specified value.
2737 * @cat DOM/Attributes
2744 * Get a set of elements containing the unique parents of the matched
2747 * @example $("p").parent()
2748 * @before <div><p>Hello</p><p>Hello</p></div>
2749 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2753 * @cat DOM/Traversing
2757 * Get a set of elements containing the unique parents of the matched
2758 * set of elements, and filtered by an expression.
2760 * @example $("p").parent(".selected")
2761 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2762 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2766 * @param String expr An expression to filter the parents with
2767 * @cat DOM/Traversing
2769 parent: "a.parentNode",
2772 * Get a set of elements containing the unique ancestors of the matched
2773 * set of elements (except for the root element).
2775 * @example $("span").ancestors()
2776 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2777 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2781 * @cat DOM/Traversing
2785 * Get a set of elements containing the unique ancestors of the matched
2786 * set of elements, and filtered by an expression.
2788 * @example $("span").ancestors("p")
2789 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2790 * @result [ <p><span>Hello</span></p> ]
2794 * @param String expr An expression to filter the ancestors with
2795 * @cat DOM/Traversing
2797 ancestors: jQuery.parents,
2800 * Get a set of elements containing the unique ancestors of the matched
2801 * set of elements (except for the root element).
2803 * @example $("span").ancestors()
2804 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2805 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2809 * @cat DOM/Traversing
2813 * Get a set of elements containing the unique ancestors of the matched
2814 * set of elements, and filtered by an expression.
2816 * @example $("span").ancestors("p")
2817 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2818 * @result [ <p><span>Hello</span></p> ]
2822 * @param String expr An expression to filter the ancestors with
2823 * @cat DOM/Traversing
2825 parents: jQuery.parents,
2828 * Get a set of elements containing the unique next siblings of each of the
2829 * matched set of elements.
2831 * It only returns the very next sibling, not all next siblings.
2833 * @example $("p").next()
2834 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2835 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2839 * @cat DOM/Traversing
2843 * Get a set of elements containing the unique next siblings of each of the
2844 * matched set of elements, and filtered by an expression.
2846 * It only returns the very next sibling, not all next siblings.
2848 * @example $("p").next(".selected")
2849 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2850 * @result [ <p class="selected">Hello Again</p> ]
2854 * @param String expr An expression to filter the next Elements with
2855 * @cat DOM/Traversing
2857 next: "jQuery.sibling(a).next",
2860 * Get a set of elements containing the unique previous siblings of each of the
2861 * matched set of elements.
2863 * It only returns the immediately previous sibling, not all previous siblings.
2865 * @example $("p").previous()
2866 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2867 * @result [ <div><span>Hello Again</span></div> ]
2871 * @cat DOM/Traversing
2875 * Get a set of elements containing the unique previous siblings of each of the
2876 * matched set of elements, and filtered by an expression.
2878 * It only returns the immediately previous sibling, not all previous siblings.
2880 * @example $("p").previous(".selected")
2881 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2882 * @result [ <div><span>Hello</span></div> ]
2886 * @param String expr An expression to filter the previous Elements with
2887 * @cat DOM/Traversing
2889 prev: "jQuery.sibling(a).prev",
2892 * Get a set of elements containing all of the unique siblings of each of the
2893 * matched set of elements.
2895 * @example $("div").siblings()
2896 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2897 * @result [ <p>Hello</p>, <p>And Again</p> ]
2901 * @cat DOM/Traversing
2905 * Get a set of elements containing all of the unique siblings of each of the
2906 * matched set of elements, and filtered by an expression.
2908 * @example $("div").siblings(".selected")
2909 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2910 * @result [ <p class="selected">Hello Again</p> ]
2914 * @param String expr An expression to filter the sibling Elements with
2915 * @cat DOM/Traversing
2917 siblings: jQuery.sibling,
2921 * Get a set of elements containing all of the unique children of each of the
2922 * matched set of elements.
2924 * @example $("div").children()
2925 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2926 * @result [ <span>Hello Again</span> ]
2930 * @cat DOM/Traversing
2934 * Get a set of elements containing all of the unique children of each of the
2935 * matched set of elements, and filtered by an expression.
2937 * @example $("div").children(".selected")
2938 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2939 * @result [ <p class="selected">Hello Again</p> ]
2943 * @param String expr An expression to filter the child Elements with
2944 * @cat DOM/Traversing
2946 children: "jQuery.sibling(a.firstChild)"
2952 * Remove an attribute from each of the matched elements.
2954 * @example $("input").removeAttr("disabled")
2955 * @before <input disabled="disabled"/>
2960 * @param String name The name of the attribute to remove.
2963 removeAttr: function( key ) {
2964 this.removeAttribute( key );
2968 * Displays each of the set of matched elements if they are hidden.
2970 * @example $("p").show()
2971 * @before <p style="display: none">Hello</p>
2972 * @result [ <p style="display: block">Hello</p> ]
2974 * @test var pass = true, div = $("div");
2975 * div.show().each(function(){
2976 * if ( this.style.display == "none" ) pass = false;
2978 * ok( pass, "Show" );
2985 this.style.display = this.oldblock ? this.oldblock : "";
2986 if ( jQuery.css(this,"display") == "none" )
2987 this.style.display = "block";
2991 * Hides each of the set of matched elements if they are shown.
2993 * @example $("p").hide()
2994 * @before <p>Hello</p>
2995 * @result [ <p style="display: none">Hello</p> ]
2997 * var pass = true, div = $("div");
2998 * div.hide().each(function(){
2999 * if ( this.style.display != "none" ) pass = false;
3001 * ok( pass, "Hide" );
3008 this.oldblock = this.oldblock || jQuery.css(this,"display");
3009 if ( this.oldblock == "none" )
3010 this.oldblock = "block";
3011 this.style.display = "none";
3015 * Toggles each of the set of matched elements. If they are shown,
3016 * toggle makes them hidden. If they are hidden, toggle
3019 * @example $("p").toggle()
3020 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3021 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3028 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3032 * Adds the specified class to each of the set of matched elements.
3034 * @example $("p").addClass("selected")
3035 * @before <p>Hello</p>
3036 * @result [ <p class="selected">Hello</p> ]
3038 * @test var div = $("div");
3039 * div.addClass("test");
3041 * for ( var i = 0; i < div.size(); i++ ) {
3042 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3044 * ok( pass, "Add Class" );
3048 * @param String class A CSS class to add to the elements
3051 addClass: function(c){
3052 jQuery.className.add(this,c);
3056 * Removes the specified class from the set of matched elements.
3058 * @example $("p").removeClass("selected")
3059 * @before <p class="selected">Hello</p>
3060 * @result [ <p>Hello</p> ]
3062 * @test var div = $("div").addClass("test");
3063 * div.removeClass("test");
3065 * for ( var i = 0; i < div.size(); i++ ) {
3066 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3068 * ok( pass, "Remove Class" );
3072 * @param String class A CSS class to remove from the elements
3075 removeClass: function(c){
3076 jQuery.className.remove(this,c);
3080 * Adds the specified class if it is present, removes it if it is
3083 * @example $("p").toggleClass("selected")
3084 * @before <p>Hello</p><p class="selected">Hello Again</p>
3085 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3089 * @param String class A CSS class with which to toggle the elements
3092 toggleClass: function( c ){
3093 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3097 * Removes all matched elements from the DOM. This does NOT remove them from the
3098 * jQuery object, allowing you to use the matched elements further.
3100 * @example $("p").remove();
3101 * @before <p>Hello</p> how are <p>you?</p>
3106 * @cat DOM/Manipulation
3110 * Removes only elements (out of the list of matched elements) that match
3111 * the specified jQuery expression. This does NOT remove them from the
3112 * jQuery object, allowing you to use the matched elements further.
3114 * @example $("p").remove(".hello");
3115 * @before <p class="hello">Hello</p> how are <p>you?</p>
3116 * @result how are <p>you?</p>
3120 * @param String expr A jQuery expression to filter elements by.
3121 * @cat DOM/Manipulation
3123 remove: function(a){
3124 if ( !a || jQuery.filter( a, [this] ).r )
3125 this.parentNode.removeChild( this );
3129 * Removes all child nodes from the set of matched elements.
3131 * @example $("p").empty()
3132 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3133 * @result [ <p></p> ]
3137 * @cat DOM/Manipulation
3140 while ( this.firstChild )
3141 this.removeChild( this.firstChild );
3145 * Binds a particular event (like click) to a each of a set of match elements.
3147 * @example $("p").bind( "click", function() { alert("Hello"); } )
3148 * @before <p>Hello</p>
3149 * @result [ <p>Hello</p> ]
3151 * Cancel a default action and prevent it from bubbling by returning false
3152 * from your function.
3154 * @example $("form").bind( "submit", function() { return false; } )
3156 * Cancel a default action by using the preventDefault method.
3158 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
3160 * Stop an event from bubbling by using the stopPropogation method.
3162 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
3166 * @param String type An event type
3167 * @param Function fn A function to bind to the event on each of the set of matched elements
3170 bind: function( type, fn ) {
3171 if ( fn.constructor == String )
3172 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3173 jQuery.event.add( this, type, fn );
3177 * The opposite of bind, removes a bound event from each of the matched
3178 * elements. You must pass the identical function that was used in the original
3181 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3182 * @before <p onclick="alert('Hello');">Hello</p>
3183 * @result [ <p>Hello</p> ]
3187 * @param String type An event type
3188 * @param Function fn A function to unbind from the event on each of the set of matched elements
3193 * Removes all bound events of a particular type from each of the matched
3196 * @example $("p").unbind( "click" )
3197 * @before <p onclick="alert('Hello');">Hello</p>
3198 * @result [ <p>Hello</p> ]
3202 * @param String type An event type
3207 * Removes all bound events from each of the matched elements.
3209 * @example $("p").unbind()
3210 * @before <p onclick="alert('Hello');">Hello</p>
3211 * @result [ <p>Hello</p> ]
3217 unbind: function( type, fn ) {
3218 jQuery.event.remove( this, type, fn );
3222 * Trigger a type of event on every matched element.
3224 * @example $("p").trigger("click")
3225 * @before <p click="alert('hello')">Hello</p>
3226 * @result alert('hello')
3230 * @param String type An event type to trigger.
3233 trigger: function( type, data ) {
3234 jQuery.event.trigger( type, data, this );