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' );
441 * @param String key The name of the property to set.
442 * @param Object value The value to set the property to.
445 attr: function( key, value, type ) {
446 // Check to see if we're setting style values
447 return key.constructor != String || value != undefined ?
448 this.each(function(){
449 // See if we're setting a hash of styles
450 if ( value == undefined )
451 // Set all the styles
452 for ( var prop in key )
454 type ? this.style : this,
458 // See if we're setting a single key/value style
461 type ? this.style : this,
466 // Look for the case where we're accessing a style value
467 jQuery[ type || "attr" ]( this[0], key );
471 * Access a style property on the first matched element.
472 * This method makes it easy to retrieve a style property value
473 * from the first matched element.
475 * @example $("p").css("color");
476 * @before <p style="color:red;">Test Paragraph.</p>
478 * @desc Retrieves the color style of the first paragraph
480 * @example $("p").css("fontWeight");
481 * @before <p style="font-weight: bold;">Test Paragraph.</p>
483 * @desc Retrieves the font-weight style of the first paragraph.
484 * Note that for all style properties with a dash (like 'font-weight'), you have to
485 * write it in camelCase. In other words: Every time you have a '-' in a
486 * property, remove it and replace the next character with an uppercase
487 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
488 * borderStyle, borderBottomWidth etc.
490 * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
494 * @param String name The name of the property to access.
499 * Set a hash of key/value style properties to all matched elements.
500 * This serves as the best way to set a large number of style properties
501 * on all matched elements.
503 * @example $("p").css({ color: "red", background: "blue" });
504 * @before <p>Test Paragraph.</p>
505 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
507 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
508 * @test $('#foo').css({display: 'none'});
509 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
510 * @test $('#foo').css({display: 'block'});
511 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
515 * @param Hash prop A set of key/value pairs to set as style properties.
520 * Set a single style property to a value, on all matched elements.
522 * @example $("p").css("color","red");
523 * @before <p>Test Paragraph.</p>
524 * @result <p style="color:red;">Test Paragraph.</p>
525 * @desc Changes the color of all paragraphs to red
528 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
529 * @test $('#foo').css('display', 'none');
530 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
531 * @test $('#foo').css('display', 'block');
532 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
536 * @param String key The name of the property to set.
537 * @param Object value The value to set the property to.
540 css: function( key, value ) {
541 return this.attr( key, value, "curCSS" );
545 * Retrieve the text contents of all matched elements. The result is
546 * a string that contains the combined text contents of all matched
547 * elements. This method works on both HTML and XML documents.
549 * @example $("p").text();
550 * @before <p>Test Paragraph.</p>
551 * @result Test Paragraph.
553 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
554 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
563 for ( var j = 0; j < e.length; j++ ) {
564 var r = e[j].childNodes;
565 for ( var i = 0; i < r.length; i++ )
566 if ( r[i].nodeType != 8 )
567 t += r[i].nodeType != 1 ?
568 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
574 * Wrap all matched elements with a structure of other elements.
575 * This wrapping process is most useful for injecting additional
576 * stucture into a document, without ruining the original semantic
577 * qualities of a document.
579 * This works by going through the first element
580 * provided (which is generated, on the fly, from the provided HTML)
581 * and finds the deepest ancestor element within its
582 * structure - it is that element that will en-wrap everything else.
584 * @example $("p").wrap("<div class='wrap'></div>");
585 * @before <p>Test Paragraph.</p>
586 * @result <div class='wrap'><p>Test Paragraph.</p></div>
588 * @test var defaultText = 'Try them out:'
589 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
590 * ok( defaultText == result, 'Check for simple wrapping' );
591 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
593 * @test var defaultText = 'Try them out:'
594 * var result = $('#first').wrap('<div class="red">xx<span></span>yy</div>').text()
595 * ok( 'xx' + defaultText + 'yy' == result, 'Check for wrapping' );
596 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
600 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
601 * @cat DOM/Manipulation
605 * Wrap all matched elements with a structure of other elements.
606 * This wrapping process is most useful for injecting additional
607 * stucture into a document, without ruining the original semantic
608 * qualities of a document.
610 * This works by going through the first element
611 * provided and finding the deepest ancestor element within its
612 * structure - it is that element that will en-wrap everything else.
614 * @example $("p").wrap("<div class='wrap'></div>");
615 * @before <p>Test Paragraph.</p>
616 * @result <div class='wrap'><p>Test Paragraph.</p></div>
620 * @param Element elem A DOM element that will be wrapped.
621 * @cat DOM/Manipulation
624 // The elements to wrap the target around
625 var a = jQuery.clean(arguments);
627 // Wrap each of the matched elements individually
628 return this.each(function(){
629 // Clone the structure that we're using to wrap
630 var b = a[0].cloneNode(true);
632 // Insert it before the element to be wrapped
633 this.parentNode.insertBefore( b, this );
635 // Find he deepest point in the wrap structure
636 while ( b.firstChild )
639 // Move the matched element to within the wrap structure
640 b.appendChild( this );
645 * Append any number of elements to the inside of every matched elements,
646 * generated from the provided HTML.
647 * This operation is similar to doing an appendChild to all the
648 * specified elements, adding them into the document.
650 * @example $("p").append("<b>Hello</b>");
651 * @before <p>I would like to say: </p>
652 * @result <p>I would like to say: <b>Hello</b></p>
654 * @test var defaultText = 'Try them out:'
655 * var result = $('#first').append('<b>buga</b>');
656 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
660 * @param String html A string of HTML, that will be created on the fly and appended to the target.
661 * @cat DOM/Manipulation
665 * Append an element to the inside of all matched elements.
666 * This operation is similar to doing an appendChild to all the
667 * specified elements, adding them into the document.
669 * @example $("p").append( $("#foo")[0] );
670 * @before <p>I would like to say: </p><b id="foo">Hello</b>
671 * @result <p>I would like to say: <b id="foo">Hello</b></p>
673 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
674 * $('#sap').append(document.getElementById('first'));
675 * ok( expected == $('#sap').text(), "Check for appending of element" );
679 * @param Element elem A DOM element that will be appended.
680 * @cat DOM/Manipulation
684 * Append any number of elements to the inside of all matched elements.
685 * This operation is similar to doing an appendChild to all the
686 * specified elements, adding them into the document.
688 * @example $("p").append( $("b") );
689 * @before <p>I would like to say: </p><b>Hello</b>
690 * @result <p>I would like to say: <b>Hello</b></p>
692 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
693 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
694 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
698 * @param Array<Element> elems An array of elements, all of which will be appended.
699 * @cat DOM/Manipulation
702 return this.domManip(arguments, true, 1, function(a){
703 this.appendChild( a );
708 * Prepend any number of elements to the inside of every matched elements,
709 * generated from the provided HTML.
710 * This operation is the best way to insert dynamically created elements
711 * inside, at the beginning, of all the matched element.
713 * @example $("p").prepend("<b>Hello</b>");
714 * @before <p>I would like to say: </p>
715 * @result <p><b>Hello</b>I would like to say: </p>
717 * @test var defaultText = 'Try them out:'
718 * var result = $('#first').prepend('<b>buga</b>');
719 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
723 * @param String html A string of HTML, that will be created on the fly and appended to the target.
724 * @cat DOM/Manipulation
728 * Prepend an element to the inside of all matched elements.
729 * This operation is the best way to insert an element inside, at the
730 * beginning, of all the matched element.
732 * @example $("p").prepend( $("#foo")[0] );
733 * @before <p>I would like to say: </p><b id="foo">Hello</b>
734 * @result <p><b id="foo">Hello</b>I would like to say: </p>
736 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
737 * $('#sap').prepend(document.getElementById('first'));
738 * ok( expected == $('#sap').text(), "Check for prepending of element" );
742 * @param Element elem A DOM element that will be appended.
743 * @cat DOM/Manipulation
747 * Prepend any number of elements to the inside of all matched elements.
748 * This operation is the best way to insert a set of elements inside, at the
749 * beginning, of all the matched element.
751 * @example $("p").prepend( $("b") );
752 * @before <p>I would like to say: </p><b>Hello</b>
753 * @result <p><b>Hello</b>I would like to say: </p>
755 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
756 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
757 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
761 * @param Array<Element> elems An array of elements, all of which will be appended.
762 * @cat DOM/Manipulation
764 prepend: function() {
765 return this.domManip(arguments, true, -1, function(a){
766 this.insertBefore( a, this.firstChild );
771 * Insert any number of dynamically generated elements before each of the
774 * @example $("p").before("<b>Hello</b>");
775 * @before <p>I would like to say: </p>
776 * @result <b>Hello</b><p>I would like to say: </p>
778 * @test var expected = 'This is a normal link: bugaYahoo';
779 * $('#yahoo').before('<b>buga</b>');
780 * ok( expected == $('#en').text(), 'Insert String before' );
784 * @param String html A string of HTML, that will be created on the fly and appended to the target.
785 * @cat DOM/Manipulation
789 * Insert an element before each of the matched elements.
791 * @example $("p").before( $("#foo")[0] );
792 * @before <p>I would like to say: </p><b id="foo">Hello</b>
793 * @result <b id="foo">Hello</b><p>I would like to say: </p>
795 * @test var expected = "This is a normal link: Try them out:Yahoo";
796 * $('#yahoo').before(document.getElementById('first'));
797 * ok( expected == $('#en').text(), "Insert element before" );
801 * @param Element elem A DOM element that will be appended.
802 * @cat DOM/Manipulation
806 * Insert any number of elements before each of the matched elements.
808 * @example $("p").before( $("b") );
809 * @before <p>I would like to say: </p><b>Hello</b>
810 * @result <b>Hello</b><p>I would like to say: </p>
812 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
813 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
814 * ok( expected == $('#en').text(), "Insert array of elements before" );
818 * @param Array<Element> elems An array of elements, all of which will be appended.
819 * @cat DOM/Manipulation
822 return this.domManip(arguments, false, 1, function(a){
823 this.parentNode.insertBefore( a, this );
828 * Insert any number of dynamically generated elements after each of the
831 * @example $("p").after("<b>Hello</b>");
832 * @before <p>I would like to say: </p>
833 * @result <p>I would like to say: </p><b>Hello</b>
835 * @test var expected = 'This is a normal link: Yahoobuga';
836 * $('#yahoo').after('<b>buga</b>');
837 * ok( expected == $('#en').text(), 'Insert String after' );
841 * @param String html A string of HTML, that will be created on the fly and appended to the target.
842 * @cat DOM/Manipulation
846 * Insert an element after each of the matched elements.
848 * @example $("p").after( $("#foo")[0] );
849 * @before <b id="foo">Hello</b><p>I would like to say: </p>
850 * @result <p>I would like to say: </p><b id="foo">Hello</b>
852 * @test var expected = "This is a normal link: YahooTry them out:";
853 * $('#yahoo').after(document.getElementById('first'));
854 * ok( expected == $('#en').text(), "Insert element after" );
858 * @param Element elem A DOM element that will be appended.
859 * @cat DOM/Manipulation
863 * Insert any number of elements after each of the matched elements.
865 * @example $("p").after( $("b") );
866 * @before <b>Hello</b><p>I would like to say: </p>
867 * @result <p>I would like to say: </p><b>Hello</b>
869 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
870 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
871 * ok( expected == $('#en').text(), "Insert array of elements after" );
875 * @param Array<Element> elems An array of elements, all of which will be appended.
876 * @cat DOM/Manipulation
879 return this.domManip(arguments, false, -1, function(a){
880 this.parentNode.insertBefore( a, this.nextSibling );
885 * End the most recent 'destructive' operation, reverting the list of matched elements
886 * back to its previous state. After an end operation, the list of matched elements will
887 * revert to the last state of matched elements.
889 * @example $("p").find("span").end();
890 * @before <p><span>Hello</span>, how are you?</p>
891 * @result $("p").find("span").end() == [ <p>...</p> ]
893 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
897 * @cat DOM/Traversing
900 return this.get( this.stack.pop() );
904 * Searches for all elements that match the specified expression.
905 * This method is the optimal way of finding additional descendant
906 * elements with which to process.
908 * All searching is done using a jQuery expression. The expression can be
909 * written using CSS 1-3 Selector syntax, or basic XPath.
911 * @example $("p").find("span");
912 * @before <p><span>Hello</span>, how are you?</p>
913 * @result $("p").find("span") == [ <span>Hello</span> ]
915 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
919 * @param String expr An expression to search with.
920 * @cat DOM/Traversing
923 return this.pushStack( jQuery.map( this, function(a){
924 return jQuery.find(t,a);
929 * Create cloned copies of all matched DOM Elements. This does
930 * not create a cloned copy of this particular jQuery object,
931 * instead it creates duplicate copies of all DOM Elements.
932 * This is useful for moving copies of the elements to another
933 * location in the DOM.
935 * @example $("b").clone().prependTo("p");
936 * @before <b>Hello</b><p>, how are you?</p>
937 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
939 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
940 * var clone = $('#yahoo').clone();
941 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
942 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
946 * @cat DOM/Manipulation
948 clone: function(deep) {
949 return this.pushStack( jQuery.map( this, function(a){
950 return a.cloneNode( deep != undefined ? deep : true );
955 * Removes all elements from the set of matched elements that do not
956 * match the specified expression. This method is used to narrow down
957 * the results of a search.
959 * All searching is done using a jQuery expression. The expression
960 * can be written using CSS 1-3 Selector syntax, or basic XPath.
962 * @example $("p").filter(".selected")
963 * @before <p class="selected">Hello</p><p>How are you?</p>
964 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
966 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
970 * @param String expr An expression to search with.
971 * @cat DOM/Traversing
975 * Removes all elements from the set of matched elements that do not
976 * match at least one of the expressions passed to the function. This
977 * method is used when you want to filter the set of matched elements
978 * through more than one expression.
980 * Elements will be retained in the jQuery object if they match at
981 * least one of the expressions passed.
983 * @example $("p").filter([".selected", ":first"])
984 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
985 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
989 * @param Array<String> exprs A set of expressions to evaluate against
990 * @cat DOM/Traversing
992 filter: function(t) {
993 return this.pushStack(
994 t.constructor == Array &&
995 jQuery.map(this,function(a){
996 for ( var i = 0; i < t.length; i++ )
997 if ( jQuery.filter(t[i],[a]).r.length )
1001 t.constructor == Boolean &&
1002 ( t ? this.get() : [] ) ||
1004 t.constructor == Function &&
1005 jQuery.grep( this, t ) ||
1007 jQuery.filter(t,this).r, arguments );
1011 * Removes the specified Element from the set of matched elements. This
1012 * method is used to remove a single Element from a jQuery object.
1014 * @example $("p").not( document.getElementById("selected") )
1015 * @before <p>Hello</p><p id="selected">Hello Again</p>
1016 * @result [ <p>Hello</p> ]
1020 * @param Element el An element to remove from the set
1021 * @cat DOM/Traversing
1025 * Removes elements matching the specified expression from the set
1026 * of matched elements. This method is used to remove one or more
1027 * elements from a jQuery object.
1029 * @example $("p").not("#selected")
1030 * @before <p>Hello</p><p id="selected">Hello Again</p>
1031 * @result [ <p>Hello</p> ]
1032 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
1036 * @param String expr An expression with which to remove matching elements
1037 * @cat DOM/Traversing
1040 return this.pushStack( t.constructor == String ?
1041 jQuery.filter(t,this,false).r :
1042 jQuery.grep(this,function(a){ return a != t; }), arguments );
1046 * Adds the elements matched by the expression to the jQuery object. This
1047 * can be used to concatenate the result sets of two expressions.
1049 * @example $("p").add("span")
1050 * @before <p>Hello</p><p><span>Hello Again</span></p>
1051 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1055 * @param String expr An expression whose matched elements are added
1056 * @cat DOM/Traversing
1060 * Adds each of the Elements in the array to the set of matched elements.
1061 * This is used to add a set of Elements to a jQuery object.
1063 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1064 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1065 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1069 * @param Array<Element> els An array of Elements to add
1070 * @cat DOM/Traversing
1074 * Adds a single Element to the set of matched elements. This is used to
1075 * add a single Element to a jQuery object.
1077 * @example $("p").add( document.getElementById("a") )
1078 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1079 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1083 * @param Element el An Element to add
1084 * @cat DOM/Traversing
1087 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1088 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1092 * Checks the current selection against an expression and returns true,
1093 * if the selection fits the given expression. Does return false, if the
1094 * selection does not fit or the expression is not valid.
1096 * @example $("input[@type='checkbox']").parent().is("form")
1097 * @before <form><input type="checkbox" /></form>
1099 * @desc Returns true, because the parent of the input is a form element
1101 * @example $("input[@type='checkbox']").parent().is("form")
1102 * @before <form><p><input type="checkbox" /></p></form>
1104 * @desc Returns false, because the parent of the input is a p element
1106 * @example $("form").is(null)
1107 * @before <form></form>
1109 * @desc An invalid expression always returns false.
1111 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1112 * @test ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1113 * @test ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1114 * @test ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1115 * @test ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1116 * @test ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1117 * @test ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1118 * @test ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1119 * @test ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1120 * @test ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1121 * @test ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1122 * @test ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1123 * @test ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1124 * @test ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1125 * @test ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1126 * @test ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1127 * @test ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1128 * @test ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1129 * @test ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1130 * @test ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1131 * @test ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1132 * @test ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1136 * @param String expr The expression with which to filter
1137 * @cat DOM/Traversing
1139 is: function(expr) {
1140 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1149 * @param Boolean table
1151 * @param Function fn The function doing the DOM manipulation.
1155 domManip: function(args, table, dir, fn){
1156 var clone = this.size() > 1;
1157 var a = jQuery.clean(args);
1159 return this.each(function(){
1162 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
1163 var tbody = this.getElementsByTagName("tbody");
1165 if ( !tbody.length ) {
1166 obj = document.createElement("tbody");
1167 this.appendChild( obj );
1172 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1173 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1174 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1189 pushStack: function(a,args) {
1190 var fn = args && args[args.length-1];
1192 if ( !fn || fn.constructor != Function ) {
1193 if ( !this.stack ) this.stack = [];
1194 this.stack.push( this.get() );
1197 var old = this.get();
1199 if ( fn.constructor == Function )
1219 * Extend one object with another, returning the original,
1220 * modified, object. This is a great utility for simple inheritance.
1222 * @example var settings = { validate: false, limit: 5, name: "foo" };
1223 * var options = { validate: true, name: "bar" };
1224 * jQuery.extend(settings, options);
1225 * @result settings == { validate: true, limit: 5, name: "bar" }
1227 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1228 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1229 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1230 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1231 * jQuery.extend(settings, options);
1232 * isSet( settings, merged, "Check if extended: settings must be extended" );
1233 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1236 * @param Object obj The object to extend
1237 * @param Object prop The object that will be merged into the first.
1241 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1242 if ( !prop ) { prop = obj; obj = this; }
1243 for ( var i in prop ) obj[i] = prop[i];
1255 jQuery.initDone = true;
1257 jQuery.each( jQuery.macros.axis, function(i,n){
1258 jQuery.fn[ i ] = function(a) {
1259 var ret = jQuery.map(this,n);
1260 if ( a && a.constructor == String )
1261 ret = jQuery.filter(a,ret).r;
1262 return this.pushStack( ret, arguments );
1266 jQuery.each( jQuery.macros.to, function(i,n){
1267 jQuery.fn[ i ] = function(){
1269 return this.each(function(){
1270 for ( var j = 0; j < a.length; j++ )
1271 jQuery(a[j])[n]( this );
1276 jQuery.each( jQuery.macros.each, function(i,n){
1277 jQuery.fn[ i ] = function() {
1278 return this.each( n, arguments );
1282 jQuery.each( jQuery.macros.filter, function(i,n){
1283 jQuery.fn[ n ] = function(num,fn) {
1284 return this.filter( ":" + n + "(" + num + ")", fn );
1288 jQuery.each( jQuery.macros.attr, function(i,n){
1290 jQuery.fn[ i ] = function(h) {
1291 return h == undefined ?
1292 this.length ? this[0][n] : null :
1297 jQuery.each( jQuery.macros.css, function(i,n){
1298 jQuery.fn[ n ] = function(h) {
1299 return h == undefined ?
1300 ( this.length ? jQuery.css( this[0], n ) : null ) :
1308 * A generic iterator function, which can be used to seemlessly
1309 * iterate over both objects and arrays. This function is not the same
1310 * as $().each() - which is used to iterate, exclusively, over a jQuery
1311 * object. This function can be used to iterate over anything.
1313 * @example $.each( [0,1,2], function(i){
1314 * alert( "Item #" + i + ": " + this );
1316 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1318 * @example $.each( { name: "John", lang: "JS" }, function(i){
1319 * alert( "Name: " + i + ", Value: " + this );
1321 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1324 * @param Object obj The object, or array, to iterate over.
1325 * @param Function fn The function that will be executed on every object.
1329 each: function( obj, fn, args ) {
1330 if ( obj.length == undefined )
1331 for ( var i in obj )
1332 fn.apply( obj[i], args || [i, obj[i]] );
1334 for ( var i = 0; i < obj.length; i++ )
1335 fn.apply( obj[i], args || [i, obj[i]] );
1341 if (jQuery.className.has(o,c)) return;
1342 o.className += ( o.className ? " " : "" ) + c;
1344 remove: function(o,c){
1345 o.className = !c ? "" :
1346 o.className.replace(
1347 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
1349 has: function(e,a) {
1350 if ( e.className != undefined )
1352 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1357 * Swap in/out style options.
1360 swap: function(e,o,f) {
1361 for ( var i in o ) {
1362 e.style["old"+i] = e.style[i];
1367 e.style[i] = e.style["old"+i];
1370 css: function(e,p) {
1371 if ( p == "height" || p == "width" ) {
1372 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1374 for ( var i in d ) {
1375 old["padding" + d[i]] = 0;
1376 old["border" + d[i] + "Width"] = 0;
1379 jQuery.swap( e, old, function() {
1380 if (jQuery.css(e,"display") != "none") {
1381 oHeight = e.offsetHeight;
1382 oWidth = e.offsetWidth;
1384 e = jQuery(e.cloneNode(true)).css({
1385 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1386 }).appendTo(e.parentNode)[0];
1388 var parPos = jQuery.css(e.parentNode,"position");
1389 if ( parPos == "" || parPos == "static" )
1390 e.parentNode.style.position = "relative";
1392 oHeight = e.clientHeight;
1393 oWidth = e.clientWidth;
1395 if ( parPos == "" || parPos == "static" )
1396 e.parentNode.style.position = "static";
1398 e.parentNode.removeChild(e);
1402 return p == "height" ? oHeight : oWidth;
1403 } else if ( p == "opacity" && jQuery.browser.msie )
1404 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1406 return jQuery.curCSS( e, p );
1409 curCSS: function(elem, prop, force) {
1412 if (!force && elem.style[prop]) {
1414 ret = elem.style[prop];
1416 } else if (elem.currentStyle) {
1418 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1419 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1421 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1423 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1424 var cur = document.defaultView.getComputedStyle(elem, null);
1427 ret = cur.getPropertyValue(prop);
1428 else if ( prop == 'display' )
1431 jQuery.swap(elem, { display: 'block' }, function() {
1432 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1440 clean: function(a) {
1442 for ( var i = 0; i < a.length; i++ ) {
1443 if ( a[i].constructor == String ) {
1447 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1449 a[i] = "<table>" + a[i] + "</table>";
1450 } else if ( !a[i].indexOf("<tr") ) {
1452 a[i] = "<table>" + a[i] + "</table>";
1453 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1455 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1458 var div = document.createElement("div");
1459 div.innerHTML = a[i];
1462 div = div.firstChild;
1463 if ( table != "thead" ) div = div.firstChild;
1464 if ( table == "td" ) div = div.firstChild;
1467 for ( var j = 0; j < div.childNodes.length; j++ )
1468 r.push( div.childNodes[j] );
1469 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1470 for ( var k = 0; k < a[i].length; k++ )
1472 else if ( a[i] !== null )
1473 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1479 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1480 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1488 last: "i==r.length-1",
1493 "nth-child": "jQuery.sibling(a,m[3]).cur",
1494 "first-child": "jQuery.sibling(a,0).cur",
1495 "last-child": "jQuery.sibling(a,0).last",
1496 "only-child": "jQuery.sibling(a).length==1",
1499 parent: "a.childNodes.length",
1500 empty: "!a.childNodes.length",
1503 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1506 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1507 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1510 enabled: "!a.disabled",
1511 disabled: "a.disabled",
1512 checked: "a.checked",
1513 selected: "a.selected"
1515 ".": "jQuery.className.has(a,m[2])",
1519 "^=": "!z.indexOf(m[4])",
1520 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1521 "*=": "z.indexOf(m[4])>=0",
1524 "[": "jQuery.find(m[2],a).length"
1528 "\\.\\.|/\\.\\.", "a.parentNode",
1529 ">|/", "jQuery.sibling(a.firstChild)",
1530 "\\+", "jQuery.sibling(a).next",
1533 var s = jQuery.sibling(a);
1535 for ( var i = s.n; i < s.length; i++ )
1543 * @test t( "Element Selector", "div", ["main","foo"] );
1544 * @test t( "Element Selector", "body", ["body"] );
1545 * @test t( "Element Selector", "html", ["html"] );
1546 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1547 * @test t( "Parent Element", "div div", ["foo"] );
1549 * @test t( "ID Selector", "#body", ["body"] );
1550 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1551 * @test t( "ID Selector w/ Element", "ul#first", [] );
1553 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1554 * @test t( "Class Selector", ".blog.link", ["simon"] );
1555 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1556 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1558 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1559 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1560 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1561 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1563 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1564 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1565 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1566 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1567 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1568 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1569 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1570 * @test t( "Adjacent", "a + a", ["groups"] );
1571 * @test t( "Adjacent", "a +a", ["groups"] );
1572 * @test t( "Adjacent", "a+ a", ["groups"] );
1573 * @test t( "Adjacent", "a+a", ["groups"] );
1574 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1575 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1576 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1577 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1578 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1579 * @test t( "Attribute Exists", "[@title]", ["google"] );
1580 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1581 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1582 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1583 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1584 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1585 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1587 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1588 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1589 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1590 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1591 * @test t( "Last Child", "p:last-child", ["sap"] );
1592 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1593 * @test t( "Empty", "ul:empty", ["firstUL"] );
1594 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1595 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1596 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1597 * @test t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1598 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1599 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1600 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1601 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1603 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1604 * @test t( "All Div Elements", "//div", ["main","foo"] );
1605 * @test t( "Absolute Path", "/html/body", ["body"] );
1606 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1607 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1608 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1609 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1610 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1611 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1612 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1613 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1614 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1615 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1616 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1618 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1619 * @test t( "First Element", "p:first", ["firstp"] );
1620 * @test t( "Last Element", "p:last", ["first"] );
1621 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1622 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1623 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1624 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1625 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1626 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1627 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1628 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1631 * @type Array<Element>
1635 find: function( t, context ) {
1636 // Make sure that the context is a DOM Element
1637 if ( context && context.nodeType == undefined )
1640 // Set the correct context (if none is provided)
1641 context = context || jQuery.context || document;
1643 if ( t.constructor != String ) return [t];
1645 if ( !t.indexOf("//") ) {
1646 context = context.documentElement;
1647 t = t.substr(2,t.length);
1648 } else if ( !t.indexOf("/") ) {
1649 context = context.documentElement;
1650 t = t.substr(1,t.length);
1651 // FIX Assume the root element is right :(
1652 if ( t.indexOf("/") >= 1 )
1653 t = t.substr(t.indexOf("/"),t.length);
1656 var ret = [context];
1660 while ( t.length > 0 && last != t ) {
1664 t = jQuery.trim(t).replace( /^\/\//i, "" );
1666 var foundToken = false;
1668 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1669 if ( foundToken ) continue;
1671 var re = new RegExp("^(" + jQuery.token[i] + ")");
1675 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1676 t = jQuery.trim( t.replace( re, "" ) );
1681 if ( !foundToken ) {
1682 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1683 if ( ret[0] == context ) ret.shift();
1684 done = jQuery.merge( done, ret );
1685 r = ret = [context];
1686 t = " " + t.substr(1,t.length);
1688 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1689 var m = re2.exec(t);
1691 if ( m[1] == "#" ) {
1692 // Ummm, should make this work in all XML docs
1693 var oid = document.getElementById(m[2]);
1694 r = ret = oid ? [oid] : [];
1695 t = t.replace( re2, "" );
1697 if ( !m[2] || m[1] == "." ) m[2] = "*";
1699 for ( var i = 0; i < ret.length; i++ )
1700 r = jQuery.merge( r,
1702 jQuery.getAll(ret[i]) :
1703 ret[i].getElementsByTagName(m[2])
1711 var val = jQuery.filter(t,r);
1713 t = jQuery.trim(val.t);
1717 if ( ret && ret[0] == context ) ret.shift();
1718 done = jQuery.merge( done, ret );
1723 getAll: function(o,r) {
1725 var s = o.childNodes;
1726 for ( var i = 0; i < s.length; i++ )
1727 if ( s[i].nodeType == 1 ) {
1729 jQuery.getAll( s[i], r );
1734 attr: function(elem, name, value){
1737 "class": "className",
1738 "float": "cssFloat",
1739 innerHTML: "innerHTML",
1740 className: "className",
1742 disabled: "disabled",
1747 if ( value != undefined ) elem[fix[name]] = value;
1748 return elem[fix[name]];
1749 } else if ( elem.getAttribute != undefined ) {
1750 if ( value != undefined ) elem.setAttribute( name, value );
1751 return elem.getAttribute( name, 2 );
1753 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1754 if ( value != undefined ) elem[name] = value;
1759 // The regular expressions that power the parsing engine
1761 // Match: [@value='test'], [@foo]
1762 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1764 // Match: [div], [div p]
1767 // Match: :contains('foo')
1768 [ "(:)S\\(Q\\)", 0 ],
1770 // Match: :even, :last-chlid
1774 filter: function(t,r,not) {
1775 // Figure out if we're doing regular, or inverse, filtering
1776 var g = not !== false ? jQuery.grep :
1777 function(a,f) {return jQuery.grep(a,f,true);};
1779 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1781 var p = jQuery.parse;
1783 for ( var i = 0; i < p.length; i++ ) {
1784 var re = new RegExp( "^" + p[i][0]
1786 // Look for a string-like sequence
1787 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1789 // Look for something (optionally) enclosed with quotes
1790 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1792 var m = re.exec( t );
1795 // Re-organize the match
1797 m = ["", m[1], m[3], m[2], m[4]];
1799 // Remove what we just matched
1800 t = t.replace( re, "" );
1806 // :not() is a special case that can be optomized by
1807 // keeping it out of the expression list
1808 if ( m[1] == ":" && m[2] == "not" )
1809 r = jQuery.filter(m[3],r,false).r;
1811 // Otherwise, find the expression to execute
1813 var f = jQuery.expr[m[1]];
1814 if ( f.constructor != String )
1815 f = jQuery.expr[m[1]][m[2]];
1817 // Build a custom macro to enclose it
1818 eval("f = function(a,i){" +
1819 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1820 "return " + f + "}");
1822 // Execute it against the current filter
1827 // Return an array of filtered elements (r)
1828 // and the modified expression string (t)
1829 return { r: r, t: t };
1833 * Remove the whitespace from the beginning and end of a string.
1835 * @example $.trim(" hello, how are you? ");
1836 * @result "hello, how are you?"
1840 * @param String str The string to trim.
1844 return t.replace(/^\s+|\s+$/g, "");
1848 * All ancestors of a given element.
1852 * @type Array<Element>
1853 * @param Element elem The element to find the ancestors of.
1854 * @cat DOM/Traversing
1856 parents: function( elem ){
1858 var cur = elem.parentNode;
1859 while ( cur && cur != document ) {
1860 matched.push( cur );
1861 cur = cur.parentNode;
1867 * All elements on a specified axis.
1872 * @param Element elem The element to find all the siblings of (including itself).
1873 * @cat DOM/Traversing
1875 sibling: function(elem, pos, not) {
1878 var siblings = elem.parentNode.childNodes;
1879 for ( var i = 0; i < siblings.length; i++ ) {
1880 if ( not === true && siblings[i] == elem ) continue;
1882 if ( siblings[i].nodeType == 1 )
1883 elems.push( siblings[i] );
1884 if ( siblings[i] == elem )
1885 elems.n = elems.length - 1;
1888 return jQuery.extend( elems, {
1889 last: elems.n == elems.length - 1,
1890 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1891 prev: elems[elems.n - 1],
1892 next: elems[elems.n + 1]
1897 * Merge two arrays together, removing all duplicates. The final order
1898 * or the new array is: All the results from the first array, followed
1899 * by the unique results from the second array.
1901 * @example $.merge( [0,1,2], [2,3,4] )
1902 * @result [0,1,2,3,4]
1904 * @example $.merge( [3,2,1], [4,3,2] )
1909 * @param Array first The first array to merge.
1910 * @param Array second The second array to merge.
1913 merge: function(first, second) {
1916 // Move b over to the new array (this helps to avoid
1917 // StaticNodeList instances)
1918 for ( var k = 0; k < first.length; k++ )
1919 result[k] = first[k];
1921 // Now check for duplicates between a and b and only
1922 // add the unique items
1923 for ( var i = 0; i < second.length; i++ ) {
1924 var noCollision = true;
1926 // The collision-checking process
1927 for ( var j = 0; j < first.length; j++ )
1928 if ( second[i] == first[j] )
1929 noCollision = false;
1931 // If the item is unique, add it
1933 result.push( second[i] );
1940 * Filter items out of an array, by using a filter function.
1941 * The specified function will be passed two arguments: The
1942 * current array item and the index of the item in the array. The
1943 * function should return 'true' if you wish to keep the item in
1944 * the array, false if it should be removed.
1946 * @example $.grep( [0,1,2], function(i){
1953 * @param Array array The Array to find items in.
1954 * @param Function fn The function to process each item against.
1955 * @param Boolean inv Invert the selection - select the opposite of the function.
1958 grep: function(elems, fn, inv) {
1959 // If a string is passed in for the function, make a function
1960 // for it (a handy shortcut)
1961 if ( fn.constructor == String )
1962 fn = new Function("a","i","return " + fn);
1966 // Go through the array, only saving the items
1967 // that pass the validator function
1968 for ( var i = 0; i < elems.length; i++ )
1969 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1970 result.push( elems[i] );
1976 * Translate all items in an array to another array of items.
1977 * The translation function that is provided to this method is
1978 * called for each item in the array and is passed one argument:
1979 * The item to be translated. The function can then return:
1980 * The translated value, 'null' (to remove the item), or
1981 * an array of values - which will be flattened into the full array.
1983 * @example $.map( [0,1,2], function(i){
1988 * @example $.map( [0,1,2], function(i){
1989 * return i > 0 ? i + 1 : null;
1993 * @example $.map( [0,1,2], function(i){
1994 * return [ i, i + 1 ];
1996 * @result [0, 1, 1, 2, 2, 3]
2000 * @param Array array The Array to translate.
2001 * @param Function fn The function to process each item against.
2004 map: function(elems, fn) {
2005 // If a string is passed in for the function, make a function
2006 // for it (a handy shortcut)
2007 if ( fn.constructor == String )
2008 fn = new Function("a","return " + fn);
2012 // Go through the array, translating each of the items to their
2013 // new value (or values).
2014 for ( var i = 0; i < elems.length; i++ ) {
2015 var val = fn(elems[i],i);
2017 if ( val !== null && val != undefined ) {
2018 if ( val.constructor != Array ) val = [val];
2019 result = jQuery.merge( result, val );
2027 * A number of helper functions used for managing events.
2028 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2032 // Bind an event to an element
2033 // Original by Dean Edwards
2034 add: function(element, type, handler) {
2035 // For whatever reason, IE has trouble passing the window object
2036 // around, causing it to be cloned in the process
2037 if ( jQuery.browser.msie && element.setInterval != undefined )
2040 // Make sure that the function being executed has a unique ID
2041 if ( !handler.guid )
2042 handler.guid = this.guid++;
2044 // Init the element's event structure
2045 if (!element.events)
2046 element.events = {};
2048 // Get the current list of functions bound to this event
2049 var handlers = element.events[type];
2051 // If it hasn't been initialized yet
2053 // Init the event handler queue
2054 handlers = element.events[type] = {};
2056 // Remember an existing handler, if it's already there
2057 if (element["on" + type])
2058 handlers[0] = element["on" + type];
2061 // Add the function to the element's handler list
2062 handlers[handler.guid] = handler;
2064 // And bind the global event handler to the element
2065 element["on" + type] = this.handle;
2067 // Remember the function in a global list (for triggering)
2068 if (!this.global[type])
2069 this.global[type] = [];
2070 this.global[type].push( element );
2076 // Detach an event or set of events from an element
2077 remove: function(element, type, handler) {
2079 if (type && element.events[type])
2081 delete element.events[type][handler.guid];
2083 for ( var i in element.events[type] )
2084 delete element.events[type][i];
2086 for ( var j in element.events )
2087 this.remove( element, j );
2090 trigger: function(type,data,element) {
2091 // Touch up the incoming data
2094 // Handle a global trigger
2096 var g = this.global[type];
2098 for ( var i = 0; i < g.length; i++ )
2099 this.trigger( type, data, g[i] );
2101 // Handle triggering a single element
2102 } else if ( element["on" + type] ) {
2103 // Pass along a fake event
2104 data.unshift( this.fix({ type: type, target: element }) );
2106 // Trigger the event
2107 element["on" + type].apply( element, data );
2111 handle: function(event) {
2112 if ( typeof jQuery == "undefined" ) return;
2114 event = event || jQuery.event.fix( window.event );
2116 // If no correct event was found, fail
2117 if ( !event ) return;
2119 var returnValue = true;
2121 var c = this.events[event.type];
2123 for ( var j in c ) {
2124 if ( c[j].apply( this, [event] ) === false ) {
2125 event.preventDefault();
2126 event.stopPropagation();
2127 returnValue = false;
2134 fix: function(event) {
2136 event.preventDefault = function() {
2137 this.returnValue = false;
2140 event.stopPropagation = function() {
2141 this.cancelBubble = true;
2152 var b = navigator.userAgent.toLowerCase();
2154 // Figure out what browser is being used
2156 safari: /webkit/.test(b),
2157 opera: /opera/.test(b),
2158 msie: /msie/.test(b) && !/opera/.test(b),
2159 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2162 // Check to see if the W3C box model is being used
2163 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2169 * Append all of the matched elements to another, specified, set of elements.
2170 * This operation is, essentially, the reverse of doing a regular
2171 * $(A).append(B), in that instead of appending B to A, you're appending
2174 * @example $("p").appendTo("#foo");
2175 * @before <p>I would like to say: </p><div id="foo"></div>
2176 * @result <div id="foo"><p>I would like to say: </p></div>
2180 * @param String expr A jQuery expression of elements to match.
2181 * @cat DOM/Manipulation
2186 * Prepend all of the matched elements to another, specified, set of elements.
2187 * This operation is, essentially, the reverse of doing a regular
2188 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2191 * @example $("p").prependTo("#foo");
2192 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2193 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2197 * @param String expr A jQuery expression of elements to match.
2198 * @cat DOM/Manipulation
2200 prependTo: "prepend",
2203 * Insert all of the matched elements before another, specified, set of elements.
2204 * This operation is, essentially, the reverse of doing a regular
2205 * $(A).before(B), in that instead of inserting B before A, you're inserting
2208 * @example $("p").insertBefore("#foo");
2209 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2210 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2212 * @name insertBefore
2214 * @param String expr A jQuery expression of elements to match.
2215 * @cat DOM/Manipulation
2217 insertBefore: "before",
2220 * Insert all of the matched elements after another, specified, set of elements.
2221 * This operation is, essentially, the reverse of doing a regular
2222 * $(A).after(B), in that instead of inserting B after A, you're inserting
2225 * @example $("p").insertAfter("#foo");
2226 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2227 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2231 * @param String expr A jQuery expression of elements to match.
2232 * @cat DOM/Manipulation
2234 insertAfter: "after"
2238 * Get the current CSS width of the first matched element.
2240 * @example $("p").width();
2241 * @before <p>This is just a test.</p>
2250 * Set the CSS width of every matched element. Be sure to include
2251 * the "px" (or other unit of measurement) after the number that you
2252 * specify, otherwise you might get strange results.
2254 * @example $("p").width("20px");
2255 * @before <p>This is just a test.</p>
2256 * @result <p style="width:20px;">This is just a test.</p>
2260 * @param String val Set the CSS property to the specified value.
2265 * Get the current CSS height of the first matched element.
2267 * @example $("p").height();
2268 * @before <p>This is just a test.</p>
2277 * Set the CSS height of every matched element. Be sure to include
2278 * the "px" (or other unit of measurement) after the number that you
2279 * specify, otherwise you might get strange results.
2281 * @example $("p").height("20px");
2282 * @before <p>This is just a test.</p>
2283 * @result <p style="height:20px;">This is just a test.</p>
2287 * @param String val Set the CSS property to the specified value.
2292 * Get the current CSS top of the first matched element.
2294 * @example $("p").top();
2295 * @before <p>This is just a test.</p>
2304 * Set the CSS top of every matched element. Be sure to include
2305 * the "px" (or other unit of measurement) after the number that you
2306 * specify, otherwise you might get strange results.
2308 * @example $("p").top("20px");
2309 * @before <p>This is just a test.</p>
2310 * @result <p style="top:20px;">This is just a test.</p>
2314 * @param String val Set the CSS property to the specified value.
2319 * Get the current CSS left of the first matched element.
2321 * @example $("p").left();
2322 * @before <p>This is just a test.</p>
2331 * Set the CSS left of every matched element. Be sure to include
2332 * the "px" (or other unit of measurement) after the number that you
2333 * specify, otherwise you might get strange results.
2335 * @example $("p").left("20px");
2336 * @before <p>This is just a test.</p>
2337 * @result <p style="left:20px;">This is just a test.</p>
2341 * @param String val Set the CSS property to the specified value.
2346 * Get the current CSS position of the first matched element.
2348 * @example $("p").position();
2349 * @before <p>This is just a test.</p>
2358 * Set the CSS position of every matched element.
2360 * @example $("p").position("relative");
2361 * @before <p>This is just a test.</p>
2362 * @result <p style="position:relative;">This is just a test.</p>
2366 * @param String val Set the CSS property to the specified value.
2371 * Get the current CSS float of the first matched element.
2373 * @example $("p").float();
2374 * @before <p>This is just a test.</p>
2383 * Set the CSS float of every matched element.
2385 * @example $("p").float("left");
2386 * @before <p>This is just a test.</p>
2387 * @result <p style="float:left;">This is just a test.</p>
2391 * @param String val Set the CSS property to the specified value.
2396 * Get the current CSS overflow of the first matched element.
2398 * @example $("p").overflow();
2399 * @before <p>This is just a test.</p>
2408 * Set the CSS overflow of every matched element.
2410 * @example $("p").overflow("auto");
2411 * @before <p>This is just a test.</p>
2412 * @result <p style="overflow:auto;">This is just a test.</p>
2416 * @param String val Set the CSS property to the specified value.
2421 * Get the current CSS color of the first matched element.
2423 * @example $("p").color();
2424 * @before <p>This is just a test.</p>
2433 * Set the CSS color of every matched element.
2435 * @example $("p").color("blue");
2436 * @before <p>This is just a test.</p>
2437 * @result <p style="color:blue;">This is just a test.</p>
2441 * @param String val Set the CSS property to the specified value.
2446 * Get the current CSS background of the first matched element.
2448 * @example $("p").background();
2449 * @before <p style="background:blue;">This is just a test.</p>
2458 * Set the CSS background of every matched element.
2460 * @example $("p").background("blue");
2461 * @before <p>This is just a test.</p>
2462 * @result <p style="background:blue;">This is just a test.</p>
2466 * @param String val Set the CSS property to the specified value.
2470 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2473 * Reduce the set of matched elements to a single element.
2474 * The position of the element in the set of matched elements
2475 * starts at 0 and goes to length - 1.
2477 * @example $("p").eq(1)
2478 * @before <p>This is just a test.</p><p>So is this</p>
2479 * @result [ <p>So is this</p> ]
2483 * @param Number pos The index of the element that you wish to limit to.
2488 * Reduce the set of matched elements to all elements before a given position.
2489 * The position of the element in the set of matched elements
2490 * starts at 0 and goes to length - 1.
2492 * @example $("p").lt(1)
2493 * @before <p>This is just a test.</p><p>So is this</p>
2494 * @result [ <p>This is just a test.</p> ]
2498 * @param Number pos Reduce the set to all elements below this position.
2503 * Reduce the set of matched elements to all elements after a given position.
2504 * The position of the element in the set of matched elements
2505 * starts at 0 and goes to length - 1.
2507 * @example $("p").gt(0)
2508 * @before <p>This is just a test.</p><p>So is this</p>
2509 * @result [ <p>So is this</p> ]
2513 * @param Number pos Reduce the set to all elements after this position.
2518 * Filter the set of elements to those that contain the specified text.
2520 * @example $("p").contains("test")
2521 * @before <p>This is just a test.</p><p>So is this</p>
2522 * @result [ <p>This is just a test.</p> ]
2526 * @param String str The string that will be contained within the text of an element.
2527 * @cat DOM/Traversing
2530 filter: [ "eq", "lt", "gt", "contains" ],
2534 * Get the current value of the first matched element.
2536 * @example $("input").val();
2537 * @before <input type="text" value="some text"/>
2538 * @result "some text"
2540 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2541 * @test ok( !$("#text1").val() == "", "Check for value of input element" );
2545 * @cat DOM/Attributes
2549 * Set the value of every matched element.
2551 * @example $("input").value("test");
2552 * @before <input type="text" value="some text"/>
2553 * @result <input type="text" value="test"/>
2555 * @test document.getElementById('text1').value = "bla";
2556 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2557 * $("#text1").val('test');
2558 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2562 * @param String val Set the property to the specified value.
2563 * @cat DOM/Attributes
2568 * Get the html contents of the first matched element.
2570 * @example $("div").html();
2571 * @before <div><input/></div>
2576 * @cat DOM/Attributes
2580 * Set the html contents of every matched element.
2582 * @example $("div").html("<b>new stuff</b>");
2583 * @before <div><input/></div>
2584 * @result <div><b>new stuff</b></div>
2586 * @test var div = $("div");
2587 * div.html("<b>test</b>");
2589 * for ( var i = 0; i < div.size(); i++ ) {
2590 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2592 * ok( pass, "Set HTML" );
2596 * @param String val Set the html contents to the specified value.
2597 * @cat DOM/Attributes
2602 * Get the current id of the first matched element.
2604 * @example $("input").id();
2605 * @before <input type="text" id="test" value="some text"/>
2610 * @cat DOM/Attributes
2614 * Set the id of every matched element.
2616 * @example $("input").id("newid");
2617 * @before <input type="text" id="test" value="some text"/>
2618 * @result <input type="text" id="newid" value="some text"/>
2622 * @param String val Set the property to the specified value.
2623 * @cat DOM/Attributes
2628 * Get the current title of the first matched element.
2630 * @example $("img").title();
2631 * @before <img src="test.jpg" title="my image"/>
2632 * @result "my image"
2636 * @cat DOM/Attributes
2640 * Set the title of every matched element.
2642 * @example $("img").title("new title");
2643 * @before <img src="test.jpg" title="my image"/>
2644 * @result <img src="test.jpg" title="new image"/>
2648 * @param String val Set the property to the specified value.
2649 * @cat DOM/Attributes
2654 * Get the current name of the first matched element.
2656 * @example $("input").name();
2657 * @before <input type="text" name="username"/>
2658 * @result "username"
2662 * @cat DOM/Attributes
2666 * Set the name of every matched element.
2668 * @example $("input").name("user");
2669 * @before <input type="text" name="username"/>
2670 * @result <input type="text" name="user"/>
2674 * @param String val Set the property to the specified value.
2675 * @cat DOM/Attributes
2680 * Get the current href of the first matched element.
2682 * @example $("a").href();
2683 * @before <a href="test.html">my link</a>
2684 * @result "test.html"
2688 * @cat DOM/Attributes
2692 * Set the href of every matched element.
2694 * @example $("a").href("test2.html");
2695 * @before <a href="test.html">my link</a>
2696 * @result <a href="test2.html">my link</a>
2700 * @param String val Set the property to the specified value.
2701 * @cat DOM/Attributes
2706 * Get the current src of the first matched element.
2708 * @example $("img").src();
2709 * @before <img src="test.jpg" title="my image"/>
2710 * @result "test.jpg"
2714 * @cat DOM/Attributes
2718 * Set the src of every matched element.
2720 * @example $("img").src("test2.jpg");
2721 * @before <img src="test.jpg" title="my image"/>
2722 * @result <img src="test2.jpg" title="my image"/>
2726 * @param String val Set the property to the specified value.
2727 * @cat DOM/Attributes
2732 * Get the current rel of the first matched element.
2734 * @example $("a").rel();
2735 * @before <a href="test.html" rel="nofollow">my link</a>
2736 * @result "nofollow"
2740 * @cat DOM/Attributes
2744 * Set the rel of every matched element.
2746 * @example $("a").rel("nofollow");
2747 * @before <a href="test.html">my link</a>
2748 * @result <a href="test.html" rel="nofollow">my link</a>
2752 * @param String val Set the property to the specified value.
2753 * @cat DOM/Attributes
2760 * Get a set of elements containing the unique parents of the matched
2763 * @example $("p").parent()
2764 * @before <div><p>Hello</p><p>Hello</p></div>
2765 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2769 * @cat DOM/Traversing
2773 * Get a set of elements containing the unique parents of the matched
2774 * set of elements, and filtered by an expression.
2776 * @example $("p").parent(".selected")
2777 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2778 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2782 * @param String expr An expression to filter the parents with
2783 * @cat DOM/Traversing
2785 parent: "a.parentNode",
2788 * Get a set of elements containing the unique ancestors of the matched
2789 * set of elements (except for the root element).
2791 * @example $("span").ancestors()
2792 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2793 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2797 * @cat DOM/Traversing
2801 * Get a set of elements containing the unique ancestors of the matched
2802 * set of elements, and filtered by an expression.
2804 * @example $("span").ancestors("p")
2805 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2806 * @result [ <p><span>Hello</span></p> ]
2810 * @param String expr An expression to filter the ancestors with
2811 * @cat DOM/Traversing
2813 ancestors: jQuery.parents,
2816 * Get a set of elements containing the unique ancestors of the matched
2817 * set of elements (except for the root element).
2819 * @example $("span").ancestors()
2820 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2821 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2825 * @cat DOM/Traversing
2829 * Get a set of elements containing the unique ancestors of the matched
2830 * set of elements, and filtered by an expression.
2832 * @example $("span").ancestors("p")
2833 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2834 * @result [ <p><span>Hello</span></p> ]
2838 * @param String expr An expression to filter the ancestors with
2839 * @cat DOM/Traversing
2841 parents: jQuery.parents,
2844 * Get a set of elements containing the unique next siblings of each of the
2845 * matched set of elements.
2847 * It only returns the very next sibling, not all next siblings.
2849 * @example $("p").next()
2850 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2851 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2855 * @cat DOM/Traversing
2859 * Get a set of elements containing the unique next siblings of each of the
2860 * matched set of elements, and filtered by an expression.
2862 * It only returns the very next sibling, not all next siblings.
2864 * @example $("p").next(".selected")
2865 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2866 * @result [ <p class="selected">Hello Again</p> ]
2870 * @param String expr An expression to filter the next Elements with
2871 * @cat DOM/Traversing
2873 next: "jQuery.sibling(a).next",
2876 * Get a set of elements containing the unique previous siblings of each of the
2877 * matched set of elements.
2879 * It only returns the immediately previous sibling, not all previous siblings.
2881 * @example $("p").previous()
2882 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2883 * @result [ <div><span>Hello Again</span></div> ]
2887 * @cat DOM/Traversing
2891 * Get a set of elements containing the unique previous siblings of each of the
2892 * matched set of elements, and filtered by an expression.
2894 * It only returns the immediately previous sibling, not all previous siblings.
2896 * @example $("p").previous(".selected")
2897 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2898 * @result [ <div><span>Hello</span></div> ]
2902 * @param String expr An expression to filter the previous Elements with
2903 * @cat DOM/Traversing
2905 prev: "jQuery.sibling(a).prev",
2908 * Get a set of elements containing all of the unique siblings of each of the
2909 * matched set of elements.
2911 * @example $("div").siblings()
2912 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2913 * @result [ <p>Hello</p>, <p>And Again</p> ]
2917 * @cat DOM/Traversing
2921 * Get a set of elements containing all of the unique siblings of each of the
2922 * matched set of elements, and filtered by an expression.
2924 * @example $("div").siblings(".selected")
2925 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2926 * @result [ <p class="selected">Hello Again</p> ]
2930 * @param String expr An expression to filter the sibling Elements with
2931 * @cat DOM/Traversing
2933 siblings: jQuery.sibling,
2937 * Get a set of elements containing all of the unique children of each of the
2938 * matched set of elements.
2940 * @example $("div").children()
2941 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2942 * @result [ <span>Hello Again</span> ]
2946 * @cat DOM/Traversing
2950 * Get a set of elements containing all of the unique children of each of the
2951 * matched set of elements, and filtered by an expression.
2953 * @example $("div").children(".selected")
2954 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2955 * @result [ <p class="selected">Hello Again</p> ]
2959 * @param String expr An expression to filter the child Elements with
2960 * @cat DOM/Traversing
2962 children: "jQuery.sibling(a.firstChild)"
2968 * Remove an attribute from each of the matched elements.
2970 * @example $("input").removeAttr("disabled")
2971 * @before <input disabled="disabled"/>
2976 * @param String name The name of the attribute to remove.
2979 removeAttr: function( key ) {
2980 this.removeAttribute( key );
2984 * Displays each of the set of matched elements if they are hidden.
2986 * @example $("p").show()
2987 * @before <p style="display: none">Hello</p>
2988 * @result [ <p style="display: block">Hello</p> ]
2990 * @test var pass = true, div = $("div");
2991 * div.show().each(function(){
2992 * if ( this.style.display == "none" ) pass = false;
2994 * ok( pass, "Show" );
3001 this.style.display = this.oldblock ? this.oldblock : "";
3002 if ( jQuery.css(this,"display") == "none" )
3003 this.style.display = "block";
3007 * Hides each of the set of matched elements if they are shown.
3009 * @example $("p").hide()
3010 * @before <p>Hello</p>
3011 * @result [ <p style="display: none">Hello</p> ]
3013 * var pass = true, div = $("div");
3014 * div.hide().each(function(){
3015 * if ( this.style.display != "none" ) pass = false;
3017 * ok( pass, "Hide" );
3024 this.oldblock = this.oldblock || jQuery.css(this,"display");
3025 if ( this.oldblock == "none" )
3026 this.oldblock = "block";
3027 this.style.display = "none";
3031 * Toggles each of the set of matched elements. If they are shown,
3032 * toggle makes them hidden. If they are hidden, toggle
3035 * @example $("p").toggle()
3036 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3037 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3044 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3048 * Adds the specified class to each of the set of matched elements.
3050 * @example $("p").addClass("selected")
3051 * @before <p>Hello</p>
3052 * @result [ <p class="selected">Hello</p> ]
3054 * @test var div = $("div");
3055 * div.addClass("test");
3057 * for ( var i = 0; i < div.size(); i++ ) {
3058 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3060 * ok( pass, "Add Class" );
3064 * @param String class A CSS class to add to the elements
3067 addClass: function(c){
3068 jQuery.className.add(this,c);
3072 * Removes the specified class from the set of matched elements.
3074 * @example $("p").removeClass("selected")
3075 * @before <p class="selected">Hello</p>
3076 * @result [ <p>Hello</p> ]
3078 * @test var div = $("div").addClass("test");
3079 * div.removeClass("test");
3081 * for ( var i = 0; i < div.size(); i++ ) {
3082 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3084 * ok( pass, "Remove Class" );
3088 * @param String class A CSS class to remove from the elements
3091 removeClass: function(c){
3092 jQuery.className.remove(this,c);
3096 * Adds the specified class if it is present, removes it if it is
3099 * @example $("p").toggleClass("selected")
3100 * @before <p>Hello</p><p class="selected">Hello Again</p>
3101 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3105 * @param String class A CSS class with which to toggle the elements
3108 toggleClass: function( c ){
3109 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3113 * Removes all matched elements from the DOM. This does NOT remove them from the
3114 * jQuery object, allowing you to use the matched elements further.
3116 * @example $("p").remove();
3117 * @before <p>Hello</p> how are <p>you?</p>
3122 * @cat DOM/Manipulation
3126 * Removes only elements (out of the list of matched elements) that match
3127 * the specified jQuery expression. This does NOT remove them from the
3128 * jQuery object, allowing you to use the matched elements further.
3130 * @example $("p").remove(".hello");
3131 * @before <p class="hello">Hello</p> how are <p>you?</p>
3132 * @result how are <p>you?</p>
3136 * @param String expr A jQuery expression to filter elements by.
3137 * @cat DOM/Manipulation
3139 remove: function(a){
3140 if ( !a || jQuery.filter( a, [this] ).r )
3141 this.parentNode.removeChild( this );
3145 * Removes all child nodes from the set of matched elements.
3147 * @example $("p").empty()
3148 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3149 * @result [ <p></p> ]
3153 * @cat DOM/Manipulation
3156 while ( this.firstChild )
3157 this.removeChild( this.firstChild );
3161 * Binds a handler to a particular event (like click) for each matched element.
3162 * The event handler is passed an event object that you can use to prevent
3163 * default behaviour. To stop both default action and event bubbling, your handler
3164 * has to return false.
3166 * @example $("p").bind( "click", function() {
3167 * alert( $(this).text() );
3169 * @before <p>Hello</p>
3172 * @example $("form").bind( "submit", function() { return false; } )
3173 * @desc Cancel a default action and prevent it from bubbling by returning false
3174 * from your function.
3176 * @example $("form").bind( "submit", function(event) {
3177 * event.preventDefault();
3179 * @desc Cancel only the default action by using the preventDefault method.
3182 * @example $("form").bind( "submit", function(event) {
3183 * event.stopPropagation();
3185 * @desc Stop only an event from bubbling by using the stopPropagation method.
3189 * @param String type An event type
3190 * @param Function fn A function to bind to the event on each of the set of matched elements
3193 bind: function( type, fn ) {
3194 if ( fn.constructor == String )
3195 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3196 jQuery.event.add( this, type, fn );
3200 * The opposite of bind, removes a bound event from each of the matched
3201 * elements. You must pass the identical function that was used in the original
3204 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3205 * @before <p onclick="alert('Hello');">Hello</p>
3206 * @result [ <p>Hello</p> ]
3210 * @param String type An event type
3211 * @param Function fn A function to unbind from the event on each of the set of matched elements
3216 * Removes all bound events of a particular type from each of the matched
3219 * @example $("p").unbind( "click" )
3220 * @before <p onclick="alert('Hello');">Hello</p>
3221 * @result [ <p>Hello</p> ]
3225 * @param String type An event type
3230 * Removes all bound events from each of the matched elements.
3232 * @example $("p").unbind()
3233 * @before <p onclick="alert('Hello');">Hello</p>
3234 * @result [ <p>Hello</p> ]
3240 unbind: function( type, fn ) {
3241 jQuery.event.remove( this, type, fn );
3245 * Trigger a type of event on every matched element.
3247 * @example $("p").trigger("click")
3248 * @before <p click="alert('hello')">Hello</p>
3249 * @result alert('hello')
3253 * @param String type An event type to trigger.
3256 trigger: function( type, data ) {
3257 jQuery.event.trigger( type, data, this );