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' );
387 * @test ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
388 * @test ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
389 * @test ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
390 * @test ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
391 * @test ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
392 * @test ok( $('#name').attr('name') == "name", 'Check for name attribute' );
396 * @param String name The name of the property to access.
401 * Set a hash of key/value object properties to all matched elements.
402 * This serves as the best way to set a large number of properties
403 * on all matched elements.
405 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
407 * @result <img src="test.jpg" alt="Test Image"/>
409 * @test var pass = true;
410 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
411 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
413 * ok( pass, "Set Multiple Attributes" );
417 * @param Hash prop A set of key/value pairs to set as object properties.
422 * Set a single property to a value, on all matched elements.
424 * @example $("img").attr("src","test.jpg");
426 * @result <img src="test.jpg"/>
428 * @test var div = $("div");
429 * div.attr("foo", "bar");
431 * for ( var i = 0; i < div.size(); i++ ) {
432 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
434 * ok( pass, "Set Attribute" );
436 * @test $("#name").attr('name', 'something');
437 * ok( $("#name").name() == 'something', 'Set name attribute' );
438 * @test $("#check2").attr('checked', true);
439 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
440 * $("#check2").attr('checked', false);
441 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
445 * @param String key The name of the property to set.
446 * @param Object value The value to set the property to.
449 attr: function( key, value, type ) {
450 // Check to see if we're setting style values
451 return key.constructor != String || value != undefined ?
452 this.each(function(){
453 // See if we're setting a hash of styles
454 if ( value == undefined )
455 // Set all the styles
456 for ( var prop in key )
458 type ? this.style : this,
462 // See if we're setting a single key/value style
465 type ? this.style : this,
470 // Look for the case where we're accessing a style value
471 jQuery[ type || "attr" ]( this[0], key );
475 * Access a style property on the first matched element.
476 * This method makes it easy to retrieve a style property value
477 * from the first matched element.
479 * @example $("p").css("color");
480 * @before <p style="color:red;">Test Paragraph.</p>
482 * @desc Retrieves the color style of the first paragraph
484 * @example $("p").css("fontWeight");
485 * @before <p style="font-weight: bold;">Test Paragraph.</p>
487 * @desc Retrieves the font-weight style of the first paragraph.
488 * Note that for all style properties with a dash (like 'font-weight'), you have to
489 * write it in camelCase. In other words: Every time you have a '-' in a
490 * property, remove it and replace the next character with an uppercase
491 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
492 * borderStyle, borderBottomWidth etc.
494 * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
498 * @param String name The name of the property to access.
503 * Set a hash of key/value style properties to all matched elements.
504 * This serves as the best way to set a large number of style properties
505 * on all matched elements.
507 * @example $("p").css({ color: "red", background: "blue" });
508 * @before <p>Test Paragraph.</p>
509 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
511 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
512 * @test $('#foo').css({display: 'none'});
513 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
514 * @test $('#foo').css({display: 'block'});
515 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
519 * @param Hash prop A set of key/value pairs to set as style properties.
524 * Set a single style property to a value, on all matched elements.
526 * @example $("p").css("color","red");
527 * @before <p>Test Paragraph.</p>
528 * @result <p style="color:red;">Test Paragraph.</p>
529 * @desc Changes the color of all paragraphs to red
532 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
533 * @test $('#foo').css('display', 'none');
534 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
535 * @test $('#foo').css('display', 'block');
536 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
540 * @param String key The name of the property to set.
541 * @param Object value The value to set the property to.
544 css: function( key, value ) {
545 return this.attr( key, value, "curCSS" );
549 * Retrieve the text contents of all matched elements. The result is
550 * a string that contains the combined text contents of all matched
551 * elements. This method works on both HTML and XML documents.
553 * @example $("p").text();
554 * @before <p>Test Paragraph.</p>
555 * @result Test Paragraph.
557 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
558 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
567 for ( var j = 0; j < e.length; j++ ) {
568 var r = e[j].childNodes;
569 for ( var i = 0; i < r.length; i++ )
570 if ( r[i].nodeType != 8 )
571 t += r[i].nodeType != 1 ?
572 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
578 * Wrap all matched elements with a structure of other elements.
579 * This wrapping process is most useful for injecting additional
580 * stucture into a document, without ruining the original semantic
581 * qualities of a document.
583 * This works by going through the first element
584 * provided (which is generated, on the fly, from the provided HTML)
585 * and finds the deepest ancestor element within its
586 * structure - it is that element that will en-wrap everything else.
588 * @example $("p").wrap("<div class='wrap'></div>");
589 * @before <p>Test Paragraph.</p>
590 * @result <div class='wrap'><p>Test Paragraph.</p></div>
592 * @test var defaultText = 'Try them out:'
593 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
594 * ok( defaultText == result, 'Check for simple wrapping' );
595 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
597 * @test var defaultText = 'Try them out:'
598 * var result = $('#first').wrap('<div class="red">xx<span></span>yy</div>').text()
599 * ok( 'xx' + defaultText + 'yy' == result, 'Check for wrapping' );
600 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
604 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
605 * @cat DOM/Manipulation
609 * Wrap all matched elements with a structure of other elements.
610 * This wrapping process is most useful for injecting additional
611 * stucture into a document, without ruining the original semantic
612 * qualities of a document.
614 * This works by going through the first element
615 * provided and finding the deepest ancestor element within its
616 * structure - it is that element that will en-wrap everything else.
618 * @example $("p").wrap("<div class='wrap'></div>");
619 * @before <p>Test Paragraph.</p>
620 * @result <div class='wrap'><p>Test Paragraph.</p></div>
624 * @param Element elem A DOM element that will be wrapped.
625 * @cat DOM/Manipulation
628 // The elements to wrap the target around
629 var a = jQuery.clean(arguments);
631 // Wrap each of the matched elements individually
632 return this.each(function(){
633 // Clone the structure that we're using to wrap
634 var b = a[0].cloneNode(true);
636 // Insert it before the element to be wrapped
637 this.parentNode.insertBefore( b, this );
639 // Find he deepest point in the wrap structure
640 while ( b.firstChild )
643 // Move the matched element to within the wrap structure
644 b.appendChild( this );
649 * Append any number of elements to the inside of every matched elements,
650 * generated from the provided HTML.
651 * This operation is similar to doing an appendChild to all the
652 * specified elements, adding them into the document.
654 * @example $("p").append("<b>Hello</b>");
655 * @before <p>I would like to say: </p>
656 * @result <p>I would like to say: <b>Hello</b></p>
658 * @test var defaultText = 'Try them out:'
659 * var result = $('#first').append('<b>buga</b>');
660 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
664 * @param String html A string of HTML, that will be created on the fly and appended to the target.
665 * @cat DOM/Manipulation
669 * Append an element to the inside of all matched elements.
670 * This operation is similar to doing an appendChild to all the
671 * specified elements, adding them into the document.
673 * @example $("p").append( $("#foo")[0] );
674 * @before <p>I would like to say: </p><b id="foo">Hello</b>
675 * @result <p>I would like to say: <b id="foo">Hello</b></p>
677 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
678 * $('#sap').append(document.getElementById('first'));
679 * ok( expected == $('#sap').text(), "Check for appending of element" );
683 * @param Element elem A DOM element that will be appended.
684 * @cat DOM/Manipulation
688 * Append any number of elements to the inside of all matched elements.
689 * This operation is similar to doing an appendChild to all the
690 * specified elements, adding them into the document.
692 * @example $("p").append( $("b") );
693 * @before <p>I would like to say: </p><b>Hello</b>
694 * @result <p>I would like to say: <b>Hello</b></p>
696 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
697 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
698 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
702 * @param Array<Element> elems An array of elements, all of which will be appended.
703 * @cat DOM/Manipulation
706 return this.domManip(arguments, true, 1, function(a){
707 this.appendChild( a );
712 * Prepend any number of elements to the inside of every matched elements,
713 * generated from the provided HTML.
714 * This operation is the best way to insert dynamically created elements
715 * inside, at the beginning, of all the matched element.
717 * @example $("p").prepend("<b>Hello</b>");
718 * @before <p>I would like to say: </p>
719 * @result <p><b>Hello</b>I would like to say: </p>
721 * @test var defaultText = 'Try them out:'
722 * var result = $('#first').prepend('<b>buga</b>');
723 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
727 * @param String html A string of HTML, that will be created on the fly and appended to the target.
728 * @cat DOM/Manipulation
732 * Prepend an element to the inside of all matched elements.
733 * This operation is the best way to insert an element inside, at the
734 * beginning, of all the matched element.
736 * @example $("p").prepend( $("#foo")[0] );
737 * @before <p>I would like to say: </p><b id="foo">Hello</b>
738 * @result <p><b id="foo">Hello</b>I would like to say: </p>
740 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
741 * $('#sap').prepend(document.getElementById('first'));
742 * ok( expected == $('#sap').text(), "Check for prepending of element" );
746 * @param Element elem A DOM element that will be appended.
747 * @cat DOM/Manipulation
751 * Prepend any number of elements to the inside of all matched elements.
752 * This operation is the best way to insert a set of elements inside, at the
753 * beginning, of all the matched element.
755 * @example $("p").prepend( $("b") );
756 * @before <p>I would like to say: </p><b>Hello</b>
757 * @result <p><b>Hello</b>I would like to say: </p>
759 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
760 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
761 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
765 * @param Array<Element> elems An array of elements, all of which will be appended.
766 * @cat DOM/Manipulation
768 prepend: function() {
769 return this.domManip(arguments, true, -1, function(a){
770 this.insertBefore( a, this.firstChild );
775 * Insert any number of dynamically generated elements before each of the
778 * @example $("p").before("<b>Hello</b>");
779 * @before <p>I would like to say: </p>
780 * @result <b>Hello</b><p>I would like to say: </p>
782 * @test var expected = 'This is a normal link: bugaYahoo';
783 * $('#yahoo').before('<b>buga</b>');
784 * ok( expected == $('#en').text(), 'Insert String before' );
788 * @param String html A string of HTML, that will be created on the fly and appended to the target.
789 * @cat DOM/Manipulation
793 * Insert an element before each of the matched elements.
795 * @example $("p").before( $("#foo")[0] );
796 * @before <p>I would like to say: </p><b id="foo">Hello</b>
797 * @result <b id="foo">Hello</b><p>I would like to say: </p>
799 * @test var expected = "This is a normal link: Try them out:Yahoo";
800 * $('#yahoo').before(document.getElementById('first'));
801 * ok( expected == $('#en').text(), "Insert element before" );
805 * @param Element elem A DOM element that will be appended.
806 * @cat DOM/Manipulation
810 * Insert any number of elements before each of the matched elements.
812 * @example $("p").before( $("b") );
813 * @before <p>I would like to say: </p><b>Hello</b>
814 * @result <b>Hello</b><p>I would like to say: </p>
816 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
817 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
818 * ok( expected == $('#en').text(), "Insert array of elements before" );
822 * @param Array<Element> elems An array of elements, all of which will be appended.
823 * @cat DOM/Manipulation
826 return this.domManip(arguments, false, 1, function(a){
827 this.parentNode.insertBefore( a, this );
832 * Insert any number of dynamically generated elements after each of the
835 * @example $("p").after("<b>Hello</b>");
836 * @before <p>I would like to say: </p>
837 * @result <p>I would like to say: </p><b>Hello</b>
839 * @test var expected = 'This is a normal link: Yahoobuga';
840 * $('#yahoo').after('<b>buga</b>');
841 * ok( expected == $('#en').text(), 'Insert String after' );
845 * @param String html A string of HTML, that will be created on the fly and appended to the target.
846 * @cat DOM/Manipulation
850 * Insert an element after each of the matched elements.
852 * @example $("p").after( $("#foo")[0] );
853 * @before <b id="foo">Hello</b><p>I would like to say: </p>
854 * @result <p>I would like to say: </p><b id="foo">Hello</b>
856 * @test var expected = "This is a normal link: YahooTry them out:";
857 * $('#yahoo').after(document.getElementById('first'));
858 * ok( expected == $('#en').text(), "Insert element after" );
862 * @param Element elem A DOM element that will be appended.
863 * @cat DOM/Manipulation
867 * Insert any number of elements after each of the matched elements.
869 * @example $("p").after( $("b") );
870 * @before <b>Hello</b><p>I would like to say: </p>
871 * @result <p>I would like to say: </p><b>Hello</b>
873 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
874 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
875 * ok( expected == $('#en').text(), "Insert array of elements after" );
879 * @param Array<Element> elems An array of elements, all of which will be appended.
880 * @cat DOM/Manipulation
883 return this.domManip(arguments, false, -1, function(a){
884 this.parentNode.insertBefore( a, this.nextSibling );
889 * End the most recent 'destructive' operation, reverting the list of matched elements
890 * back to its previous state. After an end operation, the list of matched elements will
891 * revert to the last state of matched elements.
893 * @example $("p").find("span").end();
894 * @before <p><span>Hello</span>, how are you?</p>
895 * @result $("p").find("span").end() == [ <p>...</p> ]
897 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
901 * @cat DOM/Traversing
904 return this.get( this.stack.pop() );
908 * Searches for all elements that match the specified expression.
909 * This method is the optimal way of finding additional descendant
910 * elements with which to process.
912 * All searching is done using a jQuery expression. The expression can be
913 * written using CSS 1-3 Selector syntax, or basic XPath.
915 * @example $("p").find("span");
916 * @before <p><span>Hello</span>, how are you?</p>
917 * @result $("p").find("span") == [ <span>Hello</span> ]
919 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
923 * @param String expr An expression to search with.
924 * @cat DOM/Traversing
927 return this.pushStack( jQuery.map( this, function(a){
928 return jQuery.find(t,a);
933 * Create cloned copies of all matched DOM Elements. This does
934 * not create a cloned copy of this particular jQuery object,
935 * instead it creates duplicate copies of all DOM Elements.
936 * This is useful for moving copies of the elements to another
937 * location in the DOM.
939 * @example $("b").clone().prependTo("p");
940 * @before <b>Hello</b><p>, how are you?</p>
941 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
943 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
944 * var clone = $('#yahoo').clone();
945 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
946 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
950 * @cat DOM/Manipulation
952 clone: function(deep) {
953 return this.pushStack( jQuery.map( this, function(a){
954 return a.cloneNode( deep != undefined ? deep : true );
959 * Removes all elements from the set of matched elements that do not
960 * match the specified expression. This method is used to narrow down
961 * the results of a search.
963 * All searching is done using a jQuery expression. The expression
964 * can be written using CSS 1-3 Selector syntax, or basic XPath.
966 * @example $("p").filter(".selected")
967 * @before <p class="selected">Hello</p><p>How are you?</p>
968 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
970 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
974 * @param String expr An expression to search with.
975 * @cat DOM/Traversing
979 * Removes all elements from the set of matched elements that do not
980 * match at least one of the expressions passed to the function. This
981 * method is used when you want to filter the set of matched elements
982 * through more than one expression.
984 * Elements will be retained in the jQuery object if they match at
985 * least one of the expressions passed.
987 * @example $("p").filter([".selected", ":first"])
988 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
989 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
993 * @param Array<String> exprs A set of expressions to evaluate against
994 * @cat DOM/Traversing
996 filter: function(t) {
997 return this.pushStack(
998 t.constructor == Array &&
999 jQuery.map(this,function(a){
1000 for ( var i = 0; i < t.length; i++ )
1001 if ( jQuery.filter(t[i],[a]).r.length )
1005 t.constructor == Boolean &&
1006 ( t ? this.get() : [] ) ||
1008 t.constructor == Function &&
1009 jQuery.grep( this, t ) ||
1011 jQuery.filter(t,this).r, arguments );
1015 * Removes the specified Element from the set of matched elements. This
1016 * method is used to remove a single Element from a jQuery object.
1018 * @example $("p").not( document.getElementById("selected") )
1019 * @before <p>Hello</p><p id="selected">Hello Again</p>
1020 * @result [ <p>Hello</p> ]
1024 * @param Element el An element to remove from the set
1025 * @cat DOM/Traversing
1029 * Removes elements matching the specified expression from the set
1030 * of matched elements. This method is used to remove one or more
1031 * elements from a jQuery object.
1033 * @example $("p").not("#selected")
1034 * @before <p>Hello</p><p id="selected">Hello Again</p>
1035 * @result [ <p>Hello</p> ]
1036 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
1040 * @param String expr An expression with which to remove matching elements
1041 * @cat DOM/Traversing
1044 return this.pushStack( t.constructor == String ?
1045 jQuery.filter(t,this,false).r :
1046 jQuery.grep(this,function(a){ return a != t; }), arguments );
1050 * Adds the elements matched by the expression to the jQuery object. This
1051 * can be used to concatenate the result sets of two expressions.
1053 * @example $("p").add("span")
1054 * @before <p>Hello</p><p><span>Hello Again</span></p>
1055 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1059 * @param String expr An expression whose matched elements are added
1060 * @cat DOM/Traversing
1064 * Adds each of the Elements in the array to the set of matched elements.
1065 * This is used to add a set of Elements to a jQuery object.
1067 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1068 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1069 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1073 * @param Array<Element> els An array of Elements to add
1074 * @cat DOM/Traversing
1078 * Adds a single Element to the set of matched elements. This is used to
1079 * add a single Element to a jQuery object.
1081 * @example $("p").add( document.getElementById("a") )
1082 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1083 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1087 * @param Element el An Element to add
1088 * @cat DOM/Traversing
1091 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1092 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1096 * Checks the current selection against an expression and returns true,
1097 * if the selection fits the given expression. Does return false, if the
1098 * selection does not fit or the expression is not valid.
1100 * @example $("input[@type='checkbox']").parent().is("form")
1101 * @before <form><input type="checkbox" /></form>
1103 * @desc Returns true, because the parent of the input is a form element
1105 * @example $("input[@type='checkbox']").parent().is("form")
1106 * @before <form><p><input type="checkbox" /></p></form>
1108 * @desc Returns false, because the parent of the input is a p element
1110 * @example $("form").is(null)
1111 * @before <form></form>
1113 * @desc An invalid expression always returns false.
1115 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1116 * @test ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1117 * @test ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1118 * @test ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1119 * @test ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1120 * @test ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1121 * @test ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1122 * @test ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1123 * @test ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1124 * @test ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1125 * @test ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1126 * @test ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1127 * @test ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1128 * @test ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1129 * @test ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1130 * @test ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1131 * @test ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1132 * @test ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1133 * @test ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1134 * @test ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1135 * @test ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1136 * @test ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1140 * @param String expr The expression with which to filter
1141 * @cat DOM/Traversing
1143 is: function(expr) {
1144 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1153 * @param Boolean table
1155 * @param Function fn The function doing the DOM manipulation.
1159 domManip: function(args, table, dir, fn){
1160 var clone = this.size() > 1;
1161 var a = jQuery.clean(args);
1163 return this.each(function(){
1166 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
1167 var tbody = this.getElementsByTagName("tbody");
1169 if ( !tbody.length ) {
1170 obj = document.createElement("tbody");
1171 this.appendChild( obj );
1176 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1177 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1178 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1193 pushStack: function(a,args) {
1194 var fn = args && args[args.length-1];
1196 if ( !fn || fn.constructor != Function ) {
1197 if ( !this.stack ) this.stack = [];
1198 this.stack.push( this.get() );
1201 var old = this.get();
1203 if ( fn.constructor == Function )
1223 * Extend one object with another, returning the original,
1224 * modified, object. This is a great utility for simple inheritance.
1226 * @example var settings = { validate: false, limit: 5, name: "foo" };
1227 * var options = { validate: true, name: "bar" };
1228 * jQuery.extend(settings, options);
1229 * @result settings == { validate: true, limit: 5, name: "bar" }
1231 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1232 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1233 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1234 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1235 * jQuery.extend(settings, options);
1236 * isSet( settings, merged, "Check if extended: settings must be extended" );
1237 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1240 * @param Object obj The object to extend
1241 * @param Object prop The object that will be merged into the first.
1245 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1246 if ( !prop ) { prop = obj; obj = this; }
1247 for ( var i in prop ) obj[i] = prop[i];
1259 jQuery.initDone = true;
1261 jQuery.each( jQuery.macros.axis, function(i,n){
1262 jQuery.fn[ i ] = function(a) {
1263 var ret = jQuery.map(this,n);
1264 if ( a && a.constructor == String )
1265 ret = jQuery.filter(a,ret).r;
1266 return this.pushStack( ret, arguments );
1270 jQuery.each( jQuery.macros.to, function(i,n){
1271 jQuery.fn[ i ] = function(){
1273 return this.each(function(){
1274 for ( var j = 0; j < a.length; j++ )
1275 jQuery(a[j])[n]( this );
1280 jQuery.each( jQuery.macros.each, function(i,n){
1281 jQuery.fn[ i ] = function() {
1282 return this.each( n, arguments );
1286 jQuery.each( jQuery.macros.filter, function(i,n){
1287 jQuery.fn[ n ] = function(num,fn) {
1288 return this.filter( ":" + n + "(" + num + ")", fn );
1292 jQuery.each( jQuery.macros.attr, function(i,n){
1294 jQuery.fn[ i ] = function(h) {
1295 return h == undefined ?
1296 this.length ? this[0][n] : null :
1301 jQuery.each( jQuery.macros.css, function(i,n){
1302 jQuery.fn[ n ] = function(h) {
1303 return h == undefined ?
1304 ( this.length ? jQuery.css( this[0], n ) : null ) :
1312 * A generic iterator function, which can be used to seemlessly
1313 * iterate over both objects and arrays. This function is not the same
1314 * as $().each() - which is used to iterate, exclusively, over a jQuery
1315 * object. This function can be used to iterate over anything.
1317 * @example $.each( [0,1,2], function(i){
1318 * alert( "Item #" + i + ": " + this );
1320 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1322 * @example $.each( { name: "John", lang: "JS" }, function(i){
1323 * alert( "Name: " + i + ", Value: " + this );
1325 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1328 * @param Object obj The object, or array, to iterate over.
1329 * @param Function fn The function that will be executed on every object.
1333 each: function( obj, fn, args ) {
1334 if ( obj.length == undefined )
1335 for ( var i in obj )
1336 fn.apply( obj[i], args || [i, obj[i]] );
1338 for ( var i = 0; i < obj.length; i++ )
1339 fn.apply( obj[i], args || [i, obj[i]] );
1345 if (jQuery.className.has(o,c)) return;
1346 o.className += ( o.className ? " " : "" ) + c;
1348 remove: function(o,c){
1349 o.className = !c ? "" :
1350 o.className.replace(
1351 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
1353 has: function(e,a) {
1354 if ( e.className != undefined )
1356 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1361 * Swap in/out style options.
1364 swap: function(e,o,f) {
1365 for ( var i in o ) {
1366 e.style["old"+i] = e.style[i];
1371 e.style[i] = e.style["old"+i];
1374 css: function(e,p) {
1375 if ( p == "height" || p == "width" ) {
1376 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1378 for ( var i in d ) {
1379 old["padding" + d[i]] = 0;
1380 old["border" + d[i] + "Width"] = 0;
1383 jQuery.swap( e, old, function() {
1384 if (jQuery.css(e,"display") != "none") {
1385 oHeight = e.offsetHeight;
1386 oWidth = e.offsetWidth;
1388 e = jQuery(e.cloneNode(true)).css({
1389 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1390 }).appendTo(e.parentNode)[0];
1392 var parPos = jQuery.css(e.parentNode,"position");
1393 if ( parPos == "" || parPos == "static" )
1394 e.parentNode.style.position = "relative";
1396 oHeight = e.clientHeight;
1397 oWidth = e.clientWidth;
1399 if ( parPos == "" || parPos == "static" )
1400 e.parentNode.style.position = "static";
1402 e.parentNode.removeChild(e);
1406 return p == "height" ? oHeight : oWidth;
1407 } else if ( p == "opacity" && jQuery.browser.msie )
1408 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1410 return jQuery.curCSS( e, p );
1413 curCSS: function(elem, prop, force) {
1416 if (!force && elem.style[prop]) {
1418 ret = elem.style[prop];
1420 } else if (elem.currentStyle) {
1422 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1423 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1425 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1427 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1428 var cur = document.defaultView.getComputedStyle(elem, null);
1431 ret = cur.getPropertyValue(prop);
1432 else if ( prop == 'display' )
1435 jQuery.swap(elem, { display: 'block' }, function() {
1436 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1444 clean: function(a) {
1446 for ( var i = 0; i < a.length; i++ ) {
1447 if ( a[i].constructor == String ) {
1451 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1453 a[i] = "<table>" + a[i] + "</table>";
1454 } else if ( !a[i].indexOf("<tr") ) {
1456 a[i] = "<table>" + a[i] + "</table>";
1457 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1459 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1462 var div = document.createElement("div");
1463 div.innerHTML = a[i];
1466 div = div.firstChild;
1467 if ( table != "thead" ) div = div.firstChild;
1468 if ( table == "td" ) div = div.firstChild;
1471 for ( var j = 0; j < div.childNodes.length; j++ )
1472 r.push( div.childNodes[j] );
1473 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1474 for ( var k = 0; k < a[i].length; k++ )
1476 else if ( a[i] !== null )
1477 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1483 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1484 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1492 last: "i==r.length-1",
1497 "nth-child": "jQuery.sibling(a,m[3]).cur",
1498 "first-child": "jQuery.sibling(a,0).cur",
1499 "last-child": "jQuery.sibling(a,0).last",
1500 "only-child": "jQuery.sibling(a).length==1",
1503 parent: "a.childNodes.length",
1504 empty: "!a.childNodes.length",
1507 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1510 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1511 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1514 enabled: "!a.disabled",
1515 disabled: "a.disabled",
1516 checked: "a.checked",
1517 selected: "a.selected"
1519 ".": "jQuery.className.has(a,m[2])",
1523 "^=": "!z.indexOf(m[4])",
1524 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1525 "*=": "z.indexOf(m[4])>=0",
1528 "[": "jQuery.find(m[2],a).length"
1532 "\\.\\.|/\\.\\.", "a.parentNode",
1533 ">|/", "jQuery.sibling(a.firstChild)",
1534 "\\+", "jQuery.sibling(a).next",
1537 var s = jQuery.sibling(a);
1539 for ( var i = s.n; i < s.length; i++ )
1547 * @test t( "Element Selector", "div", ["main","foo"] );
1548 * @test t( "Element Selector", "body", ["body"] );
1549 * @test t( "Element Selector", "html", ["html"] );
1550 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1551 * @test t( "Parent Element", "div div", ["foo"] );
1553 * @test t( "ID Selector", "#body", ["body"] );
1554 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1555 * @test t( "ID Selector w/ Element", "ul#first", [] );
1557 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1558 * @test t( "Class Selector", ".blog.link", ["simon"] );
1559 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1560 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1562 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1563 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1564 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1565 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1567 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1568 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1569 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1570 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1571 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1572 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1573 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1574 * @test t( "Adjacent", "a + a", ["groups"] );
1575 * @test t( "Adjacent", "a +a", ["groups"] );
1576 * @test t( "Adjacent", "a+ a", ["groups"] );
1577 * @test t( "Adjacent", "a+a", ["groups"] );
1578 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1579 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1580 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1581 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1582 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1583 * @test t( "Attribute Exists", "[@title]", ["google"] );
1584 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1585 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1586 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1587 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1588 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1589 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1591 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1592 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1593 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1594 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1595 * @test t( "Last Child", "p:last-child", ["sap"] );
1596 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1597 * @test t( "Empty", "ul:empty", ["firstUL"] );
1598 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1599 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1600 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1601 * @test t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1602 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1603 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1604 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1605 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1607 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1608 * @test t( "All Div Elements", "//div", ["main","foo"] );
1609 * @test t( "Absolute Path", "/html/body", ["body"] );
1610 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1611 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1612 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1613 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1614 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1615 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1616 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1617 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1618 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1619 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1620 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1622 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1623 * @test t( "First Element", "p:first", ["firstp"] );
1624 * @test t( "Last Element", "p:last", ["first"] );
1625 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1626 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1627 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1628 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1629 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1630 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1631 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1632 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1635 * @type Array<Element>
1639 find: function( t, context ) {
1640 // Make sure that the context is a DOM Element
1641 if ( context && context.nodeType == undefined )
1644 // Set the correct context (if none is provided)
1645 context = context || jQuery.context || document;
1647 if ( t.constructor != String ) return [t];
1649 if ( !t.indexOf("//") ) {
1650 context = context.documentElement;
1651 t = t.substr(2,t.length);
1652 } else if ( !t.indexOf("/") ) {
1653 context = context.documentElement;
1654 t = t.substr(1,t.length);
1655 // FIX Assume the root element is right :(
1656 if ( t.indexOf("/") >= 1 )
1657 t = t.substr(t.indexOf("/"),t.length);
1660 var ret = [context];
1664 while ( t.length > 0 && last != t ) {
1668 t = jQuery.trim(t).replace( /^\/\//i, "" );
1670 var foundToken = false;
1672 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1673 if ( foundToken ) continue;
1675 var re = new RegExp("^(" + jQuery.token[i] + ")");
1679 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1680 t = jQuery.trim( t.replace( re, "" ) );
1685 if ( !foundToken ) {
1686 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1687 if ( ret[0] == context ) ret.shift();
1688 done = jQuery.merge( done, ret );
1689 r = ret = [context];
1690 t = " " + t.substr(1,t.length);
1692 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1693 var m = re2.exec(t);
1695 if ( m[1] == "#" ) {
1696 // Ummm, should make this work in all XML docs
1697 var oid = document.getElementById(m[2]);
1698 r = ret = oid ? [oid] : [];
1699 t = t.replace( re2, "" );
1701 if ( !m[2] || m[1] == "." ) m[2] = "*";
1703 for ( var i = 0; i < ret.length; i++ )
1704 r = jQuery.merge( r,
1706 jQuery.getAll(ret[i]) :
1707 ret[i].getElementsByTagName(m[2])
1715 var val = jQuery.filter(t,r);
1717 t = jQuery.trim(val.t);
1721 if ( ret && ret[0] == context ) ret.shift();
1722 done = jQuery.merge( done, ret );
1727 getAll: function(o,r) {
1729 var s = o.childNodes;
1730 for ( var i = 0; i < s.length; i++ )
1731 if ( s[i].nodeType == 1 ) {
1733 jQuery.getAll( s[i], r );
1738 attr: function(elem, name, value){
1741 "class": "className",
1742 "float": "cssFloat",
1743 innerHTML: "innerHTML",
1744 className: "className",
1746 disabled: "disabled",
1751 if ( value != undefined ) elem[fix[name]] = value;
1752 return elem[fix[name]];
1753 } else if ( elem.getAttribute != undefined ) {
1754 if ( value != undefined ) elem.setAttribute( name, value );
1755 return elem.getAttribute( name, 2 );
1757 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1758 if ( value != undefined ) elem[name] = value;
1763 // The regular expressions that power the parsing engine
1765 // Match: [@value='test'], [@foo]
1766 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1768 // Match: [div], [div p]
1771 // Match: :contains('foo')
1772 [ "(:)S\\(Q\\)", 0 ],
1774 // Match: :even, :last-chlid
1778 filter: function(t,r,not) {
1779 // Figure out if we're doing regular, or inverse, filtering
1780 var g = not !== false ? jQuery.grep :
1781 function(a,f) {return jQuery.grep(a,f,true);};
1783 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1785 var p = jQuery.parse;
1787 for ( var i = 0; i < p.length; i++ ) {
1788 var re = new RegExp( "^" + p[i][0]
1790 // Look for a string-like sequence
1791 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1793 // Look for something (optionally) enclosed with quotes
1794 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1796 var m = re.exec( t );
1799 // Re-organize the match
1801 m = ["", m[1], m[3], m[2], m[4]];
1803 // Remove what we just matched
1804 t = t.replace( re, "" );
1810 // :not() is a special case that can be optomized by
1811 // keeping it out of the expression list
1812 if ( m[1] == ":" && m[2] == "not" )
1813 r = jQuery.filter(m[3],r,false).r;
1815 // Otherwise, find the expression to execute
1817 var f = jQuery.expr[m[1]];
1818 if ( f.constructor != String )
1819 f = jQuery.expr[m[1]][m[2]];
1821 // Build a custom macro to enclose it
1822 eval("f = function(a,i){" +
1823 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1824 "return " + f + "}");
1826 // Execute it against the current filter
1831 // Return an array of filtered elements (r)
1832 // and the modified expression string (t)
1833 return { r: r, t: t };
1837 * Remove the whitespace from the beginning and end of a string.
1839 * @example $.trim(" hello, how are you? ");
1840 * @result "hello, how are you?"
1844 * @param String str The string to trim.
1848 return t.replace(/^\s+|\s+$/g, "");
1852 * All ancestors of a given element.
1856 * @type Array<Element>
1857 * @param Element elem The element to find the ancestors of.
1858 * @cat DOM/Traversing
1860 parents: function( elem ){
1862 var cur = elem.parentNode;
1863 while ( cur && cur != document ) {
1864 matched.push( cur );
1865 cur = cur.parentNode;
1871 * All elements on a specified axis.
1876 * @param Element elem The element to find all the siblings of (including itself).
1877 * @cat DOM/Traversing
1879 sibling: function(elem, pos, not) {
1882 var siblings = elem.parentNode.childNodes;
1883 for ( var i = 0; i < siblings.length; i++ ) {
1884 if ( not === true && siblings[i] == elem ) continue;
1886 if ( siblings[i].nodeType == 1 )
1887 elems.push( siblings[i] );
1888 if ( siblings[i] == elem )
1889 elems.n = elems.length - 1;
1892 return jQuery.extend( elems, {
1893 last: elems.n == elems.length - 1,
1894 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1895 prev: elems[elems.n - 1],
1896 next: elems[elems.n + 1]
1901 * Merge two arrays together, removing all duplicates. The final order
1902 * or the new array is: All the results from the first array, followed
1903 * by the unique results from the second array.
1905 * @example $.merge( [0,1,2], [2,3,4] )
1906 * @result [0,1,2,3,4]
1908 * @example $.merge( [3,2,1], [4,3,2] )
1913 * @param Array first The first array to merge.
1914 * @param Array second The second array to merge.
1917 merge: function(first, second) {
1920 // Move b over to the new array (this helps to avoid
1921 // StaticNodeList instances)
1922 for ( var k = 0; k < first.length; k++ )
1923 result[k] = first[k];
1925 // Now check for duplicates between a and b and only
1926 // add the unique items
1927 for ( var i = 0; i < second.length; i++ ) {
1928 var noCollision = true;
1930 // The collision-checking process
1931 for ( var j = 0; j < first.length; j++ )
1932 if ( second[i] == first[j] )
1933 noCollision = false;
1935 // If the item is unique, add it
1937 result.push( second[i] );
1944 * Filter items out of an array, by using a filter function.
1945 * The specified function will be passed two arguments: The
1946 * current array item and the index of the item in the array. The
1947 * function should return 'true' if you wish to keep the item in
1948 * the array, false if it should be removed.
1950 * @example $.grep( [0,1,2], function(i){
1957 * @param Array array The Array to find items in.
1958 * @param Function fn The function to process each item against.
1959 * @param Boolean inv Invert the selection - select the opposite of the function.
1962 grep: function(elems, fn, inv) {
1963 // If a string is passed in for the function, make a function
1964 // for it (a handy shortcut)
1965 if ( fn.constructor == String )
1966 fn = new Function("a","i","return " + fn);
1970 // Go through the array, only saving the items
1971 // that pass the validator function
1972 for ( var i = 0; i < elems.length; i++ )
1973 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1974 result.push( elems[i] );
1980 * Translate all items in an array to another array of items.
1981 * The translation function that is provided to this method is
1982 * called for each item in the array and is passed one argument:
1983 * The item to be translated. The function can then return:
1984 * The translated value, 'null' (to remove the item), or
1985 * an array of values - which will be flattened into the full array.
1987 * @example $.map( [0,1,2], function(i){
1992 * @example $.map( [0,1,2], function(i){
1993 * return i > 0 ? i + 1 : null;
1997 * @example $.map( [0,1,2], function(i){
1998 * return [ i, i + 1 ];
2000 * @result [0, 1, 1, 2, 2, 3]
2004 * @param Array array The Array to translate.
2005 * @param Function fn The function to process each item against.
2008 map: function(elems, fn) {
2009 // If a string is passed in for the function, make a function
2010 // for it (a handy shortcut)
2011 if ( fn.constructor == String )
2012 fn = new Function("a","return " + fn);
2016 // Go through the array, translating each of the items to their
2017 // new value (or values).
2018 for ( var i = 0; i < elems.length; i++ ) {
2019 var val = fn(elems[i],i);
2021 if ( val !== null && val != undefined ) {
2022 if ( val.constructor != Array ) val = [val];
2023 result = jQuery.merge( result, val );
2031 * A number of helper functions used for managing events.
2032 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2036 // Bind an event to an element
2037 // Original by Dean Edwards
2038 add: function(element, type, handler) {
2039 // For whatever reason, IE has trouble passing the window object
2040 // around, causing it to be cloned in the process
2041 if ( jQuery.browser.msie && element.setInterval != undefined )
2044 // Make sure that the function being executed has a unique ID
2045 if ( !handler.guid )
2046 handler.guid = this.guid++;
2048 // Init the element's event structure
2049 if (!element.events)
2050 element.events = {};
2052 // Get the current list of functions bound to this event
2053 var handlers = element.events[type];
2055 // If it hasn't been initialized yet
2057 // Init the event handler queue
2058 handlers = element.events[type] = {};
2060 // Remember an existing handler, if it's already there
2061 if (element["on" + type])
2062 handlers[0] = element["on" + type];
2065 // Add the function to the element's handler list
2066 handlers[handler.guid] = handler;
2068 // And bind the global event handler to the element
2069 element["on" + type] = this.handle;
2071 // Remember the function in a global list (for triggering)
2072 if (!this.global[type])
2073 this.global[type] = [];
2074 this.global[type].push( element );
2080 // Detach an event or set of events from an element
2081 remove: function(element, type, handler) {
2083 if (type && element.events[type])
2085 delete element.events[type][handler.guid];
2087 for ( var i in element.events[type] )
2088 delete element.events[type][i];
2090 for ( var j in element.events )
2091 this.remove( element, j );
2094 trigger: function(type,data,element) {
2095 // Touch up the incoming data
2098 // Handle a global trigger
2100 var g = this.global[type];
2102 for ( var i = 0; i < g.length; i++ )
2103 this.trigger( type, data, g[i] );
2105 // Handle triggering a single element
2106 } else if ( element["on" + type] ) {
2107 // Pass along a fake event
2108 data.unshift( this.fix({ type: type, target: element }) );
2110 // Trigger the event
2111 element["on" + type].apply( element, data );
2115 handle: function(event) {
2116 if ( typeof jQuery == "undefined" ) return;
2118 event = event || jQuery.event.fix( window.event );
2120 // If no correct event was found, fail
2121 if ( !event ) return;
2123 var returnValue = true;
2125 var c = this.events[event.type];
2127 for ( var j in c ) {
2128 if ( c[j].apply( this, [event] ) === false ) {
2129 event.preventDefault();
2130 event.stopPropagation();
2131 returnValue = false;
2138 fix: function(event) {
2140 event.preventDefault = function() {
2141 this.returnValue = false;
2144 event.stopPropagation = function() {
2145 this.cancelBubble = true;
2156 var b = navigator.userAgent.toLowerCase();
2158 // Figure out what browser is being used
2160 safari: /webkit/.test(b),
2161 opera: /opera/.test(b),
2162 msie: /msie/.test(b) && !/opera/.test(b),
2163 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2166 // Check to see if the W3C box model is being used
2167 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2173 * Append all of the matched elements to another, specified, set of elements.
2174 * This operation is, essentially, the reverse of doing a regular
2175 * $(A).append(B), in that instead of appending B to A, you're appending
2178 * @example $("p").appendTo("#foo");
2179 * @before <p>I would like to say: </p><div id="foo"></div>
2180 * @result <div id="foo"><p>I would like to say: </p></div>
2184 * @param String expr A jQuery expression of elements to match.
2185 * @cat DOM/Manipulation
2190 * Prepend all of the matched elements to another, specified, set of elements.
2191 * This operation is, essentially, the reverse of doing a regular
2192 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2195 * @example $("p").prependTo("#foo");
2196 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2197 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2201 * @param String expr A jQuery expression of elements to match.
2202 * @cat DOM/Manipulation
2204 prependTo: "prepend",
2207 * Insert all of the matched elements before another, specified, set of elements.
2208 * This operation is, essentially, the reverse of doing a regular
2209 * $(A).before(B), in that instead of inserting B before A, you're inserting
2212 * @example $("p").insertBefore("#foo");
2213 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2214 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2216 * @name insertBefore
2218 * @param String expr A jQuery expression of elements to match.
2219 * @cat DOM/Manipulation
2221 insertBefore: "before",
2224 * Insert all of the matched elements after another, specified, set of elements.
2225 * This operation is, essentially, the reverse of doing a regular
2226 * $(A).after(B), in that instead of inserting B after A, you're inserting
2229 * @example $("p").insertAfter("#foo");
2230 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2231 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2235 * @param String expr A jQuery expression of elements to match.
2236 * @cat DOM/Manipulation
2238 insertAfter: "after"
2242 * Get the current CSS width of the first matched element.
2244 * @example $("p").width();
2245 * @before <p>This is just a test.</p>
2254 * Set the CSS width of every matched element. Be sure to include
2255 * the "px" (or other unit of measurement) after the number that you
2256 * specify, otherwise you might get strange results.
2258 * @example $("p").width("20px");
2259 * @before <p>This is just a test.</p>
2260 * @result <p style="width:20px;">This is just a test.</p>
2264 * @param String val Set the CSS property to the specified value.
2269 * Get the current CSS height of the first matched element.
2271 * @example $("p").height();
2272 * @before <p>This is just a test.</p>
2281 * Set the CSS height of every matched element. Be sure to include
2282 * the "px" (or other unit of measurement) after the number that you
2283 * specify, otherwise you might get strange results.
2285 * @example $("p").height("20px");
2286 * @before <p>This is just a test.</p>
2287 * @result <p style="height:20px;">This is just a test.</p>
2291 * @param String val Set the CSS property to the specified value.
2296 * Get the current CSS top of the first matched element.
2298 * @example $("p").top();
2299 * @before <p>This is just a test.</p>
2308 * Set the CSS top of every matched element. Be sure to include
2309 * the "px" (or other unit of measurement) after the number that you
2310 * specify, otherwise you might get strange results.
2312 * @example $("p").top("20px");
2313 * @before <p>This is just a test.</p>
2314 * @result <p style="top:20px;">This is just a test.</p>
2318 * @param String val Set the CSS property to the specified value.
2323 * Get the current CSS left of the first matched element.
2325 * @example $("p").left();
2326 * @before <p>This is just a test.</p>
2335 * Set the CSS left of every matched element. Be sure to include
2336 * the "px" (or other unit of measurement) after the number that you
2337 * specify, otherwise you might get strange results.
2339 * @example $("p").left("20px");
2340 * @before <p>This is just a test.</p>
2341 * @result <p style="left:20px;">This is just a test.</p>
2345 * @param String val Set the CSS property to the specified value.
2350 * Get the current CSS position of the first matched element.
2352 * @example $("p").position();
2353 * @before <p>This is just a test.</p>
2362 * Set the CSS position of every matched element.
2364 * @example $("p").position("relative");
2365 * @before <p>This is just a test.</p>
2366 * @result <p style="position:relative;">This is just a test.</p>
2370 * @param String val Set the CSS property to the specified value.
2375 * Get the current CSS float of the first matched element.
2377 * @example $("p").float();
2378 * @before <p>This is just a test.</p>
2387 * Set the CSS float of every matched element.
2389 * @example $("p").float("left");
2390 * @before <p>This is just a test.</p>
2391 * @result <p style="float:left;">This is just a test.</p>
2395 * @param String val Set the CSS property to the specified value.
2400 * Get the current CSS overflow of the first matched element.
2402 * @example $("p").overflow();
2403 * @before <p>This is just a test.</p>
2412 * Set the CSS overflow of every matched element.
2414 * @example $("p").overflow("auto");
2415 * @before <p>This is just a test.</p>
2416 * @result <p style="overflow:auto;">This is just a test.</p>
2420 * @param String val Set the CSS property to the specified value.
2425 * Get the current CSS color of the first matched element.
2427 * @example $("p").color();
2428 * @before <p>This is just a test.</p>
2437 * Set the CSS color of every matched element.
2439 * @example $("p").color("blue");
2440 * @before <p>This is just a test.</p>
2441 * @result <p style="color:blue;">This is just a test.</p>
2445 * @param String val Set the CSS property to the specified value.
2450 * Get the current CSS background of the first matched element.
2452 * @example $("p").background();
2453 * @before <p style="background:blue;">This is just a test.</p>
2462 * Set the CSS background of every matched element.
2464 * @example $("p").background("blue");
2465 * @before <p>This is just a test.</p>
2466 * @result <p style="background:blue;">This is just a test.</p>
2470 * @param String val Set the CSS property to the specified value.
2474 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2477 * Reduce the set of matched elements to a single element.
2478 * The position of the element in the set of matched elements
2479 * starts at 0 and goes to length - 1.
2481 * @example $("p").eq(1)
2482 * @before <p>This is just a test.</p><p>So is this</p>
2483 * @result [ <p>So is this</p> ]
2487 * @param Number pos The index of the element that you wish to limit to.
2492 * Reduce the set of matched elements to all elements before a given position.
2493 * The position of the element in the set of matched elements
2494 * starts at 0 and goes to length - 1.
2496 * @example $("p").lt(1)
2497 * @before <p>This is just a test.</p><p>So is this</p>
2498 * @result [ <p>This is just a test.</p> ]
2502 * @param Number pos Reduce the set to all elements below this position.
2507 * Reduce the set of matched elements to all elements after a given position.
2508 * The position of the element in the set of matched elements
2509 * starts at 0 and goes to length - 1.
2511 * @example $("p").gt(0)
2512 * @before <p>This is just a test.</p><p>So is this</p>
2513 * @result [ <p>So is this</p> ]
2517 * @param Number pos Reduce the set to all elements after this position.
2522 * Filter the set of elements to those that contain the specified text.
2524 * @example $("p").contains("test")
2525 * @before <p>This is just a test.</p><p>So is this</p>
2526 * @result [ <p>This is just a test.</p> ]
2530 * @param String str The string that will be contained within the text of an element.
2531 * @cat DOM/Traversing
2534 filter: [ "eq", "lt", "gt", "contains" ],
2538 * Get the current value of the first matched element.
2540 * @example $("input").val();
2541 * @before <input type="text" value="some text"/>
2542 * @result "some text"
2544 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2545 * @test ok( !$("#text1").val() == "", "Check for value of input element" );
2549 * @cat DOM/Attributes
2553 * Set the value of every matched element.
2555 * @example $("input").value("test");
2556 * @before <input type="text" value="some text"/>
2557 * @result <input type="text" value="test"/>
2559 * @test document.getElementById('text1').value = "bla";
2560 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2561 * $("#text1").val('test');
2562 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2566 * @param String val Set the property to the specified value.
2567 * @cat DOM/Attributes
2572 * Get the html contents of the first matched element.
2574 * @example $("div").html();
2575 * @before <div><input/></div>
2580 * @cat DOM/Attributes
2584 * Set the html contents of every matched element.
2586 * @example $("div").html("<b>new stuff</b>");
2587 * @before <div><input/></div>
2588 * @result <div><b>new stuff</b></div>
2590 * @test var div = $("div");
2591 * div.html("<b>test</b>");
2593 * for ( var i = 0; i < div.size(); i++ ) {
2594 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2596 * ok( pass, "Set HTML" );
2600 * @param String val Set the html contents to the specified value.
2601 * @cat DOM/Attributes
2606 * Get the current id of the first matched element.
2608 * @example $("input").id();
2609 * @before <input type="text" id="test" value="some text"/>
2614 * @cat DOM/Attributes
2618 * Set the id of every matched element.
2620 * @example $("input").id("newid");
2621 * @before <input type="text" id="test" value="some text"/>
2622 * @result <input type="text" id="newid" value="some text"/>
2626 * @param String val Set the property to the specified value.
2627 * @cat DOM/Attributes
2632 * Get the current title of the first matched element.
2634 * @example $("img").title();
2635 * @before <img src="test.jpg" title="my image"/>
2636 * @result "my image"
2640 * @cat DOM/Attributes
2644 * Set the title of every matched element.
2646 * @example $("img").title("new title");
2647 * @before <img src="test.jpg" title="my image"/>
2648 * @result <img src="test.jpg" title="new image"/>
2652 * @param String val Set the property to the specified value.
2653 * @cat DOM/Attributes
2658 * Get the current name of the first matched element.
2660 * @example $("input").name();
2661 * @before <input type="text" name="username"/>
2662 * @result "username"
2666 * @cat DOM/Attributes
2670 * Set the name of every matched element.
2672 * @example $("input").name("user");
2673 * @before <input type="text" name="username"/>
2674 * @result <input type="text" name="user"/>
2678 * @param String val Set the property to the specified value.
2679 * @cat DOM/Attributes
2684 * Get the current href of the first matched element.
2686 * @example $("a").href();
2687 * @before <a href="test.html">my link</a>
2688 * @result "test.html"
2692 * @cat DOM/Attributes
2696 * Set the href of every matched element.
2698 * @example $("a").href("test2.html");
2699 * @before <a href="test.html">my link</a>
2700 * @result <a href="test2.html">my link</a>
2704 * @param String val Set the property to the specified value.
2705 * @cat DOM/Attributes
2710 * Get the current src of the first matched element.
2712 * @example $("img").src();
2713 * @before <img src="test.jpg" title="my image"/>
2714 * @result "test.jpg"
2718 * @cat DOM/Attributes
2722 * Set the src of every matched element.
2724 * @example $("img").src("test2.jpg");
2725 * @before <img src="test.jpg" title="my image"/>
2726 * @result <img src="test2.jpg" title="my image"/>
2730 * @param String val Set the property to the specified value.
2731 * @cat DOM/Attributes
2736 * Get the current rel of the first matched element.
2738 * @example $("a").rel();
2739 * @before <a href="test.html" rel="nofollow">my link</a>
2740 * @result "nofollow"
2744 * @cat DOM/Attributes
2748 * Set the rel of every matched element.
2750 * @example $("a").rel("nofollow");
2751 * @before <a href="test.html">my link</a>
2752 * @result <a href="test.html" rel="nofollow">my link</a>
2756 * @param String val Set the property to the specified value.
2757 * @cat DOM/Attributes
2764 * Get a set of elements containing the unique parents of the matched
2767 * @example $("p").parent()
2768 * @before <div><p>Hello</p><p>Hello</p></div>
2769 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2773 * @cat DOM/Traversing
2777 * Get a set of elements containing the unique parents of the matched
2778 * set of elements, and filtered by an expression.
2780 * @example $("p").parent(".selected")
2781 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2782 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2786 * @param String expr An expression to filter the parents with
2787 * @cat DOM/Traversing
2789 parent: "a.parentNode",
2792 * Get a set of elements containing the unique ancestors of the matched
2793 * set of elements (except for the root element).
2795 * @example $("span").ancestors()
2796 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2797 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2801 * @cat DOM/Traversing
2805 * Get a set of elements containing the unique ancestors of the matched
2806 * set of elements, and filtered by an expression.
2808 * @example $("span").ancestors("p")
2809 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2810 * @result [ <p><span>Hello</span></p> ]
2814 * @param String expr An expression to filter the ancestors with
2815 * @cat DOM/Traversing
2817 ancestors: jQuery.parents,
2820 * Get a set of elements containing the unique ancestors of the matched
2821 * set of elements (except for the root element).
2823 * @example $("span").ancestors()
2824 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2825 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2829 * @cat DOM/Traversing
2833 * Get a set of elements containing the unique ancestors of the matched
2834 * set of elements, and filtered by an expression.
2836 * @example $("span").ancestors("p")
2837 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2838 * @result [ <p><span>Hello</span></p> ]
2842 * @param String expr An expression to filter the ancestors with
2843 * @cat DOM/Traversing
2845 parents: jQuery.parents,
2848 * Get a set of elements containing the unique next siblings of each of the
2849 * matched set of elements.
2851 * It only returns the very next sibling, not all next siblings.
2853 * @example $("p").next()
2854 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2855 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2859 * @cat DOM/Traversing
2863 * Get a set of elements containing the unique next siblings of each of the
2864 * matched set of elements, and filtered by an expression.
2866 * It only returns the very next sibling, not all next siblings.
2868 * @example $("p").next(".selected")
2869 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2870 * @result [ <p class="selected">Hello Again</p> ]
2874 * @param String expr An expression to filter the next Elements with
2875 * @cat DOM/Traversing
2877 next: "jQuery.sibling(a).next",
2880 * Get a set of elements containing the unique previous siblings of each of the
2881 * matched set of elements.
2883 * It only returns the immediately previous sibling, not all previous siblings.
2885 * @example $("p").previous()
2886 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2887 * @result [ <div><span>Hello Again</span></div> ]
2891 * @cat DOM/Traversing
2895 * Get a set of elements containing the unique previous siblings of each of the
2896 * matched set of elements, and filtered by an expression.
2898 * It only returns the immediately previous sibling, not all previous siblings.
2900 * @example $("p").previous(".selected")
2901 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2902 * @result [ <div><span>Hello</span></div> ]
2906 * @param String expr An expression to filter the previous Elements with
2907 * @cat DOM/Traversing
2909 prev: "jQuery.sibling(a).prev",
2912 * Get a set of elements containing all of the unique siblings of each of the
2913 * matched set of elements.
2915 * @example $("div").siblings()
2916 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2917 * @result [ <p>Hello</p>, <p>And Again</p> ]
2921 * @cat DOM/Traversing
2925 * Get a set of elements containing all of the unique siblings of each of the
2926 * matched set of elements, and filtered by an expression.
2928 * @example $("div").siblings(".selected")
2929 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2930 * @result [ <p class="selected">Hello Again</p> ]
2934 * @param String expr An expression to filter the sibling Elements with
2935 * @cat DOM/Traversing
2937 siblings: jQuery.sibling,
2941 * Get a set of elements containing all of the unique children of each of the
2942 * matched set of elements.
2944 * @example $("div").children()
2945 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2946 * @result [ <span>Hello Again</span> ]
2950 * @cat DOM/Traversing
2954 * Get a set of elements containing all of the unique children of each of the
2955 * matched set of elements, and filtered by an expression.
2957 * @example $("div").children(".selected")
2958 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2959 * @result [ <p class="selected">Hello Again</p> ]
2963 * @param String expr An expression to filter the child Elements with
2964 * @cat DOM/Traversing
2966 children: "jQuery.sibling(a.firstChild)"
2972 * Remove an attribute from each of the matched elements.
2974 * @example $("input").removeAttr("disabled")
2975 * @before <input disabled="disabled"/>
2980 * @param String name The name of the attribute to remove.
2983 removeAttr: function( key ) {
2984 this.removeAttribute( key );
2988 * Displays each of the set of matched elements if they are hidden.
2990 * @example $("p").show()
2991 * @before <p style="display: none">Hello</p>
2992 * @result [ <p style="display: block">Hello</p> ]
2994 * @test var pass = true, div = $("div");
2995 * div.show().each(function(){
2996 * if ( this.style.display == "none" ) pass = false;
2998 * ok( pass, "Show" );
3005 this.style.display = this.oldblock ? this.oldblock : "";
3006 if ( jQuery.css(this,"display") == "none" )
3007 this.style.display = "block";
3011 * Hides each of the set of matched elements if they are shown.
3013 * @example $("p").hide()
3014 * @before <p>Hello</p>
3015 * @result [ <p style="display: none">Hello</p> ]
3017 * var pass = true, div = $("div");
3018 * div.hide().each(function(){
3019 * if ( this.style.display != "none" ) pass = false;
3021 * ok( pass, "Hide" );
3028 this.oldblock = this.oldblock || jQuery.css(this,"display");
3029 if ( this.oldblock == "none" )
3030 this.oldblock = "block";
3031 this.style.display = "none";
3035 * Toggles each of the set of matched elements. If they are shown,
3036 * toggle makes them hidden. If they are hidden, toggle
3039 * @example $("p").toggle()
3040 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3041 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3048 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3052 * Adds the specified class to each of the set of matched elements.
3054 * @example $("p").addClass("selected")
3055 * @before <p>Hello</p>
3056 * @result [ <p class="selected">Hello</p> ]
3058 * @test var div = $("div");
3059 * div.addClass("test");
3061 * for ( var i = 0; i < div.size(); i++ ) {
3062 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3064 * ok( pass, "Add Class" );
3068 * @param String class A CSS class to add to the elements
3071 addClass: function(c){
3072 jQuery.className.add(this,c);
3076 * Removes the specified class from the set of matched elements.
3078 * @example $("p").removeClass("selected")
3079 * @before <p class="selected">Hello</p>
3080 * @result [ <p>Hello</p> ]
3082 * @test var div = $("div").addClass("test");
3083 * div.removeClass("test");
3085 * for ( var i = 0; i < div.size(); i++ ) {
3086 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3088 * ok( pass, "Remove Class" );
3092 * @param String class A CSS class to remove from the elements
3095 removeClass: function(c){
3096 jQuery.className.remove(this,c);
3100 * Adds the specified class if it is present, removes it if it is
3103 * @example $("p").toggleClass("selected")
3104 * @before <p>Hello</p><p class="selected">Hello Again</p>
3105 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3109 * @param String class A CSS class with which to toggle the elements
3112 toggleClass: function( c ){
3113 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3117 * Removes all matched elements from the DOM. This does NOT remove them from the
3118 * jQuery object, allowing you to use the matched elements further.
3120 * @example $("p").remove();
3121 * @before <p>Hello</p> how are <p>you?</p>
3126 * @cat DOM/Manipulation
3130 * Removes only elements (out of the list of matched elements) that match
3131 * the specified jQuery expression. This does NOT remove them from the
3132 * jQuery object, allowing you to use the matched elements further.
3134 * @example $("p").remove(".hello");
3135 * @before <p class="hello">Hello</p> how are <p>you?</p>
3136 * @result how are <p>you?</p>
3140 * @param String expr A jQuery expression to filter elements by.
3141 * @cat DOM/Manipulation
3143 remove: function(a){
3144 if ( !a || jQuery.filter( a, [this] ).r )
3145 this.parentNode.removeChild( this );
3149 * Removes all child nodes from the set of matched elements.
3151 * @example $("p").empty()
3152 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3153 * @result [ <p></p> ]
3157 * @cat DOM/Manipulation
3160 while ( this.firstChild )
3161 this.removeChild( this.firstChild );
3165 * Binds a handler to a particular event (like click) for each matched element.
3166 * The event handler is passed an event object that you can use to prevent
3167 * default behaviour. To stop both default action and event bubbling, your handler
3168 * has to return false.
3170 * @example $("p").bind( "click", function() {
3171 * alert( $(this).text() );
3173 * @before <p>Hello</p>
3174 * @result alert("Hello")
3176 * @example $("form").bind( "submit", function() { return false; } )
3177 * @desc Cancel a default action and prevent it from bubbling by returning false
3178 * from your function.
3180 * @example $("form").bind( "submit", function(event) {
3181 * event.preventDefault();
3183 * @desc Cancel only the default action by using the preventDefault method.
3186 * @example $("form").bind( "submit", function(event) {
3187 * event.stopPropagation();
3189 * @desc Stop only an event from bubbling by using the stopPropagation method.
3193 * @param String type An event type
3194 * @param Function fn A function to bind to the event on each of the set of matched elements
3197 bind: function( type, fn ) {
3198 if ( fn.constructor == String )
3199 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3200 jQuery.event.add( this, type, fn );
3204 * The opposite of bind, removes a bound event from each of the matched
3205 * elements. You must pass the identical function that was used in the original
3208 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3209 * @before <p onclick="alert('Hello');">Hello</p>
3210 * @result [ <p>Hello</p> ]
3214 * @param String type An event type
3215 * @param Function fn A function to unbind from the event on each of the set of matched elements
3220 * Removes all bound events of a particular type from each of the matched
3223 * @example $("p").unbind( "click" )
3224 * @before <p onclick="alert('Hello');">Hello</p>
3225 * @result [ <p>Hello</p> ]
3229 * @param String type An event type
3234 * Removes all bound events from each of the matched elements.
3236 * @example $("p").unbind()
3237 * @before <p onclick="alert('Hello');">Hello</p>
3238 * @result [ <p>Hello</p> ]
3244 unbind: function( type, fn ) {
3245 jQuery.event.remove( this, type, fn );
3249 * Trigger a type of event on every matched element.
3251 * @example $("p").trigger("click")
3252 * @before <p click="alert('hello')">Hello</p>
3253 * @result alert('hello')
3257 * @param String type An event type to trigger.
3260 trigger: function( type, data ) {
3261 jQuery.event.trigger( type, data, this );