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 * ok( Function.prototype.apply, "Function.apply()" );
20 * ok( document.getElementById, "getElementById" );
21 * ok( document.getElementsByTagName, "getElementsByTagName" );
22 * ok( RegExp, "RegExp" );
23 * ok( jQuery, "jQuery" );
31 jQuery = function(a,c) {
33 // Shortcut for document ready (because $(document).each() is silly)
34 if ( a && typeof a == "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 && typeof fn == "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.
157 * You can have as many $(document).ready events on your page as you like.
159 * @example $(function(){
160 * // Document is ready
162 * @desc Executes the function when the DOM is ready to be used.
165 * @param Function fn The function to execute when the DOM is ready.
171 * A means of creating a cloned copy of a jQuery object. This function
172 * copies the set of matched elements from one jQuery object and creates
173 * another, new, jQuery object containing the same elements.
175 * @example var div = $("div");
176 * $( div ).find("p");
177 * @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).
180 * @param jQuery obj The jQuery object to be cloned.
185 // Map the jQuery namespace to the '$' one
188 jQuery.fn = jQuery.prototype = {
190 * The current SVN version of jQuery.
201 * The number of elements currently matched.
203 * @example $("img").length;
204 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
207 * @test ok( $("div").length == 2, "Get Number of Elements Found" );
216 * The number of elements currently matched.
218 * @example $("img").size();
219 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
222 * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
233 * Access all matched elements. This serves as a backwards-compatible
234 * way of accessing all matched elements (other than the jQuery object
235 * itself, which is, in fact, an array of elements).
237 * @example $("img").get();
238 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
239 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
241 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
244 * @type Array<Element>
249 * Access a single matched element. num is used to access the
250 * Nth element matched.
252 * @example $("img").get(1);
253 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
254 * @result [ <img src="test1.jpg"/> ]
256 * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
260 * @param Number num Access the element in the Nth position.
265 * Set the jQuery object to an array of elements.
267 * @example $("img").get([ document.body ]);
268 * @result $("img").get() == [ document.body ]
273 * @param Elements elems An array of elements
276 get: function( num ) {
277 // Watch for when an array (of elements) is passed in
278 if ( num && num.constructor == Array ) {
280 // Use a tricky hack to make the jQuery object
281 // look and feel like an array
283 [].push.apply( this, num );
287 return num == undefined ?
289 // Return a 'clean' array
290 jQuery.merge( this, [] ) :
292 // Return just the object
297 * Execute a function within the context of every matched element.
298 * This means that every time the passed-in function is executed
299 * (which is once for every element matched) the 'this' keyword
300 * points to the specific element.
302 * Additionally, the function, when executed, is passed a single
303 * argument representing the position of the element in the matched
306 * @example $("img").each(function(){
307 * this.src = "test.jpg";
309 * @before <img/> <img/>
310 * @result <img src="test.jpg"/> <img src="test.jpg"/>
312 * @example $("img").each(function(i){
313 * alert( "Image #" + i + " is " + this );
315 * @before <img/> <img/>
316 * @result <img src="test.jpg"/> <img src="test.jpg"/>
318 * @test var div = $("div");
319 * div.each(function(){this.foo = 'zoo';});
321 * for ( var i = 0; i < div.size(); i++ ) {
322 * if ( div.get(i).foo != "zoo" ) pass = false;
324 * ok( pass, "Execute a function, Relative" );
328 * @param Function fn A function to execute
331 each: function( fn, args ) {
332 return jQuery.each( this, fn, args );
336 * Searches every matched element for the object and returns
337 * the index of the element, if found, starting with zero.
338 * Returns -1 if the object wasn't found.
340 * @example $("*").index(document.getElementById('foobar'))
341 * @before <div id="foobar"></div><b></b><span id="foo"></span>
344 * @example $("*").index(document.getElementById('foo'))
345 * @before <div id="foobar"></div><b></b><span id="foo"></span>
348 * @example $("*").index(document.getElementById('bar'))
349 * @before <div id="foobar"></div><b></b><span id="foo"></span>
352 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
353 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
354 * var inputElements = $('#radio1,#radio2,#check1,#check2');
355 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
356 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
357 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
358 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
359 * ok( inputElements.index(window) == -1, "Check for not found index" );
360 * ok( inputElements.index(document) == -1, "Check for not found index" );
364 * @param Object obj Object to search for
367 index: function( obj ) {
369 this.each(function(i){
370 if ( this == obj ) pos = i;
376 * Access a property on the first matched element.
377 * This method makes it easy to retrieve a property value
378 * from the first matched element.
380 * @example $("img").attr("src");
381 * @before <img src="test.jpg"/>
384 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
385 * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
386 * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
387 * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
388 * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
389 * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
390 * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
391 * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
392 * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
393 * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
394 * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
395 * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
399 * @param String name The name of the property to access.
404 * Set a hash of key/value object properties to all matched elements.
405 * This serves as the best way to set a large number of properties
406 * on all matched elements.
408 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
410 * @result <img src="test.jpg" alt="Test Image"/>
412 * @test var pass = true;
413 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
414 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
416 * ok( pass, "Set Multiple Attributes" );
420 * @param Hash prop A set of key/value pairs to set as object properties.
425 * Set a single property to a value, on all matched elements.
427 * @example $("img").attr("src","test.jpg");
429 * @result <img src="test.jpg"/>
431 * @test var div = $("div");
432 * div.attr("foo", "bar");
434 * for ( var i = 0; i < div.size(); i++ ) {
435 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
437 * ok( pass, "Set Attribute" );
439 * $("#name").attr('name', 'something');
440 * ok( $("#name").name() == 'something', 'Set name attribute' );
441 * $("#check2").attr('checked', true);
442 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
443 * $("#check2").attr('checked', false);
444 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
448 * @param String key The name of the property to set.
449 * @param Object value The value to set the property to.
452 attr: function( key, value, type ) {
453 // Check to see if we're setting style values
454 return key.constructor != String || value != undefined ?
455 this.each(function(){
456 // See if we're setting a hash of styles
457 if ( value == undefined )
458 // Set all the styles
459 for ( var prop in key )
461 type ? this.style : this,
465 // See if we're setting a single key/value style
468 type ? this.style : this,
473 // Look for the case where we're accessing a style value
474 jQuery[ type || "attr" ]( this[0], key );
478 * Access a style property on the first matched element.
479 * This method makes it easy to retrieve a style property value
480 * from the first matched element.
482 * @example $("p").css("color");
483 * @before <p style="color:red;">Test Paragraph.</p>
485 * @desc Retrieves the color style of the first paragraph
487 * @example $("p").css("fontWeight");
488 * @before <p style="font-weight: bold;">Test Paragraph.</p>
490 * @desc Retrieves the font-weight style of the first paragraph.
491 * Note that for all style properties with a dash (like 'font-weight'), you have to
492 * write it in camelCase. In other words: Every time you have a '-' in a
493 * property, remove it and replace the next character with an uppercase
494 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
495 * borderStyle, borderBottomWidth etc.
497 * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
501 * @param String name The name of the property to access.
506 * Set a hash of key/value style properties to all matched elements.
507 * This serves as the best way to set a large number of style properties
508 * on all matched elements.
510 * @example $("p").css({ color: "red", background: "blue" });
511 * @before <p>Test Paragraph.</p>
512 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
514 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
515 * $('#foo').css({display: 'none'});
516 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
517 * $('#foo').css({display: 'block'});
518 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
522 * @param Hash prop A set of key/value pairs to set as style properties.
527 * Set a single style property to a value, on all matched elements.
529 * @example $("p").css("color","red");
530 * @before <p>Test Paragraph.</p>
531 * @result <p style="color:red;">Test Paragraph.</p>
532 * @desc Changes the color of all paragraphs to red
535 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
536 * $('#foo').css('display', 'none');
537 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
538 * $('#foo').css('display', 'block');
539 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
543 * @param String key The name of the property to set.
544 * @param Object value The value to set the property to.
547 css: function( key, value ) {
548 return this.attr( key, value, "curCSS" );
552 * Retrieve the text contents of all matched elements. The result is
553 * a string that contains the combined text contents of all matched
554 * elements. This method works on both HTML and XML documents.
556 * @example $("p").text();
557 * @before <p>Test Paragraph.</p>
558 * @result Test Paragraph.
560 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
561 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
570 for ( var j = 0; j < e.length; j++ ) {
571 var r = e[j].childNodes;
572 for ( var i = 0; i < r.length; i++ )
573 if ( r[i].nodeType != 8 )
574 t += r[i].nodeType != 1 ?
575 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
581 * Wrap all matched elements with a structure of other elements.
582 * This wrapping process is most useful for injecting additional
583 * stucture into a document, without ruining the original semantic
584 * qualities of a document.
586 * This works by going through the first element
587 * provided (which is generated, on the fly, from the provided HTML)
588 * and finds the deepest ancestor element within its
589 * structure - it is that element that will en-wrap everything else.
591 * This does not work with elements that contain text. Any necessary text
592 * must be added after the wrapping is done.
594 * @example $("p").wrap("<div class='wrap'></div>");
595 * @before <p>Test Paragraph.</p>
596 * @result <div class='wrap'><p>Test Paragraph.</p></div>
598 * @test var defaultText = 'Try them out:'
599 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
600 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
601 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
605 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
606 * @cat DOM/Manipulation
610 * Wrap all matched elements with a structure of other elements.
611 * This wrapping process is most useful for injecting additional
612 * stucture into a document, without ruining the original semantic
613 * qualities of a document.
615 * This works by going through the first element
616 * provided and finding the deepest ancestor element within its
617 * structure - it is that element that will en-wrap everything else.
619 * This does not work with elements that contain text. Any necessary text
620 * must be added after the wrapping is done.
622 * @example $("p").wrap( document.getElementById('content') );
623 * @before <p>Test Paragraph.</p><div id="content"></div>
624 * @result <div id="content"><p>Test Paragraph.</p></div>
626 * @test var defaultText = 'Try them out:'
627 * var result = $('#first').wrap(document.getElementById('empty')).parent();
628 * ok( result.is('ol'), 'Check for element wrapping' );
629 * ok( result.text() == defaultText, 'Check for element wrapping' );
633 * @param Element elem A DOM element that will be wrapped.
634 * @cat DOM/Manipulation
637 // The elements to wrap the target around
638 var a = jQuery.clean(arguments);
640 // Wrap each of the matched elements individually
641 return this.each(function(){
642 // Clone the structure that we're using to wrap
643 var b = a[0].cloneNode(true);
645 // Insert it before the element to be wrapped
646 this.parentNode.insertBefore( b, this );
648 // Find he deepest point in the wrap structure
649 while ( b.firstChild )
652 // Move the matched element to within the wrap structure
653 b.appendChild( this );
658 * Append any number of elements to the inside of every matched elements,
659 * generated from the provided HTML.
660 * This operation is similar to doing an appendChild to all the
661 * specified elements, adding them into the document.
663 * @example $("p").append("<b>Hello</b>");
664 * @before <p>I would like to say: </p>
665 * @result <p>I would like to say: <b>Hello</b></p>
667 * @test var defaultText = 'Try them out:'
668 * var result = $('#first').append('<b>buga</b>');
669 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
673 * @param String html A string of HTML, that will be created on the fly and appended to the target.
674 * @cat DOM/Manipulation
678 * Append an element to the inside of all matched elements.
679 * This operation is similar to doing an appendChild to all the
680 * specified elements, adding them into the document.
682 * @example $("p").append( $("#foo")[0] );
683 * @before <p>I would like to say: </p><b id="foo">Hello</b>
684 * @result <p>I would like to say: <b id="foo">Hello</b></p>
686 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
687 * $('#sap').append(document.getElementById('first'));
688 * ok( expected == $('#sap').text(), "Check for appending of element" );
692 * @param Element elem A DOM element that will be appended.
693 * @cat DOM/Manipulation
697 * Append any number of elements to the inside of all matched elements.
698 * This operation is similar to doing an appendChild to all the
699 * specified elements, adding them into the document.
701 * @example $("p").append( $("b") );
702 * @before <p>I would like to say: </p><b>Hello</b>
703 * @result <p>I would like to say: <b>Hello</b></p>
705 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
706 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
707 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
711 * @param Array<Element> elems An array of elements, all of which will be appended.
712 * @cat DOM/Manipulation
715 return this.domManip(arguments, true, 1, function(a){
716 this.appendChild( a );
721 * Prepend any number of elements to the inside of every matched elements,
722 * generated from the provided HTML.
723 * This operation is the best way to insert dynamically created elements
724 * inside, at the beginning, of all the matched element.
726 * @example $("p").prepend("<b>Hello</b>");
727 * @before <p>I would like to say: </p>
728 * @result <p><b>Hello</b>I would like to say: </p>
730 * @test var defaultText = 'Try them out:'
731 * var result = $('#first').prepend('<b>buga</b>');
732 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
736 * @param String html A string of HTML, that will be created on the fly and appended to the target.
737 * @cat DOM/Manipulation
741 * Prepend an element to the inside of all matched elements.
742 * This operation is the best way to insert an element inside, at the
743 * beginning, of all the matched element.
745 * @example $("p").prepend( $("#foo")[0] );
746 * @before <p>I would like to say: </p><b id="foo">Hello</b>
747 * @result <p><b id="foo">Hello</b>I would like to say: </p>
749 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
750 * $('#sap').prepend(document.getElementById('first'));
751 * ok( expected == $('#sap').text(), "Check for prepending of element" );
755 * @param Element elem A DOM element that will be appended.
756 * @cat DOM/Manipulation
760 * Prepend any number of elements to the inside of all matched elements.
761 * This operation is the best way to insert a set of elements inside, at the
762 * beginning, of all the matched element.
764 * @example $("p").prepend( $("b") );
765 * @before <p>I would like to say: </p><b>Hello</b>
766 * @result <p><b>Hello</b>I would like to say: </p>
768 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
769 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
770 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
774 * @param Array<Element> elems An array of elements, all of which will be appended.
775 * @cat DOM/Manipulation
777 prepend: function() {
778 return this.domManip(arguments, true, -1, function(a){
779 this.insertBefore( a, this.firstChild );
784 * Insert any number of dynamically generated elements before each of the
787 * @example $("p").before("<b>Hello</b>");
788 * @before <p>I would like to say: </p>
789 * @result <b>Hello</b><p>I would like to say: </p>
791 * @test var expected = 'This is a normal link: bugaYahoo';
792 * $('#yahoo').before('<b>buga</b>');
793 * ok( expected == $('#en').text(), 'Insert String before' );
797 * @param String html A string of HTML, that will be created on the fly and appended to the target.
798 * @cat DOM/Manipulation
802 * Insert an element before each of the matched elements.
804 * @example $("p").before( $("#foo")[0] );
805 * @before <p>I would like to say: </p><b id="foo">Hello</b>
806 * @result <b id="foo">Hello</b><p>I would like to say: </p>
808 * @test var expected = "This is a normal link: Try them out:Yahoo";
809 * $('#yahoo').before(document.getElementById('first'));
810 * ok( expected == $('#en').text(), "Insert element before" );
814 * @param Element elem A DOM element that will be appended.
815 * @cat DOM/Manipulation
819 * Insert any number of elements before each of the matched elements.
821 * @example $("p").before( $("b") );
822 * @before <p>I would like to say: </p><b>Hello</b>
823 * @result <b>Hello</b><p>I would like to say: </p>
825 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
826 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
827 * ok( expected == $('#en').text(), "Insert array of elements before" );
831 * @param Array<Element> elems An array of elements, all of which will be appended.
832 * @cat DOM/Manipulation
835 return this.domManip(arguments, false, 1, function(a){
836 this.parentNode.insertBefore( a, this );
841 * Insert any number of dynamically generated elements after each of the
844 * @example $("p").after("<b>Hello</b>");
845 * @before <p>I would like to say: </p>
846 * @result <p>I would like to say: </p><b>Hello</b>
848 * @test var expected = 'This is a normal link: Yahoobuga';
849 * $('#yahoo').after('<b>buga</b>');
850 * ok( expected == $('#en').text(), 'Insert String after' );
854 * @param String html A string of HTML, that will be created on the fly and appended to the target.
855 * @cat DOM/Manipulation
859 * Insert an element after each of the matched elements.
861 * @example $("p").after( $("#foo")[0] );
862 * @before <b id="foo">Hello</b><p>I would like to say: </p>
863 * @result <p>I would like to say: </p><b id="foo">Hello</b>
865 * @test var expected = "This is a normal link: YahooTry them out:";
866 * $('#yahoo').after(document.getElementById('first'));
867 * ok( expected == $('#en').text(), "Insert element after" );
871 * @param Element elem A DOM element that will be appended.
872 * @cat DOM/Manipulation
876 * Insert any number of elements after each of the matched elements.
878 * @example $("p").after( $("b") );
879 * @before <b>Hello</b><p>I would like to say: </p>
880 * @result <p>I would like to say: </p><b>Hello</b>
882 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
883 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
884 * ok( expected == $('#en').text(), "Insert array of elements after" );
888 * @param Array<Element> elems An array of elements, all of which will be appended.
889 * @cat DOM/Manipulation
892 return this.domManip(arguments, false, -1, function(a){
893 this.parentNode.insertBefore( a, this.nextSibling );
898 * End the most recent 'destructive' operation, reverting the list of matched elements
899 * back to its previous state. After an end operation, the list of matched elements will
900 * revert to the last state of matched elements.
902 * @example $("p").find("span").end();
903 * @before <p><span>Hello</span>, how are you?</p>
904 * @result $("p").find("span").end() == [ <p>...</p> ]
906 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
910 * @cat DOM/Traversing
913 return this.get( this.stack.pop() );
917 * Searches for all elements that match the specified expression.
918 * This method is the optimal way of finding additional descendant
919 * elements with which to process.
921 * All searching is done using a jQuery expression. The expression can be
922 * written using CSS 1-3 Selector syntax, or basic XPath.
924 * @example $("p").find("span");
925 * @before <p><span>Hello</span>, how are you?</p>
926 * @result $("p").find("span") == [ <span>Hello</span> ]
928 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
932 * @param String expr An expression to search with.
933 * @cat DOM/Traversing
936 return this.pushStack( jQuery.map( this, function(a){
937 return jQuery.find(t,a);
942 * Create cloned copies of all matched DOM Elements. This does
943 * not create a cloned copy of this particular jQuery object,
944 * instead it creates duplicate copies of all DOM Elements.
945 * This is useful for moving copies of the elements to another
946 * location in the DOM.
948 * @example $("b").clone().prependTo("p");
949 * @before <b>Hello</b><p>, how are you?</p>
950 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
952 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
953 * var clone = $('#yahoo').clone();
954 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
955 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
959 * @cat DOM/Manipulation
961 clone: function(deep) {
962 return this.pushStack( jQuery.map( this, function(a){
963 return a.cloneNode( deep != undefined ? deep : true );
968 * Removes all elements from the set of matched elements that do not
969 * match the specified expression. This method is used to narrow down
970 * the results of a search.
972 * All searching is done using a jQuery expression. The expression
973 * can be written using CSS 1-3 Selector syntax, or basic XPath.
975 * @example $("p").filter(".selected")
976 * @before <p class="selected">Hello</p><p>How are you?</p>
977 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
979 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
980 * @test $("input").filter(":checked",function(i){
981 * ok( this == q("radio2", "check1")[i], "Filter elements, context" );
983 * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){
984 * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
989 * @param String expr An expression to search with.
990 * @cat DOM/Traversing
994 * Removes all elements from the set of matched elements that do not
995 * match at least one of the expressions passed to the function. This
996 * method is used when you want to filter the set of matched elements
997 * through more than one expression.
999 * Elements will be retained in the jQuery object if they match at
1000 * least one of the expressions passed.
1002 * @example $("p").filter([".selected", ":first"])
1003 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
1004 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
1008 * @param Array<String> exprs A set of expressions to evaluate against
1009 * @cat DOM/Traversing
1011 filter: function(t) {
1012 return this.pushStack(
1013 t.constructor == Array &&
1014 jQuery.map(this,function(a){
1015 for ( var i = 0; i < t.length; i++ )
1016 if ( jQuery.filter(t[i],[a]).r.length )
1020 t.constructor == Boolean &&
1021 ( t ? this.get() : [] ) ||
1023 typeof t == "function" &&
1024 jQuery.grep( this, t ) ||
1026 jQuery.filter(t,this).r, arguments );
1030 * Removes the specified Element from the set of matched elements. This
1031 * method is used to remove a single Element from a jQuery object.
1033 * @example $("p").not( document.getElementById("selected") )
1034 * @before <p>Hello</p><p id="selected">Hello Again</p>
1035 * @result [ <p>Hello</p> ]
1039 * @param Element el An element to remove from the set
1040 * @cat DOM/Traversing
1044 * Removes elements matching the specified expression from the set
1045 * of matched elements. This method is used to remove one or more
1046 * elements from a jQuery object.
1048 * @example $("p").not("#selected")
1049 * @before <p>Hello</p><p id="selected">Hello Again</p>
1050 * @result [ <p>Hello</p> ]
1052 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
1056 * @param String expr An expression with which to remove matching elements
1057 * @cat DOM/Traversing
1060 return this.pushStack( t.constructor == String ?
1061 jQuery.filter(t,this,false).r :
1062 jQuery.grep(this,function(a){ return a != t; }), arguments );
1066 * Adds the elements matched by the expression to the jQuery object. This
1067 * can be used to concatenate the result sets of two expressions.
1069 * @example $("p").add("span")
1070 * @before <p>Hello</p><p><span>Hello Again</span></p>
1071 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1075 * @param String expr An expression whose matched elements are added
1076 * @cat DOM/Traversing
1080 * Adds each of the Elements in the array to the set of matched elements.
1081 * This is used to add a set of Elements to a jQuery object.
1083 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1084 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1085 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1089 * @param Array<Element> els An array of Elements to add
1090 * @cat DOM/Traversing
1094 * Adds a single Element to the set of matched elements. This is used to
1095 * add a single Element to a jQuery object.
1097 * @example $("p").add( document.getElementById("a") )
1098 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1099 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1103 * @param Element el An Element to add
1104 * @cat DOM/Traversing
1107 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1108 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1112 * Checks the current selection against an expression and returns true,
1113 * if the selection fits the given expression. Does return false, if the
1114 * selection does not fit or the expression is not valid.
1116 * @example $("input[@type='checkbox']").parent().is("form")
1117 * @before <form><input type="checkbox" /></form>
1119 * @desc Returns true, because the parent of the input is a form element
1121 * @example $("input[@type='checkbox']").parent().is("form")
1122 * @before <form><p><input type="checkbox" /></p></form>
1124 * @desc Returns false, because the parent of the input is a p element
1126 * @example $("form").is(null)
1127 * @before <form></form>
1129 * @desc An invalid expression always returns false.
1131 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1132 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1133 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1134 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1135 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1136 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1137 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1138 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1139 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1140 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1141 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1142 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1143 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1144 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1145 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1146 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1147 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1148 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1149 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1150 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1151 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1152 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1156 * @param String expr The expression with which to filter
1157 * @cat DOM/Traversing
1159 is: function(expr) {
1160 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1169 * @param Boolean table
1171 * @param Function fn The function doing the DOM manipulation.
1175 domManip: function(args, table, dir, fn){
1176 var clone = this.size() > 1;
1177 var a = jQuery.clean(args);
1179 return this.each(function(){
1182 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
1183 var tbody = this.getElementsByTagName("tbody");
1185 if ( !tbody.length ) {
1186 obj = document.createElement("tbody");
1187 this.appendChild( obj );
1192 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1193 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1194 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1209 pushStack: function(a,args) {
1210 var fn = args && args[args.length-1];
1211 var fn2 = args && args[args.length-2];
1213 if ( fn && fn.constructor != Function ) fn = null;
1214 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1217 if ( !this.stack ) this.stack = [];
1218 this.stack.push( this.get() );
1221 var old = this.get();
1224 if ( fn2 && a.length || !fn2 )
1225 this.each( fn2 || fn ).get( old );
1227 this.get( old ).each( fn );
1235 * Extends the jQuery object itself. Can be used to add both static
1236 * functions and plugin methods.
1238 * @example $.fn.extend({
1239 * check: function() {
1240 * this.each(function() { this.checked = true; });
1242 * uncheck: function() {
1243 * this.each(function() { this.checked = false; });
1246 * $("input[@type=checkbox]").check();
1247 * $("input[@type=radio]").uncheck();
1248 * @desc Adds two plugin methods.
1258 * Extend one object with another, returning the original,
1259 * modified, object. This is a great utility for simple inheritance.
1261 * @example var settings = { validate: false, limit: 5, name: "foo" };
1262 * var options = { validate: true, name: "bar" };
1263 * jQuery.extend(settings, options);
1264 * @result settings == { validate: true, limit: 5, name: "bar" }
1266 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1267 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1268 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1269 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1270 * jQuery.extend(settings, options);
1271 * isSet( settings, merged, "Check if extended: settings must be extended" );
1272 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1275 * @param Object obj The object to extend
1276 * @param Object prop The object that will be merged into the first.
1280 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1281 if ( !prop ) { prop = obj; obj = this; }
1282 for ( var i in prop ) obj[i] = prop[i];
1294 jQuery.initDone = true;
1296 jQuery.each( jQuery.macros.axis, function(i,n){
1297 jQuery.fn[ i ] = function(a) {
1298 var ret = jQuery.map(this,n);
1299 if ( a && a.constructor == String )
1300 ret = jQuery.filter(a,ret).r;
1301 return this.pushStack( ret, arguments );
1305 jQuery.each( jQuery.macros.to, function(i,n){
1306 jQuery.fn[ i ] = function(){
1308 return this.each(function(){
1309 for ( var j = 0; j < a.length; j++ )
1310 jQuery(a[j])[n]( this );
1315 jQuery.each( jQuery.macros.each, function(i,n){
1316 jQuery.fn[ i ] = function() {
1317 return this.each( n, arguments );
1321 jQuery.each( jQuery.macros.filter, function(i,n){
1322 jQuery.fn[ n ] = function(num,fn) {
1323 return this.filter( ":" + n + "(" + num + ")", fn );
1327 jQuery.each( jQuery.macros.attr, function(i,n){
1329 jQuery.fn[ i ] = function(h) {
1330 return h == undefined ?
1331 this.length ? this[0][n] : null :
1336 jQuery.each( jQuery.macros.css, function(i,n){
1337 jQuery.fn[ n ] = function(h) {
1338 return h == undefined ?
1339 ( this.length ? jQuery.css( this[0], n ) : null ) :
1347 * A generic iterator function, which can be used to seemlessly
1348 * iterate over both objects and arrays. This function is not the same
1349 * as $().each() - which is used to iterate, exclusively, over a jQuery
1350 * object. This function can be used to iterate over anything.
1352 * @example $.each( [0,1,2], function(i){
1353 * alert( "Item #" + i + ": " + this );
1355 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1357 * @example $.each( { name: "John", lang: "JS" }, function(i){
1358 * alert( "Name: " + i + ", Value: " + this );
1360 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1363 * @param Object obj The object, or array, to iterate over.
1364 * @param Function fn The function that will be executed on every object.
1368 each: function( obj, fn, args ) {
1369 if ( obj.length == undefined )
1370 for ( var i in obj )
1371 fn.apply( obj[i], args || [i, obj[i]] );
1373 for ( var i = 0; i < obj.length; i++ )
1374 fn.apply( obj[i], args || [i, obj[i]] );
1380 if (jQuery.className.has(o,c)) return;
1381 o.className += ( o.className ? " " : "" ) + c;
1383 remove: function(o,c){
1385 o.className = !c ? "" :
1386 o.className.replace(
1387 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/
1391 var classes = o.className.split(" ");
1392 for(var i=0; i<classes.length; i++) {
1393 if(classes[i] == c) {
1394 classes.splice(i, 1);
1398 o.className = classes.join(' ');
1401 has: function(e,a) {
1402 if ( e.className != undefined )
1404 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1409 * Swap in/out style options.
1412 swap: function(e,o,f) {
1413 for ( var i in o ) {
1414 e.style["old"+i] = e.style[i];
1419 e.style[i] = e.style["old"+i];
1422 css: function(e,p) {
1423 if ( p == "height" || p == "width" ) {
1424 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1426 for ( var i in d ) {
1427 old["padding" + d[i]] = 0;
1428 old["border" + d[i] + "Width"] = 0;
1431 jQuery.swap( e, old, function() {
1432 if (jQuery.css(e,"display") != "none") {
1433 oHeight = e.offsetHeight;
1434 oWidth = e.offsetWidth;
1436 e = jQuery(e.cloneNode(true)).css({
1437 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1438 }).appendTo(e.parentNode)[0];
1440 var parPos = jQuery.css(e.parentNode,"position");
1441 if ( parPos == "" || parPos == "static" )
1442 e.parentNode.style.position = "relative";
1444 oHeight = e.clientHeight;
1445 oWidth = e.clientWidth;
1447 if ( parPos == "" || parPos == "static" )
1448 e.parentNode.style.position = "static";
1450 e.parentNode.removeChild(e);
1454 return p == "height" ? oHeight : oWidth;
1455 } else if ( p == "opacity" && jQuery.browser.msie )
1456 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1458 return jQuery.curCSS( e, p );
1461 curCSS: function(elem, prop, force) {
1464 if (!force && elem.style[prop]) {
1466 ret = elem.style[prop];
1468 } else if (elem.currentStyle) {
1470 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1471 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1473 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1475 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1476 var cur = document.defaultView.getComputedStyle(elem, null);
1479 ret = cur.getPropertyValue(prop);
1480 else if ( prop == 'display' )
1483 jQuery.swap(elem, { display: 'block' }, function() {
1484 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1492 clean: function(a) {
1494 for ( var i = 0; i < a.length; i++ ) {
1495 if ( a[i].constructor == String ) {
1499 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1501 a[i] = "<table>" + a[i] + "</table>";
1502 } else if ( !a[i].indexOf("<tr") ) {
1504 a[i] = "<table>" + a[i] + "</table>";
1505 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1507 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1510 var div = document.createElement("div");
1511 div.innerHTML = a[i];
1514 div = div.firstChild;
1515 if ( table != "thead" ) div = div.firstChild;
1516 if ( table == "td" ) div = div.firstChild;
1519 for ( var j = 0; j < div.childNodes.length; j++ )
1520 r.push( div.childNodes[j] );
1521 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1522 for ( var k = 0; k < a[i].length; k++ )
1524 else if ( a[i] !== null )
1525 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1531 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1532 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1540 last: "i==r.length-1",
1545 "nth-child": "jQuery.sibling(a,m[3]).cur",
1546 "first-child": "jQuery.sibling(a,0).cur",
1547 "last-child": "jQuery.sibling(a,0).last",
1548 "only-child": "jQuery.sibling(a).length==1",
1551 parent: "a.childNodes.length",
1552 empty: "!a.childNodes.length",
1555 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1558 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1559 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1562 enabled: "!a.disabled",
1563 disabled: "a.disabled",
1564 checked: "a.checked",
1565 selected: "a.selected",
1568 text: "a.type=='text'",
1569 radio: "a.type=='radio'",
1570 checkbox: "a.type=='checkbox'",
1571 file: "a.type=='file'",
1572 password: "a.type=='password'",
1573 submit: "a.type=='submit'",
1574 image: "a.type=='image'",
1575 reset: "a.type=='reset'",
1576 button: "a.type=='button'",
1577 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
1579 ".": "jQuery.className.has(a,m[2])",
1583 "^=": "z && !z.indexOf(m[4])",
1584 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1585 "*=": "z && z.indexOf(m[4])>=0",
1588 "[": "jQuery.find(m[2],a).length"
1592 "\\.\\.|/\\.\\.", "a.parentNode",
1593 ">|/", "jQuery.sibling(a.firstChild)",
1594 "\\+", "jQuery.sibling(a).next",
1597 var s = jQuery.sibling(a);
1599 for ( var i = s.n; i < s.length; i++ )
1607 * @test t( "Element Selector", "div", ["main","foo"] );
1608 * t( "Element Selector", "body", ["body"] );
1609 * t( "Element Selector", "html", ["html"] );
1610 * ok( $("*").size() >= 30, "Element Selector" );
1611 * t( "Parent Element", "div div", ["foo"] );
1613 * t( "ID Selector", "#body", ["body"] );
1614 * t( "ID Selector w/ Element", "body#body", ["body"] );
1615 * t( "ID Selector w/ Element", "ul#first", [] );
1617 * t( "Class Selector", ".blog", ["mark","simon"] );
1618 * t( "Class Selector", ".blog.link", ["simon"] );
1619 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1620 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1622 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1623 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1624 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1625 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1627 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1628 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1629 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1630 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1631 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1632 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1633 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1634 * t( "Adjacent", "a + a", ["groups"] );
1635 * t( "Adjacent", "a +a", ["groups"] );
1636 * t( "Adjacent", "a+ a", ["groups"] );
1637 * t( "Adjacent", "a+a", ["groups"] );
1638 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1639 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1640 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1641 * t( "Attribute Exists", "a[@title]", ["google"] );
1642 * t( "Attribute Exists", "*[@title]", ["google"] );
1643 * t( "Attribute Exists", "[@title]", ["google"] );
1645 * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] );
1646 * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
1647 * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] );
1649 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1650 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1651 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1652 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1653 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1654 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1656 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1657 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1658 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1659 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1660 * t( "Last Child", "p:last-child", ["sap"] );
1661 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1662 * t( "Empty", "ul:empty", ["firstUL"] );
1663 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1664 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1665 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1666 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1667 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1668 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1669 * t( "Element Preceded By", "p ~ div", ["foo"] );
1670 * t( "Not", "a.blog:not(.link)", ["mark"] );
1672 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1673 * t( "All Div Elements", "//div", ["main","foo"] );
1674 * t( "Absolute Path", "/html/body", ["body"] );
1675 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1676 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1677 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1678 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1679 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1680 * t( "Attribute Exists", "//a[@title]", ["google"] );
1681 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1682 * t( "Parent Axis", "//p/..", ["main","foo"] );
1683 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1684 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1685 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1687 * t( "nth Element", "p:nth(1)", ["ap"] );
1688 * t( "First Element", "p:first", ["firstp"] );
1689 * t( "Last Element", "p:last", ["first"] );
1690 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1691 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1692 * t( "Position Equals", "p:eq(1)", ["ap"] );
1693 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1694 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1695 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1696 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1697 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1699 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1701 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1702 * t( "All Children of ID with no children", "#firstUL/*", [] );
1704 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1705 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1706 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1707 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1708 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1709 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1710 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1712 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1713 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1714 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1717 * @type Array<Element>
1721 find: function( t, context ) {
1722 // Make sure that the context is a DOM Element
1723 if ( context && context.nodeType == undefined )
1726 // Set the correct context (if none is provided)
1727 context = context || jQuery.context || document;
1729 if ( t.constructor != String ) return [t];
1731 if ( !t.indexOf("//") ) {
1732 context = context.documentElement;
1733 t = t.substr(2,t.length);
1734 } else if ( !t.indexOf("/") ) {
1735 context = context.documentElement;
1736 t = t.substr(1,t.length);
1737 // FIX Assume the root element is right :(
1738 if ( t.indexOf("/") >= 1 )
1739 t = t.substr(t.indexOf("/"),t.length);
1742 var ret = [context];
1746 while ( t.length > 0 && last != t ) {
1750 t = jQuery.trim(t).replace( /^\/\//i, "" );
1752 var foundToken = false;
1754 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1755 if ( foundToken ) continue;
1757 var re = new RegExp("^(" + jQuery.token[i] + ")");
1761 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1762 t = jQuery.trim( t.replace( re, "" ) );
1767 if ( !foundToken ) {
1768 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1769 if ( ret[0] == context ) ret.shift();
1770 done = jQuery.merge( done, ret );
1771 r = ret = [context];
1772 t = " " + t.substr(1,t.length);
1774 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1775 var m = re2.exec(t);
1777 if ( m[1] == "#" ) {
1778 // Ummm, should make this work in all XML docs
1779 var oid = document.getElementById(m[2]);
1780 r = ret = oid ? [oid] : [];
1781 t = t.replace( re2, "" );
1783 if ( !m[2] || m[1] == "." ) m[2] = "*";
1785 for ( var i = 0; i < ret.length; i++ )
1786 r = jQuery.merge( r,
1788 jQuery.getAll(ret[i]) :
1789 ret[i].getElementsByTagName(m[2])
1797 var val = jQuery.filter(t,r);
1799 t = jQuery.trim(val.t);
1803 if ( ret && ret[0] == context ) ret.shift();
1804 done = jQuery.merge( done, ret );
1809 getAll: function(o,r) {
1811 var s = o.childNodes;
1812 for ( var i = 0; i < s.length; i++ )
1813 if ( s[i].nodeType == 1 ) {
1815 jQuery.getAll( s[i], r );
1820 attr: function(elem, name, value){
1823 "class": "className",
1824 "float": "cssFloat",
1825 innerHTML: "innerHTML",
1826 className: "className",
1828 disabled: "disabled",
1833 if ( value != undefined ) elem[fix[name]] = value;
1834 return elem[fix[name]];
1835 } else if( value == undefined && $.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1836 return elem.getAttributeNode(name).nodeValue;
1837 } else if ( elem.getAttribute != undefined ) {
1838 if ( value != undefined ) elem.setAttribute( name, value );
1839 return elem.getAttribute( name, 2 );
1841 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1842 if ( value != undefined ) elem[name] = value;
1847 // The regular expressions that power the parsing engine
1849 // Match: [@value='test'], [@foo]
1850 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1852 // Match: [div], [div p]
1853 "(\\[)\s*(.*?)\s*\\]",
1855 // Match: :contains('foo')
1856 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1858 // Match: :even, :last-chlid
1862 filter: function(t,r,not) {
1863 // Figure out if we're doing regular, or inverse, filtering
1864 var g = not !== false ? jQuery.grep :
1865 function(a,f) {return jQuery.grep(a,f,true);};
1867 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1869 var p = jQuery.parse;
1871 for ( var i = 0; i < p.length; i++ ) {
1873 // Look for, and replace, string-like sequences
1874 // and finally build a regexp out of it
1875 var re = new RegExp(
1876 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1878 var m = re.exec( t );
1881 // Re-organize the first match
1883 m = ["",m[1], m[3], m[2], m[5]];
1885 // Remove what we just matched
1886 t = t.replace( re, "" );
1892 // :not() is a special case that can be optimized by
1893 // keeping it out of the expression list
1894 if ( m[1] == ":" && m[2] == "not" )
1895 r = jQuery.filter(m[3],r,false).r;
1897 // Otherwise, find the expression to execute
1899 var f = jQuery.expr[m[1]];
1900 if ( f.constructor != String )
1901 f = jQuery.expr[m[1]][m[2]];
1903 // Build a custom macro to enclose it
1904 eval("f = function(a,i){" +
1905 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1906 "return " + f + "}");
1908 // Execute it against the current filter
1913 // Return an array of filtered elements (r)
1914 // and the modified expression string (t)
1915 return { r: r, t: t };
1919 * Remove the whitespace from the beginning and end of a string.
1921 * @example $.trim(" hello, how are you? ");
1922 * @result "hello, how are you?"
1926 * @param String str The string to trim.
1930 return t.replace(/^\s+|\s+$/g, "");
1934 * All ancestors of a given element.
1938 * @type Array<Element>
1939 * @param Element elem The element to find the ancestors of.
1940 * @cat DOM/Traversing
1942 parents: function( elem ){
1944 var cur = elem.parentNode;
1945 while ( cur && cur != document ) {
1946 matched.push( cur );
1947 cur = cur.parentNode;
1953 * All elements on a specified axis.
1958 * @param Element elem The element to find all the siblings of (including itself).
1959 * @cat DOM/Traversing
1961 sibling: function(elem, pos, not) {
1965 var siblings = elem.parentNode.childNodes;
1966 for ( var i = 0; i < siblings.length; i++ ) {
1967 if ( not === true && siblings[i] == elem ) continue;
1969 if ( siblings[i].nodeType == 1 )
1970 elems.push( siblings[i] );
1971 if ( siblings[i] == elem )
1972 elems.n = elems.length - 1;
1976 return jQuery.extend( elems, {
1977 last: elems.n == elems.length - 1,
1978 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1979 prev: elems[elems.n - 1],
1980 next: elems[elems.n + 1]
1985 * Merge two arrays together, removing all duplicates. The final order
1986 * or the new array is: All the results from the first array, followed
1987 * by the unique results from the second array.
1989 * @example $.merge( [0,1,2], [2,3,4] )
1990 * @result [0,1,2,3,4]
1992 * @example $.merge( [3,2,1], [4,3,2] )
1997 * @param Array first The first array to merge.
1998 * @param Array second The second array to merge.
2001 merge: function(first, second) {
2004 // Move b over to the new array (this helps to avoid
2005 // StaticNodeList instances)
2006 for ( var k = 0; k < first.length; k++ )
2007 result[k] = first[k];
2009 // Now check for duplicates between a and b and only
2010 // add the unique items
2011 for ( var i = 0; i < second.length; i++ ) {
2012 var noCollision = true;
2014 // The collision-checking process
2015 for ( var j = 0; j < first.length; j++ )
2016 if ( second[i] == first[j] )
2017 noCollision = false;
2019 // If the item is unique, add it
2021 result.push( second[i] );
2028 * Filter items out of an array, by using a filter function.
2029 * The specified function will be passed two arguments: The
2030 * current array item and the index of the item in the array. The
2031 * function should return 'true' if you wish to keep the item in
2032 * the array, false if it should be removed.
2034 * @example $.grep( [0,1,2], function(i){
2041 * @param Array array The Array to find items in.
2042 * @param Function fn The function to process each item against.
2043 * @param Boolean inv Invert the selection - select the opposite of the function.
2046 grep: function(elems, fn, inv) {
2047 // If a string is passed in for the function, make a function
2048 // for it (a handy shortcut)
2049 if ( fn.constructor == String )
2050 fn = new Function("a","i","return " + fn);
2054 // Go through the array, only saving the items
2055 // that pass the validator function
2056 for ( var i = 0; i < elems.length; i++ )
2057 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2058 result.push( elems[i] );
2064 * Translate all items in an array to another array of items.
2065 * The translation function that is provided to this method is
2066 * called for each item in the array and is passed one argument:
2067 * The item to be translated. The function can then return:
2068 * The translated value, 'null' (to remove the item), or
2069 * an array of values - which will be flattened into the full array.
2071 * @example $.map( [0,1,2], function(i){
2076 * @example $.map( [0,1,2], function(i){
2077 * return i > 0 ? i + 1 : null;
2081 * @example $.map( [0,1,2], function(i){
2082 * return [ i, i + 1 ];
2084 * @result [0, 1, 1, 2, 2, 3]
2088 * @param Array array The Array to translate.
2089 * @param Function fn The function to process each item against.
2092 map: function(elems, fn) {
2093 // If a string is passed in for the function, make a function
2094 // for it (a handy shortcut)
2095 if ( fn.constructor == String )
2096 fn = new Function("a","return " + fn);
2100 // Go through the array, translating each of the items to their
2101 // new value (or values).
2102 for ( var i = 0; i < elems.length; i++ ) {
2103 var val = fn(elems[i],i);
2105 if ( val !== null && val != undefined ) {
2106 if ( val.constructor != Array ) val = [val];
2107 result = jQuery.merge( result, val );
2115 * A number of helper functions used for managing events.
2116 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2120 // Bind an event to an element
2121 // Original by Dean Edwards
2122 add: function(element, type, handler) {
2123 // For whatever reason, IE has trouble passing the window object
2124 // around, causing it to be cloned in the process
2125 if ( jQuery.browser.msie && element.setInterval != undefined )
2128 // Make sure that the function being executed has a unique ID
2129 if ( !handler.guid )
2130 handler.guid = this.guid++;
2132 // Init the element's event structure
2133 if (!element.events)
2134 element.events = {};
2136 // Get the current list of functions bound to this event
2137 var handlers = element.events[type];
2139 // If it hasn't been initialized yet
2141 // Init the event handler queue
2142 handlers = element.events[type] = {};
2144 // Remember an existing handler, if it's already there
2145 if (element["on" + type])
2146 handlers[0] = element["on" + type];
2149 // Add the function to the element's handler list
2150 handlers[handler.guid] = handler;
2152 // And bind the global event handler to the element
2153 element["on" + type] = this.handle;
2155 // Remember the function in a global list (for triggering)
2156 if (!this.global[type])
2157 this.global[type] = [];
2158 this.global[type].push( element );
2164 // Detach an event or set of events from an element
2165 remove: function(element, type, handler) {
2167 if (type && element.events[type])
2169 delete element.events[type][handler.guid];
2171 for ( var i in element.events[type] )
2172 delete element.events[type][i];
2174 for ( var j in element.events )
2175 this.remove( element, j );
2178 trigger: function(type,data,element) {
2179 // Touch up the incoming data
2182 // Handle a global trigger
2184 var g = this.global[type];
2186 for ( var i = 0; i < g.length; i++ )
2187 this.trigger( type, data, g[i] );
2189 // Handle triggering a single element
2190 } else if ( element["on" + type] ) {
2191 // Pass along a fake event
2192 data.unshift( this.fix({ type: type, target: element }) );
2194 // Trigger the event
2195 element["on" + type].apply( element, data );
2199 handle: function(event) {
2200 if ( typeof jQuery == "undefined" ) return;
2202 event = event || jQuery.event.fix( window.event );
2204 // If no correct event was found, fail
2205 if ( !event ) return;
2207 var returnValue = true;
2209 var c = this.events[event.type];
2211 var args = [].slice.call( arguments, 1 );
2212 args.unshift( event );
2214 for ( var j in c ) {
2215 if ( c[j].apply( this, args ) === false ) {
2216 event.preventDefault();
2217 event.stopPropagation();
2218 returnValue = false;
2225 fix: function(event) {
2227 event.preventDefault = function() {
2228 this.returnValue = false;
2231 event.stopPropagation = function() {
2232 this.cancelBubble = true;
2243 * Contains flags for the useragent, read from navigator.userAgent.
2244 * Available flags are: safari, opera, msie, mozilla
2245 * This property is available before the DOM is ready, therefore you can
2246 * use it to add ready events only for certain browsers.
2248 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2249 * jQBrowser plugin</a> for advanced browser detection:
2251 * @example $.browser.msie
2252 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2254 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2255 * @desc Alerts "this is safari!" only for safari browsers
2262 var b = navigator.userAgent.toLowerCase();
2264 // Figure out what browser is being used
2266 safari: /webkit/.test(b),
2267 opera: /opera/.test(b),
2268 msie: /msie/.test(b) && !/opera/.test(b),
2269 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2272 // Check to see if the W3C box model is being used
2273 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2279 * Append all of the matched elements to another, specified, set of elements.
2280 * This operation is, essentially, the reverse of doing a regular
2281 * $(A).append(B), in that instead of appending B to A, you're appending
2284 * @example $("p").appendTo("#foo");
2285 * @before <p>I would like to say: </p><div id="foo"></div>
2286 * @result <div id="foo"><p>I would like to say: </p></div>
2290 * @param String expr A jQuery expression of elements to match.
2291 * @cat DOM/Manipulation
2296 * Prepend all of the matched elements to another, specified, set of elements.
2297 * This operation is, essentially, the reverse of doing a regular
2298 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2301 * @example $("p").prependTo("#foo");
2302 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2303 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2307 * @param String expr A jQuery expression of elements to match.
2308 * @cat DOM/Manipulation
2310 prependTo: "prepend",
2313 * Insert all of the matched elements before another, specified, set of elements.
2314 * This operation is, essentially, the reverse of doing a regular
2315 * $(A).before(B), in that instead of inserting B before A, you're inserting
2318 * @example $("p").insertBefore("#foo");
2319 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2320 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2322 * @name insertBefore
2324 * @param String expr A jQuery expression of elements to match.
2325 * @cat DOM/Manipulation
2327 insertBefore: "before",
2330 * Insert all of the matched elements after another, specified, set of elements.
2331 * This operation is, essentially, the reverse of doing a regular
2332 * $(A).after(B), in that instead of inserting B after A, you're inserting
2335 * @example $("p").insertAfter("#foo");
2336 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2337 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2341 * @param String expr A jQuery expression of elements to match.
2342 * @cat DOM/Manipulation
2344 insertAfter: "after"
2348 * Get the current CSS width of the first matched element.
2350 * @example $("p").width();
2351 * @before <p>This is just a test.</p>
2360 * Set the CSS width of every matched element. Be sure to include
2361 * the "px" (or other unit of measurement) after the number that you
2362 * specify, otherwise you might get strange results.
2364 * @example $("p").width("20px");
2365 * @before <p>This is just a test.</p>
2366 * @result <p style="width:20px;">This is just a test.</p>
2370 * @param String val Set the CSS property to the specified value.
2375 * Get the current CSS height of the first matched element.
2377 * @example $("p").height();
2378 * @before <p>This is just a test.</p>
2387 * Set the CSS height of every matched element. Be sure to include
2388 * the "px" (or other unit of measurement) after the number that you
2389 * specify, otherwise you might get strange results.
2391 * @example $("p").height("20px");
2392 * @before <p>This is just a test.</p>
2393 * @result <p style="height:20px;">This is just a test.</p>
2397 * @param String val Set the CSS property to the specified value.
2402 * Get the current CSS top of the first matched element.
2404 * @example $("p").top();
2405 * @before <p>This is just a test.</p>
2414 * Set the CSS top of every matched element. Be sure to include
2415 * the "px" (or other unit of measurement) after the number that you
2416 * specify, otherwise you might get strange results.
2418 * @example $("p").top("20px");
2419 * @before <p>This is just a test.</p>
2420 * @result <p style="top:20px;">This is just a test.</p>
2424 * @param String val Set the CSS property to the specified value.
2429 * Get the current CSS left of the first matched element.
2431 * @example $("p").left();
2432 * @before <p>This is just a test.</p>
2441 * Set the CSS left of every matched element. Be sure to include
2442 * the "px" (or other unit of measurement) after the number that you
2443 * specify, otherwise you might get strange results.
2445 * @example $("p").left("20px");
2446 * @before <p>This is just a test.</p>
2447 * @result <p style="left:20px;">This is just a test.</p>
2451 * @param String val Set the CSS property to the specified value.
2456 * Get the current CSS position of the first matched element.
2458 * @example $("p").position();
2459 * @before <p>This is just a test.</p>
2468 * Set the CSS position of every matched element.
2470 * @example $("p").position("relative");
2471 * @before <p>This is just a test.</p>
2472 * @result <p style="position:relative;">This is just a test.</p>
2476 * @param String val Set the CSS property to the specified value.
2481 * Get the current CSS float of the first matched element.
2483 * @example $("p").float();
2484 * @before <p>This is just a test.</p>
2493 * Set the CSS float of every matched element.
2495 * @example $("p").float("left");
2496 * @before <p>This is just a test.</p>
2497 * @result <p style="float:left;">This is just a test.</p>
2501 * @param String val Set the CSS property to the specified value.
2506 * Get the current CSS overflow of the first matched element.
2508 * @example $("p").overflow();
2509 * @before <p>This is just a test.</p>
2518 * Set the CSS overflow of every matched element.
2520 * @example $("p").overflow("auto");
2521 * @before <p>This is just a test.</p>
2522 * @result <p style="overflow:auto;">This is just a test.</p>
2526 * @param String val Set the CSS property to the specified value.
2531 * Get the current CSS color of the first matched element.
2533 * @example $("p").color();
2534 * @before <p>This is just a test.</p>
2543 * Set the CSS color of every matched element.
2545 * @example $("p").color("blue");
2546 * @before <p>This is just a test.</p>
2547 * @result <p style="color:blue;">This is just a test.</p>
2551 * @param String val Set the CSS property to the specified value.
2556 * Get the current CSS background of the first matched element.
2558 * @example $("p").background();
2559 * @before <p style="background:blue;">This is just a test.</p>
2568 * Set the CSS background of every matched element.
2570 * @example $("p").background("blue");
2571 * @before <p>This is just a test.</p>
2572 * @result <p style="background:blue;">This is just a test.</p>
2576 * @param String val Set the CSS property to the specified value.
2580 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2583 * Reduce the set of matched elements to a single element.
2584 * The position of the element in the set of matched elements
2585 * starts at 0 and goes to length - 1.
2587 * @example $("p").eq(1)
2588 * @before <p>This is just a test.</p><p>So is this</p>
2589 * @result [ <p>So is this</p> ]
2593 * @param Number pos The index of the element that you wish to limit to.
2598 * Reduce the set of matched elements to all elements before a given position.
2599 * The position of the element in the set of matched elements
2600 * starts at 0 and goes to length - 1.
2602 * @example $("p").lt(1)
2603 * @before <p>This is just a test.</p><p>So is this</p>
2604 * @result [ <p>This is just a test.</p> ]
2608 * @param Number pos Reduce the set to all elements below this position.
2613 * Reduce the set of matched elements to all elements after a given position.
2614 * The position of the element in the set of matched elements
2615 * starts at 0 and goes to length - 1.
2617 * @example $("p").gt(0)
2618 * @before <p>This is just a test.</p><p>So is this</p>
2619 * @result [ <p>So is this</p> ]
2623 * @param Number pos Reduce the set to all elements after this position.
2628 * Filter the set of elements to those that contain the specified text.
2630 * @example $("p").contains("test")
2631 * @before <p>This is just a test.</p><p>So is this</p>
2632 * @result [ <p>This is just a test.</p> ]
2636 * @param String str The string that will be contained within the text of an element.
2637 * @cat DOM/Traversing
2640 filter: [ "eq", "lt", "gt", "contains" ],
2644 * Get the current value of the first matched element.
2646 * @example $("input").val();
2647 * @before <input type="text" value="some text"/>
2648 * @result "some text"
2650 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2651 * ok( !$("#text1").val() == "", "Check for value of input element" );
2655 * @cat DOM/Attributes
2659 * Set the value of every matched element.
2661 * @example $("input").value("test");
2662 * @before <input type="text" value="some text"/>
2663 * @result <input type="text" value="test"/>
2665 * @test document.getElementById('text1').value = "bla";
2666 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2667 * $("#text1").val('test');
2668 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2672 * @param String val Set the property to the specified value.
2673 * @cat DOM/Attributes
2678 * Get the html contents of the first matched element.
2680 * @example $("div").html();
2681 * @before <div><input/></div>
2686 * @cat DOM/Attributes
2690 * Set the html contents of every matched element.
2692 * @example $("div").html("<b>new stuff</b>");
2693 * @before <div><input/></div>
2694 * @result <div><b>new stuff</b></div>
2696 * @test var div = $("div");
2697 * div.html("<b>test</b>");
2699 * for ( var i = 0; i < div.size(); i++ ) {
2700 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2702 * ok( pass, "Set HTML" );
2706 * @param String val Set the html contents to the specified value.
2707 * @cat DOM/Attributes
2712 * Get the current id of the first matched element.
2714 * @example $("input").id();
2715 * @before <input type="text" id="test" value="some text"/>
2718 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2719 * ok( $("#foo").id() == "foo", "Check for id" );
2720 * ok( !$("head").id(), "Check for id" );
2724 * @cat DOM/Attributes
2728 * Set the id of every matched element.
2730 * @example $("input").id("newid");
2731 * @before <input type="text" id="test" value="some text"/>
2732 * @result <input type="text" id="newid" value="some text"/>
2736 * @param String val Set the property to the specified value.
2737 * @cat DOM/Attributes
2742 * Get the current title of the first matched element.
2744 * @example $("img").title();
2745 * @before <img src="test.jpg" title="my image"/>
2746 * @result "my image"
2748 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2749 * ok( !$("#yahoo").title(), "Check for title" );
2753 * @cat DOM/Attributes
2757 * Set the title of every matched element.
2759 * @example $("img").title("new title");
2760 * @before <img src="test.jpg" title="my image"/>
2761 * @result <img src="test.jpg" title="new image"/>
2765 * @param String val Set the property to the specified value.
2766 * @cat DOM/Attributes
2771 * Get the current name of the first matched element.
2773 * @example $("input").name();
2774 * @before <input type="text" name="username"/>
2775 * @result "username"
2777 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2778 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2779 * ok( !$("#area1").name(), "Check for name" );
2783 * @cat DOM/Attributes
2787 * Set the name of every matched element.
2789 * @example $("input").name("user");
2790 * @before <input type="text" name="username"/>
2791 * @result <input type="text" name="user"/>
2795 * @param String val Set the property to the specified value.
2796 * @cat DOM/Attributes
2801 * Get the current href of the first matched element.
2803 * @example $("a").href();
2804 * @before <a href="test.html">my link</a>
2805 * @result "test.html"
2809 * @cat DOM/Attributes
2813 * Set the href of every matched element.
2815 * @example $("a").href("test2.html");
2816 * @before <a href="test.html">my link</a>
2817 * @result <a href="test2.html">my link</a>
2821 * @param String val Set the property to the specified value.
2822 * @cat DOM/Attributes
2827 * Get the current src of the first matched element.
2829 * @example $("img").src();
2830 * @before <img src="test.jpg" title="my image"/>
2831 * @result "test.jpg"
2835 * @cat DOM/Attributes
2839 * Set the src of every matched element.
2841 * @example $("img").src("test2.jpg");
2842 * @before <img src="test.jpg" title="my image"/>
2843 * @result <img src="test2.jpg" title="my image"/>
2847 * @param String val Set the property to the specified value.
2848 * @cat DOM/Attributes
2853 * Get the current rel of the first matched element.
2855 * @example $("a").rel();
2856 * @before <a href="test.html" rel="nofollow">my link</a>
2857 * @result "nofollow"
2861 * @cat DOM/Attributes
2865 * Set the rel of every matched element.
2867 * @example $("a").rel("nofollow");
2868 * @before <a href="test.html">my link</a>
2869 * @result <a href="test.html" rel="nofollow">my link</a>
2873 * @param String val Set the property to the specified value.
2874 * @cat DOM/Attributes
2881 * Get a set of elements containing the unique parents of the matched
2884 * @example $("p").parent()
2885 * @before <div><p>Hello</p><p>Hello</p></div>
2886 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2890 * @cat DOM/Traversing
2894 * Get a set of elements containing the unique parents of the matched
2895 * set of elements, and filtered by an expression.
2897 * @example $("p").parent(".selected")
2898 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2899 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2903 * @param String expr An expression to filter the parents with
2904 * @cat DOM/Traversing
2906 parent: "a.parentNode",
2909 * Get a set of elements containing the unique ancestors of the matched
2910 * set of elements (except for the root element).
2912 * @example $("span").ancestors()
2913 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2914 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2918 * @cat DOM/Traversing
2922 * Get a set of elements containing the unique ancestors of the matched
2923 * set of elements, and filtered by an expression.
2925 * @example $("span").ancestors("p")
2926 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2927 * @result [ <p><span>Hello</span></p> ]
2931 * @param String expr An expression to filter the ancestors with
2932 * @cat DOM/Traversing
2934 ancestors: jQuery.parents,
2937 * Get a set of elements containing the unique ancestors of the matched
2938 * set of elements (except for the root element).
2940 * @example $("span").ancestors()
2941 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2942 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2946 * @cat DOM/Traversing
2950 * Get a set of elements containing the unique ancestors of the matched
2951 * set of elements, and filtered by an expression.
2953 * @example $("span").ancestors("p")
2954 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2955 * @result [ <p><span>Hello</span></p> ]
2959 * @param String expr An expression to filter the ancestors with
2960 * @cat DOM/Traversing
2962 parents: jQuery.parents,
2965 * Get a set of elements containing the unique next siblings of each of the
2966 * matched set of elements.
2968 * It only returns the very next sibling, not all next siblings.
2970 * @example $("p").next()
2971 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2972 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2976 * @cat DOM/Traversing
2980 * Get a set of elements containing the unique next siblings of each of the
2981 * matched set of elements, and filtered by an expression.
2983 * It only returns the very next sibling, not all next siblings.
2985 * @example $("p").next(".selected")
2986 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2987 * @result [ <p class="selected">Hello Again</p> ]
2991 * @param String expr An expression to filter the next Elements with
2992 * @cat DOM/Traversing
2994 next: "jQuery.sibling(a).next",
2997 * Get a set of elements containing the unique previous siblings of each of the
2998 * matched set of elements.
3000 * It only returns the immediately previous sibling, not all previous siblings.
3002 * @example $("p").prev()
3003 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3004 * @result [ <div><span>Hello Again</span></div> ]
3008 * @cat DOM/Traversing
3012 * Get a set of elements containing the unique previous siblings of each of the
3013 * matched set of elements, and filtered by an expression.
3015 * It only returns the immediately previous sibling, not all previous siblings.
3017 * @example $("p").previous(".selected")
3018 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3019 * @result [ <div><span>Hello</span></div> ]
3023 * @param String expr An expression to filter the previous Elements with
3024 * @cat DOM/Traversing
3026 prev: "jQuery.sibling(a).prev",
3029 * Get a set of elements containing all of the unique siblings of each of the
3030 * matched set of elements.
3032 * @example $("div").siblings()
3033 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3034 * @result [ <p>Hello</p>, <p>And Again</p> ]
3036 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3040 * @cat DOM/Traversing
3044 * Get a set of elements containing all of the unique siblings of each of the
3045 * matched set of elements, and filtered by an expression.
3047 * @example $("div").siblings(".selected")
3048 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3049 * @result [ <p class="selected">Hello Again</p> ]
3051 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3052 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3056 * @param String expr An expression to filter the sibling Elements with
3057 * @cat DOM/Traversing
3059 siblings: "jQuery.sibling(a, null, true)",
3063 * Get a set of elements containing all of the unique children of each of the
3064 * matched set of elements.
3066 * @example $("div").children()
3067 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3068 * @result [ <span>Hello Again</span> ]
3070 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3074 * @cat DOM/Traversing
3078 * Get a set of elements containing all of the unique children of each of the
3079 * matched set of elements, and filtered by an expression.
3081 * @example $("div").children(".selected")
3082 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3083 * @result [ <p class="selected">Hello Again</p> ]
3085 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3089 * @param String expr An expression to filter the child Elements with
3090 * @cat DOM/Traversing
3092 children: "jQuery.sibling(a.firstChild)"
3098 * Remove an attribute from each of the matched elements.
3100 * @example $("input").removeAttr("disabled")
3101 * @before <input disabled="disabled"/>
3106 * @param String name The name of the attribute to remove.
3109 removeAttr: function( key ) {
3110 this.removeAttribute( key );
3114 * Displays each of the set of matched elements if they are hidden.
3116 * @example $("p").show()
3117 * @before <p style="display: none">Hello</p>
3118 * @result [ <p style="display: block">Hello</p> ]
3120 * @test var pass = true, div = $("div");
3121 * div.show().each(function(){
3122 * if ( this.style.display == "none" ) pass = false;
3124 * ok( pass, "Show" );
3131 this.style.display = this.oldblock ? this.oldblock : "";
3132 if ( jQuery.css(this,"display") == "none" )
3133 this.style.display = "block";
3137 * Hides each of the set of matched elements if they are shown.
3139 * @example $("p").hide()
3140 * @before <p>Hello</p>
3141 * @result [ <p style="display: none">Hello</p> ]
3143 * var pass = true, div = $("div");
3144 * div.hide().each(function(){
3145 * if ( this.style.display != "none" ) pass = false;
3147 * ok( pass, "Hide" );
3154 this.oldblock = this.oldblock || jQuery.css(this,"display");
3155 if ( this.oldblock == "none" )
3156 this.oldblock = "block";
3157 this.style.display = "none";
3161 * Toggles each of the set of matched elements. If they are shown,
3162 * toggle makes them hidden. If they are hidden, toggle
3165 * @example $("p").toggle()
3166 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3167 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3174 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3178 * Adds the specified class to each of the set of matched elements.
3180 * @example $("p").addClass("selected")
3181 * @before <p>Hello</p>
3182 * @result [ <p class="selected">Hello</p> ]
3184 * @test var div = $("div");
3185 * div.addClass("test");
3187 * for ( var i = 0; i < div.size(); i++ ) {
3188 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3190 * ok( pass, "Add Class" );
3194 * @param String class A CSS class to add to the elements
3197 addClass: function(c){
3198 jQuery.className.add(this,c);
3202 * Removes the specified class from the set of matched elements.
3204 * @example $("p").removeClass("selected")
3205 * @before <p class="selected">Hello</p>
3206 * @result [ <p>Hello</p> ]
3208 * @test var div = $("div").addClass("test");
3209 * div.removeClass("test");
3211 * for ( var i = 0; i < div.size(); i++ ) {
3212 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3214 * ok( pass, "Remove Class" );
3218 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3219 * div.removeClass("test").removeClass("bar").removeClass("foo");
3221 * for ( var i = 0; i < div.size(); i++ ) {
3222 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3224 * ok( pass, "Remove multiple classes" );
3228 * @param String class A CSS class to remove from the elements
3231 removeClass: function(c){
3232 jQuery.className.remove(this,c);
3236 * Adds the specified class if it is present, removes it if it is
3239 * @example $("p").toggleClass("selected")
3240 * @before <p>Hello</p><p class="selected">Hello Again</p>
3241 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3245 * @param String class A CSS class with which to toggle the elements
3248 toggleClass: function( c ){
3249 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3253 * Removes all matched elements from the DOM. This does NOT remove them from the
3254 * jQuery object, allowing you to use the matched elements further.
3256 * @example $("p").remove();
3257 * @before <p>Hello</p> how are <p>you?</p>
3262 * @cat DOM/Manipulation
3266 * Removes only elements (out of the list of matched elements) that match
3267 * the specified jQuery expression. This does NOT remove them from the
3268 * jQuery object, allowing you to use the matched elements further.
3270 * @example $("p").remove(".hello");
3271 * @before <p class="hello">Hello</p> how are <p>you?</p>
3272 * @result how are <p>you?</p>
3276 * @param String expr A jQuery expression to filter elements by.
3277 * @cat DOM/Manipulation
3279 remove: function(a){
3280 if ( !a || jQuery.filter( a, [this] ).r )
3281 this.parentNode.removeChild( this );
3285 * Removes all child nodes from the set of matched elements.
3287 * @example $("p").empty()
3288 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3289 * @result [ <p></p> ]
3293 * @cat DOM/Manipulation
3296 while ( this.firstChild )
3297 this.removeChild( this.firstChild );
3301 * Binds a handler to a particular event (like click) for each matched element.
3302 * The event handler is passed an event object that you can use to prevent
3303 * default behaviour. To stop both default action and event bubbling, your handler
3304 * has to return false.
3306 * @example $("p").bind( "click", function() {
3307 * alert( $(this).text() );
3309 * @before <p>Hello</p>
3310 * @result alert("Hello")
3312 * @example $("form").bind( "submit", function() { return false; } )
3313 * @desc Cancel a default action and prevent it from bubbling by returning false
3314 * from your function.
3316 * @example $("form").bind( "submit", function(event) {
3317 * event.preventDefault();
3319 * @desc Cancel only the default action by using the preventDefault method.
3322 * @example $("form").bind( "submit", function(event) {
3323 * event.stopPropagation();
3325 * @desc Stop only an event from bubbling by using the stopPropagation method.
3329 * @param String type An event type
3330 * @param Function fn A function to bind to the event on each of the set of matched elements
3333 bind: function( type, fn ) {
3334 if ( fn.constructor == String )
3335 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3336 jQuery.event.add( this, type, fn );
3340 * The opposite of bind, removes a bound event from each of the matched
3341 * elements. You must pass the identical function that was used in the original
3344 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3345 * @before <p onclick="alert('Hello');">Hello</p>
3346 * @result [ <p>Hello</p> ]
3350 * @param String type An event type
3351 * @param Function fn A function to unbind from the event on each of the set of matched elements
3356 * Removes all bound events of a particular type from each of the matched
3359 * @example $("p").unbind( "click" )
3360 * @before <p onclick="alert('Hello');">Hello</p>
3361 * @result [ <p>Hello</p> ]
3365 * @param String type An event type
3370 * Removes all bound events from each of the matched elements.
3372 * @example $("p").unbind()
3373 * @before <p onclick="alert('Hello');">Hello</p>
3374 * @result [ <p>Hello</p> ]
3380 unbind: function( type, fn ) {
3381 jQuery.event.remove( this, type, fn );
3385 * Trigger a type of event on every matched element.
3387 * @example $("p").trigger("click")
3388 * @before <p click="alert('hello')">Hello</p>
3389 * @result alert('hello')
3393 * @param String type An event type to trigger.
3396 trigger: function( type, data ) {
3397 jQuery.event.trigger( type, data, this );