2 * jQuery @VERSION - 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,
99 * and appends it to the element with the ID of body. Internally, an
100 * element is created and it's innerHTML property set to the given markup.
101 * It is therefore both quite flexible and limited.
104 * @param String expr An expression to search with, or a string of HTML to create on the fly.
110 * This function accepts a string containing a CSS selector, or
111 * basic XPath, which is then used to match a set of elements with the
112 * context of the specified DOM element, or document
114 * @example $("div", xml.responseXML)
115 * @desc This finds all div elements within the specified XML document.
118 * @param String expr An expression to search with.
119 * @param Element context A DOM Element, or Document, representing the base context.
125 * Wrap jQuery functionality around a specific DOM Element.
126 * This function also accepts XML Documents and Window objects
127 * as valid arguments (even though they are not DOM Elements).
129 * @example $(document).find("div > p")
130 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
131 * @result [ <p>two</p> ]
133 * @example $(document.body).background( "black" );
134 * @desc Sets the background color of the page to black.
137 * @param Element elem A DOM element to be encapsulated by a jQuery object.
143 * Wrap jQuery functionality around a set of DOM Elements.
145 * @example $( myForm.elements ).hide()
146 * @desc Hides all the input elements within a form
149 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
155 * A shorthand for $(document).ready(), allowing you to bind a function
156 * to be executed when the DOM document has finished loading. This function
157 * behaves just like $(document).ready(), in that it should be used to wrap
158 * all of the other $() operations on your page. While this function is,
159 * technically, chainable - there really isn't much use for chaining against it.
160 * You can have as many $(document).ready events on your page as you like.
162 * @example $(function(){
163 * // Document is ready
165 * @desc Executes the function when the DOM is ready to be used.
168 * @param Function fn The function to execute when the DOM is ready.
174 * A means of creating a cloned copy of a jQuery object. This function
175 * copies the set of matched elements from one jQuery object and creates
176 * another, new, jQuery object containing the same elements.
178 * @example var div = $("div");
179 * $( div ).find("p");
180 * @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).
183 * @param jQuery obj The jQuery object to be cloned.
188 // Map the jQuery namespace to the '$' one
191 jQuery.fn = jQuery.prototype = {
193 * The current version of jQuery.
204 * The number of elements currently matched.
206 * @example $("img").length;
207 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
210 * @test ok( $("div").length == 2, "Get Number of Elements Found" );
219 * The number of elements currently matched.
221 * @example $("img").size();
222 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
225 * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
236 * Access all matched elements. This serves as a backwards-compatible
237 * way of accessing all matched elements (other than the jQuery object
238 * itself, which is, in fact, an array of elements).
240 * @example $("img").get();
241 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
242 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
244 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
247 * @type Array<Element>
252 * Access a single matched element. num is used to access the
253 * Nth element matched.
255 * @example $("img").get(1);
256 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
257 * @result [ <img src="test1.jpg"/> ]
259 * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
263 * @param Number num Access the element in the Nth position.
268 * Set the jQuery object to an array of elements.
270 * @example $("img").get([ document.body ]);
271 * @result $("img").get() == [ document.body ]
276 * @param Elements elems An array of elements
279 get: function( num ) {
280 // Watch for when an array (of elements) is passed in
281 if ( num && num.constructor == Array ) {
283 // Use a tricky hack to make the jQuery object
284 // look and feel like an array
286 [].push.apply( this, num );
290 return num == undefined ?
292 // Return a 'clean' array
293 jQuery.merge( this, [] ) :
295 // Return just the object
300 * Execute a function within the context of every matched element.
301 * This means that every time the passed-in function is executed
302 * (which is once for every element matched) the 'this' keyword
303 * points to the specific element.
305 * Additionally, the function, when executed, is passed a single
306 * argument representing the position of the element in the matched
309 * @example $("img").each(function(){
310 * this.src = "test.jpg";
312 * @before <img/> <img/>
313 * @result <img src="test.jpg"/> <img src="test.jpg"/>
315 * @example $("img").each(function(i){
316 * alert( "Image #" + i + " is " + this );
318 * @before <img/> <img/>
319 * @result <img src="test.jpg"/> <img src="test.jpg"/>
321 * @test var div = $("div");
322 * div.each(function(){this.foo = 'zoo';});
324 * for ( var i = 0; i < div.size(); i++ ) {
325 * if ( div.get(i).foo != "zoo" ) pass = false;
327 * ok( pass, "Execute a function, Relative" );
331 * @param Function fn A function to execute
334 each: function( fn, args ) {
335 return jQuery.each( this, fn, args );
339 * Searches every matched element for the object and returns
340 * the index of the element, if found, starting with zero.
341 * Returns -1 if the object wasn't found.
343 * @example $("*").index(document.getElementById('foobar'))
344 * @before <div id="foobar"></div><b></b><span id="foo"></span>
347 * @example $("*").index(document.getElementById('foo'))
348 * @before <div id="foobar"></div><b></b><span id="foo"></span>
351 * @example $("*").index(document.getElementById('bar'))
352 * @before <div id="foobar"></div><b></b><span id="foo"></span>
355 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
356 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
357 * var inputElements = $('#radio1,#radio2,#check1,#check2');
358 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
359 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
360 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
361 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
362 * ok( inputElements.index(window) == -1, "Check for not found index" );
363 * ok( inputElements.index(document) == -1, "Check for not found index" );
367 * @param Object obj Object to search for
370 index: function( obj ) {
372 this.each(function(i){
373 if ( this == obj ) pos = i;
379 * Access a property on the first matched element.
380 * This method makes it easy to retrieve a property value
381 * from the first matched element.
383 * @example $("img").attr("src");
384 * @before <img src="test.jpg"/>
387 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
388 * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
389 * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
390 * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
391 * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
392 * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
393 * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
394 * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
395 * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
396 * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
397 * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
398 * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
402 * @param String name The name of the property to access.
407 * Set a hash of key/value object properties to all matched elements.
408 * This serves as the best way to set a large number of properties
409 * on all matched elements.
411 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
413 * @result <img src="test.jpg" alt="Test Image"/>
415 * @test var pass = true;
416 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
417 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
419 * ok( pass, "Set Multiple Attributes" );
423 * @param Hash prop A set of key/value pairs to set as object properties.
428 * Set a single property to a value, on all matched elements.
430 * @example $("img").attr("src","test.jpg");
432 * @result <img src="test.jpg"/>
434 * @test var div = $("div");
435 * div.attr("foo", "bar");
437 * for ( var i = 0; i < div.size(); i++ ) {
438 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
440 * ok( pass, "Set Attribute" );
442 * $("#name").attr('name', 'something');
443 * ok( $("#name").name() == 'something', 'Set name attribute' );
444 * $("#check2").attr('checked', true);
445 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
446 * $("#check2").attr('checked', false);
447 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
451 * @param String key The name of the property to set.
452 * @param Object value The value to set the property to.
455 attr: function( key, value, type ) {
456 // Check to see if we're setting style values
457 return key.constructor != String || value != undefined ?
458 this.each(function(){
459 // See if we're setting a hash of styles
460 if ( value == undefined )
461 // Set all the styles
462 for ( var prop in key )
464 type ? this.style : this,
468 // See if we're setting a single key/value style
471 type ? this.style : this,
476 // Look for the case where we're accessing a style value
477 jQuery[ type || "attr" ]( this[0], key );
481 * Access a style property on the first matched element.
482 * This method makes it easy to retrieve a style property value
483 * from the first matched element.
485 * @example $("p").css("color");
486 * @before <p style="color:red;">Test Paragraph.</p>
488 * @desc Retrieves the color style of the first paragraph
490 * @example $("p").css("fontWeight");
491 * @before <p style="font-weight: bold;">Test Paragraph.</p>
493 * @desc Retrieves the font-weight style of the first paragraph.
494 * Note that for all style properties with a dash (like 'font-weight'), you have to
495 * write it in camelCase. In other words: Every time you have a '-' in a
496 * property, remove it and replace the next character with an uppercase
497 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
498 * borderStyle, borderBottomWidth etc.
500 * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
504 * @param String name The name of the property to access.
509 * Set a hash of key/value style properties to all matched elements.
510 * This serves as the best way to set a large number of style properties
511 * on all matched elements.
513 * @example $("p").css({ color: "red", background: "blue" });
514 * @before <p>Test Paragraph.</p>
515 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
517 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
518 * $('#foo').css({display: 'none'});
519 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
520 * $('#foo').css({display: 'block'});
521 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
525 * @param Hash prop A set of key/value pairs to set as style properties.
530 * Set a single style property to a value, on all matched elements.
532 * @example $("p").css("color","red");
533 * @before <p>Test Paragraph.</p>
534 * @result <p style="color:red;">Test Paragraph.</p>
535 * @desc Changes the color of all paragraphs to red
538 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
539 * $('#foo').css('display', 'none');
540 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
541 * $('#foo').css('display', 'block');
542 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
546 * @param String key The name of the property to set.
547 * @param Object value The value to set the property to.
550 css: function( key, value ) {
551 return this.attr( key, value, "curCSS" );
555 * Retrieve the text contents of all matched elements. The result is
556 * a string that contains the combined text contents of all matched
557 * elements. This method works on both HTML and XML documents.
559 * @example $("p").text();
560 * @before <p>Test Paragraph.</p>
561 * @result Test Paragraph.
563 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
564 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
573 for ( var j = 0; j < e.length; j++ ) {
574 var r = e[j].childNodes;
575 for ( var i = 0; i < r.length; i++ )
576 if ( r[i].nodeType != 8 )
577 t += r[i].nodeType != 1 ?
578 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
584 * Wrap all matched elements with a structure of other elements.
585 * This wrapping process is most useful for injecting additional
586 * stucture into a document, without ruining the original semantic
587 * qualities of a document.
589 * This works by going through the first element
590 * provided (which is generated, on the fly, from the provided HTML)
591 * and finds the deepest ancestor element within its
592 * structure - it is that element that will en-wrap everything else.
594 * This does not work with elements that contain text. Any necessary text
595 * must be added after the wrapping is done.
597 * @example $("p").wrap("<div class='wrap'></div>");
598 * @before <p>Test Paragraph.</p>
599 * @result <div class='wrap'><p>Test Paragraph.</p></div>
601 * @test var defaultText = 'Try them out:'
602 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
603 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
604 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
608 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
609 * @cat DOM/Manipulation
613 * Wrap all matched elements with a structure of other elements.
614 * This wrapping process is most useful for injecting additional
615 * stucture into a document, without ruining the original semantic
616 * qualities of a document.
618 * This works by going through the first element
619 * provided and finding the deepest ancestor element within its
620 * structure - it is that element that will en-wrap everything else.
622 * This does not work with elements that contain text. Any necessary text
623 * must be added after the wrapping is done.
625 * @example $("p").wrap( document.getElementById('content') );
626 * @before <p>Test Paragraph.</p><div id="content"></div>
627 * @result <div id="content"><p>Test Paragraph.</p></div>
629 * @test var defaultText = 'Try them out:'
630 * var result = $('#first').wrap(document.getElementById('empty')).parent();
631 * ok( result.is('ol'), 'Check for element wrapping' );
632 * ok( result.text() == defaultText, 'Check for element wrapping' );
636 * @param Element elem A DOM element that will be wrapped.
637 * @cat DOM/Manipulation
640 // The elements to wrap the target around
641 var a = jQuery.clean(arguments);
643 // Wrap each of the matched elements individually
644 return this.each(function(){
645 // Clone the structure that we're using to wrap
646 var b = a[0].cloneNode(true);
648 // Insert it before the element to be wrapped
649 this.parentNode.insertBefore( b, this );
651 // Find the deepest point in the wrap structure
652 while ( b.firstChild )
655 // Move the matched element to within the wrap structure
656 b.appendChild( this );
661 * Append any number of elements to the inside of every matched elements,
662 * generated from the provided HTML.
663 * This operation is similar to doing an appendChild to all the
664 * specified elements, adding them into the document.
666 * @example $("p").append("<b>Hello</b>");
667 * @before <p>I would like to say: </p>
668 * @result <p>I would like to say: <b>Hello</b></p>
670 * @test var defaultText = 'Try them out:'
671 * var result = $('#first').append('<b>buga</b>');
672 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
676 * @param String html A string of HTML, that will be created on the fly and appended to the target.
677 * @cat DOM/Manipulation
681 * Append an element to the inside of all matched elements.
682 * This operation is similar to doing an appendChild to all the
683 * specified elements, adding them into the document.
685 * @example $("p").append( $("#foo")[0] );
686 * @before <p>I would like to say: </p><b id="foo">Hello</b>
687 * @result <p>I would like to say: <b id="foo">Hello</b></p>
689 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
690 * $('#sap').append(document.getElementById('first'));
691 * ok( expected == $('#sap').text(), "Check for appending of element" );
695 * @param Element elem A DOM element that will be appended.
696 * @cat DOM/Manipulation
700 * Append any number of elements to the inside of all matched elements.
701 * This operation is similar to doing an appendChild to all the
702 * specified elements, adding them into the document.
704 * @example $("p").append( $("b") );
705 * @before <p>I would like to say: </p><b>Hello</b>
706 * @result <p>I would like to say: <b>Hello</b></p>
708 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
709 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
710 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
714 * @param Array<Element> elems An array of elements, all of which will be appended.
715 * @cat DOM/Manipulation
718 return this.domManip(arguments, true, 1, function(a){
719 this.appendChild( a );
724 * Prepend any number of elements to the inside of every matched elements,
725 * generated from the provided HTML.
726 * This operation is the best way to insert dynamically created elements
727 * inside, at the beginning, of all the matched element.
729 * @example $("p").prepend("<b>Hello</b>");
730 * @before <p>I would like to say: </p>
731 * @result <p><b>Hello</b>I would like to say: </p>
733 * @test var defaultText = 'Try them out:'
734 * var result = $('#first').prepend('<b>buga</b>');
735 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
739 * @param String html A string of HTML, that will be created on the fly and appended to the target.
740 * @cat DOM/Manipulation
744 * Prepend an element to the inside of all matched elements.
745 * This operation is the best way to insert an element inside, at the
746 * beginning, of all the matched element.
748 * @example $("p").prepend( $("#foo")[0] );
749 * @before <p>I would like to say: </p><b id="foo">Hello</b>
750 * @result <p><b id="foo">Hello</b>I would like to say: </p>
752 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
753 * $('#sap').prepend(document.getElementById('first'));
754 * ok( expected == $('#sap').text(), "Check for prepending of element" );
758 * @param Element elem A DOM element that will be appended.
759 * @cat DOM/Manipulation
763 * Prepend any number of elements to the inside of all matched elements.
764 * This operation is the best way to insert a set of elements inside, at the
765 * beginning, of all the matched element.
767 * @example $("p").prepend( $("b") );
768 * @before <p>I would like to say: </p><b>Hello</b>
769 * @result <p><b>Hello</b>I would like to say: </p>
771 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
772 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
773 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
777 * @param Array<Element> elems An array of elements, all of which will be appended.
778 * @cat DOM/Manipulation
780 prepend: function() {
781 return this.domManip(arguments, true, -1, function(a){
782 this.insertBefore( a, this.firstChild );
787 * Insert any number of dynamically generated elements before each of the
790 * @example $("p").before("<b>Hello</b>");
791 * @before <p>I would like to say: </p>
792 * @result <b>Hello</b><p>I would like to say: </p>
794 * @test var expected = 'This is a normal link: bugaYahoo';
795 * $('#yahoo').before('<b>buga</b>');
796 * ok( expected == $('#en').text(), 'Insert String before' );
800 * @param String html A string of HTML, that will be created on the fly and appended to the target.
801 * @cat DOM/Manipulation
805 * Insert an element before each of the matched elements.
807 * @example $("p").before( $("#foo")[0] );
808 * @before <p>I would like to say: </p><b id="foo">Hello</b>
809 * @result <b id="foo">Hello</b><p>I would like to say: </p>
811 * @test var expected = "This is a normal link: Try them out:Yahoo";
812 * $('#yahoo').before(document.getElementById('first'));
813 * ok( expected == $('#en').text(), "Insert element before" );
817 * @param Element elem A DOM element that will be appended.
818 * @cat DOM/Manipulation
822 * Insert any number of elements before each of the matched elements.
824 * @example $("p").before( $("b") );
825 * @before <p>I would like to say: </p><b>Hello</b>
826 * @result <b>Hello</b><p>I would like to say: </p>
828 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
829 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
830 * ok( expected == $('#en').text(), "Insert array of elements before" );
834 * @param Array<Element> elems An array of elements, all of which will be appended.
835 * @cat DOM/Manipulation
838 return this.domManip(arguments, false, 1, function(a){
839 this.parentNode.insertBefore( a, this );
844 * Insert any number of dynamically generated elements after each of the
847 * @example $("p").after("<b>Hello</b>");
848 * @before <p>I would like to say: </p>
849 * @result <p>I would like to say: </p><b>Hello</b>
851 * @test var expected = 'This is a normal link: Yahoobuga';
852 * $('#yahoo').after('<b>buga</b>');
853 * ok( expected == $('#en').text(), 'Insert String after' );
857 * @param String html A string of HTML, that will be created on the fly and appended to the target.
858 * @cat DOM/Manipulation
862 * Insert an element after each of the matched elements.
864 * @example $("p").after( $("#foo")[0] );
865 * @before <b id="foo">Hello</b><p>I would like to say: </p>
866 * @result <p>I would like to say: </p><b id="foo">Hello</b>
868 * @test var expected = "This is a normal link: YahooTry them out:";
869 * $('#yahoo').after(document.getElementById('first'));
870 * ok( expected == $('#en').text(), "Insert element after" );
874 * @param Element elem A DOM element that will be appended.
875 * @cat DOM/Manipulation
879 * Insert any number of elements after each of the matched elements.
881 * @example $("p").after( $("b") );
882 * @before <b>Hello</b><p>I would like to say: </p>
883 * @result <p>I would like to say: </p><b>Hello</b>
885 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
886 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
887 * ok( expected == $('#en').text(), "Insert array of elements after" );
891 * @param Array<Element> elems An array of elements, all of which will be appended.
892 * @cat DOM/Manipulation
895 return this.domManip(arguments, false, -1, function(a){
896 this.parentNode.insertBefore( a, this.nextSibling );
901 * End the most recent 'destructive' operation, reverting the list of matched elements
902 * back to its previous state. After an end operation, the list of matched elements will
903 * revert to the last state of matched elements.
905 * @example $("p").find("span").end();
906 * @before <p><span>Hello</span>, how are you?</p>
907 * @result $("p").find("span").end() == [ <p>...</p> ]
909 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
913 * @cat DOM/Traversing
916 return this.get( this.stack.pop() );
920 * Searches for all elements that match the specified expression.
921 * This method is the optimal way of finding additional descendant
922 * elements with which to process.
924 * All searching is done using a jQuery expression. The expression can be
925 * written using CSS 1-3 Selector syntax, or basic XPath.
927 * @example $("p").find("span");
928 * @before <p><span>Hello</span>, how are you?</p>
929 * @result $("p").find("span") == [ <span>Hello</span> ]
931 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
935 * @param String expr An expression to search with.
936 * @cat DOM/Traversing
939 return this.pushStack( jQuery.map( this, function(a){
940 return jQuery.find(t,a);
945 * Create cloned copies of all matched DOM Elements. This does
946 * not create a cloned copy of this particular jQuery object,
947 * instead it creates duplicate copies of all DOM Elements.
948 * This is useful for moving copies of the elements to another
949 * location in the DOM.
951 * @example $("b").clone().prependTo("p");
952 * @before <b>Hello</b><p>, how are you?</p>
953 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
955 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
956 * var clone = $('#yahoo').clone();
957 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
958 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
962 * @cat DOM/Manipulation
964 clone: function(deep) {
965 return this.pushStack( jQuery.map( this, function(a){
966 return a.cloneNode( deep != undefined ? deep : true );
971 * Removes all elements from the set of matched elements that do not
972 * match the specified expression. This method is used to narrow down
973 * the results of a search.
975 * All searching is done using a jQuery expression. The expression
976 * can be written using CSS 1-3 Selector syntax, or basic XPath.
978 * @example $("p").filter(".selected")
979 * @before <p class="selected">Hello</p><p>How are you?</p>
980 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
982 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
983 * @test $("input").filter(":checked",function(i){
984 * ok( this == q("radio2", "check1")[i], "Filter elements, context" );
986 * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){
987 * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
992 * @param String expr An expression to search with.
993 * @cat DOM/Traversing
997 * Removes all elements from the set of matched elements that do not
998 * match at least one of the expressions passed to the function. This
999 * method is used when you want to filter the set of matched elements
1000 * through more than one expression.
1002 * Elements will be retained in the jQuery object if they match at
1003 * least one of the expressions passed.
1005 * @example $("p").filter([".selected", ":first"])
1006 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
1007 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
1011 * @param Array<String> exprs A set of expressions to evaluate against
1012 * @cat DOM/Traversing
1014 filter: function(t) {
1015 return this.pushStack(
1016 t.constructor == Array &&
1017 jQuery.map(this,function(a){
1018 for ( var i = 0; i < t.length; i++ )
1019 if ( jQuery.filter(t[i],[a]).r.length )
1023 t.constructor == Boolean &&
1024 ( t ? this.get() : [] ) ||
1026 typeof t == "function" &&
1027 jQuery.grep( this, t ) ||
1029 jQuery.filter(t,this).r, arguments );
1033 * Removes the specified Element from the set of matched elements. This
1034 * method is used to remove a single Element from a jQuery object.
1036 * @example $("p").not( document.getElementById("selected") )
1037 * @before <p>Hello</p><p id="selected">Hello Again</p>
1038 * @result [ <p>Hello</p> ]
1042 * @param Element el An element to remove from the set
1043 * @cat DOM/Traversing
1047 * Removes elements matching the specified expression from the set
1048 * of matched elements. This method is used to remove one or more
1049 * elements from a jQuery object.
1051 * @example $("p").not("#selected")
1052 * @before <p>Hello</p><p id="selected">Hello Again</p>
1053 * @result [ <p>Hello</p> ]
1055 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
1059 * @param String expr An expression with which to remove matching elements
1060 * @cat DOM/Traversing
1063 return this.pushStack( t.constructor == String ?
1064 jQuery.filter(t,this,false).r :
1065 jQuery.grep(this,function(a){ return a != t; }), arguments );
1069 * Adds the elements matched by the expression to the jQuery object. This
1070 * can be used to concatenate the result sets of two expressions.
1072 * @example $("p").add("span")
1073 * @before <p>Hello</p><p><span>Hello Again</span></p>
1074 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1078 * @param String expr An expression whose matched elements are added
1079 * @cat DOM/Traversing
1083 * Adds each of the Elements in the array to the set of matched elements.
1084 * This is used to add a set of Elements to a jQuery object.
1086 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1087 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1088 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1092 * @param Array<Element> els An array of Elements to add
1093 * @cat DOM/Traversing
1097 * Adds a single Element to the set of matched elements. This is used to
1098 * add a single Element to a jQuery object.
1100 * @example $("p").add( document.getElementById("a") )
1101 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1102 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1106 * @param Element el An Element to add
1107 * @cat DOM/Traversing
1110 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1111 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1115 * Checks the current selection against an expression and returns true,
1116 * if the selection fits the given expression. Does return false, if the
1117 * selection does not fit or the expression is not valid.
1119 * @example $("input[@type='checkbox']").parent().is("form")
1120 * @before <form><input type="checkbox" /></form>
1122 * @desc Returns true, because the parent of the input is a form element
1124 * @example $("input[@type='checkbox']").parent().is("form")
1125 * @before <form><p><input type="checkbox" /></p></form>
1127 * @desc Returns false, because the parent of the input is a p element
1129 * @example $("form").is(null)
1130 * @before <form></form>
1132 * @desc An invalid expression always returns false.
1134 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1135 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1136 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1137 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1138 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1139 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1140 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1141 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1142 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1143 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1144 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1145 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1146 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1147 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1148 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1149 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1150 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1151 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1152 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1153 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1154 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1155 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1159 * @param String expr The expression with which to filter
1160 * @cat DOM/Traversing
1162 is: function(expr) {
1163 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1172 * @param Boolean table
1174 * @param Function fn The function doing the DOM manipulation.
1178 domManip: function(args, table, dir, fn){
1179 var clone = this.size() > 1;
1180 var a = jQuery.clean(args);
1182 return this.each(function(){
1185 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
1186 var tbody = this.getElementsByTagName("tbody");
1188 if ( !tbody.length ) {
1189 obj = document.createElement("tbody");
1190 this.appendChild( obj );
1195 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1196 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1197 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1212 pushStack: function(a,args) {
1213 var fn = args && args[args.length-1];
1214 var fn2 = args && args[args.length-2];
1216 if ( fn && fn.constructor != Function ) fn = null;
1217 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1220 if ( !this.stack ) this.stack = [];
1221 this.stack.push( this.get() );
1224 var old = this.get();
1227 if ( fn2 && a.length || !fn2 )
1228 this.each( fn2 || fn ).get( old );
1230 this.get( old ).each( fn );
1238 * Extends the jQuery object itself. Can be used to add both static
1239 * functions and plugin methods.
1241 * @example $.fn.extend({
1242 * check: function() {
1243 * this.each(function() { this.checked = true; });
1245 * uncheck: function() {
1246 * this.each(function() { this.checked = false; });
1249 * $("input[@type=checkbox]").check();
1250 * $("input[@type=radio]").uncheck();
1251 * @desc Adds two plugin methods.
1261 * Extend one object with another, returning the original,
1262 * modified, object. This is a great utility for simple inheritance.
1264 * @example var settings = { validate: false, limit: 5, name: "foo" };
1265 * var options = { validate: true, name: "bar" };
1266 * jQuery.extend(settings, options);
1267 * @result settings == { validate: true, limit: 5, name: "bar" }
1269 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1270 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1271 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1272 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1273 * jQuery.extend(settings, options);
1274 * isSet( settings, merged, "Check if extended: settings must be extended" );
1275 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1278 * @param Object obj The object to extend
1279 * @param Object prop The object that will be merged into the first.
1283 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1284 if ( !prop ) { prop = obj; obj = this; }
1285 for ( var i in prop ) obj[i] = prop[i];
1297 jQuery.initDone = true;
1299 jQuery.each( jQuery.macros.axis, function(i,n){
1300 jQuery.fn[ i ] = function(a) {
1301 var ret = jQuery.map(this,n);
1302 if ( a && a.constructor == String )
1303 ret = jQuery.filter(a,ret).r;
1304 return this.pushStack( ret, arguments );
1308 jQuery.each( jQuery.macros.to, function(i,n){
1309 jQuery.fn[ i ] = function(){
1311 return this.each(function(){
1312 for ( var j = 0; j < a.length; j++ )
1313 jQuery(a[j])[n]( this );
1318 jQuery.each( jQuery.macros.each, function(i,n){
1319 jQuery.fn[ i ] = function() {
1320 return this.each( n, arguments );
1324 jQuery.each( jQuery.macros.filter, function(i,n){
1325 jQuery.fn[ n ] = function(num,fn) {
1326 return this.filter( ":" + n + "(" + num + ")", fn );
1330 jQuery.each( jQuery.macros.attr, function(i,n){
1332 jQuery.fn[ i ] = function(h) {
1333 return h == undefined ?
1334 this.length ? this[0][n] : null :
1339 jQuery.each( jQuery.macros.css, function(i,n){
1340 jQuery.fn[ n ] = function(h) {
1341 return h == undefined ?
1342 ( this.length ? jQuery.css( this[0], n ) : null ) :
1350 * A generic iterator function, which can be used to seemlessly
1351 * iterate over both objects and arrays. This function is not the same
1352 * as $().each() - which is used to iterate, exclusively, over a jQuery
1353 * object. This function can be used to iterate over anything.
1355 * @example $.each( [0,1,2], function(i){
1356 * alert( "Item #" + i + ": " + this );
1358 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1360 * @example $.each( { name: "John", lang: "JS" }, function(i){
1361 * alert( "Name: " + i + ", Value: " + this );
1363 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1366 * @param Object obj The object, or array, to iterate over.
1367 * @param Function fn The function that will be executed on every object.
1371 each: function( obj, fn, args ) {
1372 if ( obj.length == undefined )
1373 for ( var i in obj )
1374 fn.apply( obj[i], args || [i, obj[i]] );
1376 for ( var i = 0; i < obj.length; i++ )
1377 fn.apply( obj[i], args || [i, obj[i]] );
1383 if (jQuery.className.has(o,c)) return;
1384 o.className += ( o.className ? " " : "" ) + c;
1386 remove: function(o,c){
1390 var classes = o.className.split(" ");
1391 for(var i=0; i<classes.length; i++) {
1392 if(classes[i] == c) {
1393 classes.splice(i, 1);
1397 o.className = classes.join(' ');
1400 has: function(e,a) {
1401 if ( e.className != undefined )
1403 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1408 * Swap in/out style options.
1411 swap: function(e,o,f) {
1412 for ( var i in o ) {
1413 e.style["old"+i] = e.style[i];
1418 e.style[i] = e.style["old"+i];
1421 css: function(e,p) {
1422 if ( p == "height" || p == "width" ) {
1423 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1425 for ( var i in d ) {
1426 old["padding" + d[i]] = 0;
1427 old["border" + d[i] + "Width"] = 0;
1430 jQuery.swap( e, old, function() {
1431 if (jQuery.css(e,"display") != "none") {
1432 oHeight = e.offsetHeight;
1433 oWidth = e.offsetWidth;
1435 e = jQuery(e.cloneNode(true)).css({
1436 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1437 }).appendTo(e.parentNode)[0];
1439 var parPos = jQuery.css(e.parentNode,"position");
1440 if ( parPos == "" || parPos == "static" )
1441 e.parentNode.style.position = "relative";
1443 oHeight = e.clientHeight;
1444 oWidth = e.clientWidth;
1446 if ( parPos == "" || parPos == "static" )
1447 e.parentNode.style.position = "static";
1449 e.parentNode.removeChild(e);
1453 return p == "height" ? oHeight : oWidth;
1456 return jQuery.curCSS( e, p );
1459 curCSS: function(elem, prop, force) {
1462 if (prop == 'opacity' && jQuery.browser.msie)
1463 return jQuery.attr(elem.style, 'opacity');
1465 if (prop == "float" || prop == "cssFloat")
1466 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1468 if (!force && elem.style[prop]) {
1470 ret = elem.style[prop];
1472 } else if (elem.currentStyle) {
1474 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1475 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1477 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1479 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1480 var cur = document.defaultView.getComputedStyle(elem, null);
1483 ret = cur.getPropertyValue(prop);
1484 else if ( prop == 'display' )
1487 jQuery.swap(elem, { display: 'block' }, function() {
1488 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1496 clean: function(a) {
1498 for ( var i = 0; i < a.length; i++ ) {
1499 if ( a[i].constructor == String ) {
1500 // trim whitespace, otherwise indexOf won't work as expected
1501 a[i] = jQuery.trim(a[i]);
1505 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1507 a[i] = "<table>" + a[i] + "</table>";
1508 } else if ( !a[i].indexOf("<tr") ) {
1510 a[i] = "<table>" + a[i] + "</table>";
1511 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1513 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1516 var div = document.createElement("div");
1517 div.innerHTML = a[i];
1520 div = div.firstChild;
1521 if ( table != "thead" ) div = div.firstChild;
1522 if ( table == "td" ) div = div.firstChild;
1525 for ( var j = 0; j < div.childNodes.length; j++ )
1526 r.push( div.childNodes[j] );
1527 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1528 for ( var k = 0; k < a[i].length; k++ )
1530 else if ( a[i] !== null )
1531 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1537 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1538 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1546 last: "i==r.length-1",
1551 "nth-child": "jQuery.sibling(a,m[3]).cur",
1552 "first-child": "jQuery.sibling(a,0).cur",
1553 "last-child": "jQuery.sibling(a,0).last",
1554 "only-child": "jQuery.sibling(a).length==1",
1557 parent: "a.childNodes.length",
1558 empty: "!a.childNodes.length",
1561 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1564 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1565 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1568 enabled: "!a.disabled",
1569 disabled: "a.disabled",
1570 checked: "a.checked",
1571 selected: "a.selected || jQuery.attr(a, 'selected')",
1574 text: "a.type=='text'",
1575 radio: "a.type=='radio'",
1576 checkbox: "a.type=='checkbox'",
1577 file: "a.type=='file'",
1578 password: "a.type=='password'",
1579 submit: "a.type=='submit'",
1580 image: "a.type=='image'",
1581 reset: "a.type=='reset'",
1582 button: "a.type=='button'",
1583 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
1585 ".": "jQuery.className.has(a,m[2])",
1589 "^=": "z && !z.indexOf(m[4])",
1590 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1591 "*=": "z && z.indexOf(m[4])>=0",
1594 "[": "jQuery.find(m[2],a).length"
1598 "\\.\\.|/\\.\\.", "a.parentNode",
1599 ">|/", "jQuery.sibling(a.firstChild)",
1600 "\\+", "jQuery.sibling(a).next",
1603 var s = jQuery.sibling(a);
1605 for ( var i = s.n; i < s.length; i++ )
1613 * @test t( "Element Selector", "div", ["main","foo"] );
1614 * t( "Element Selector", "body", ["body"] );
1615 * t( "Element Selector", "html", ["html"] );
1616 * ok( $("*").size() >= 30, "Element Selector" );
1617 * t( "Parent Element", "div div", ["foo"] );
1619 * t( "ID Selector", "#body", ["body"] );
1620 * t( "ID Selector w/ Element", "body#body", ["body"] );
1621 * t( "ID Selector w/ Element", "ul#first", [] );
1623 * t( "Class Selector", ".blog", ["mark","simon"] );
1624 * t( "Class Selector", ".blog.link", ["simon"] );
1625 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1626 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1628 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1629 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1630 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1631 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1633 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1634 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1635 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1636 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1637 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1638 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1639 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1640 * t( "Adjacent", "a + a", ["groups"] );
1641 * t( "Adjacent", "a +a", ["groups"] );
1642 * t( "Adjacent", "a+ a", ["groups"] );
1643 * t( "Adjacent", "a+a", ["groups"] );
1644 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1645 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1646 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1647 * t( "Attribute Exists", "a[@title]", ["google"] );
1648 * t( "Attribute Exists", "*[@title]", ["google"] );
1649 * t( "Attribute Exists", "[@title]", ["google"] );
1651 * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] );
1652 * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
1653 * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] );
1655 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1656 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1657 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1658 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1659 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1660 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1662 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1663 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1664 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1665 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1666 * t( "Last Child", "p:last-child", ["sap"] );
1667 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1668 * t( "Empty", "ul:empty", ["firstUL"] );
1669 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1670 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1671 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1672 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1673 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1674 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1675 * t( "Element Preceded By", "p ~ div", ["foo"] );
1676 * t( "Not", "a.blog:not(.link)", ["mark"] );
1678 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1679 * t( "All Div Elements", "//div", ["main","foo"] );
1680 * t( "Absolute Path", "/html/body", ["body"] );
1681 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1682 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1683 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1684 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1685 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1686 * t( "Attribute Exists", "//a[@title]", ["google"] );
1687 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1688 * t( "Parent Axis", "//p/..", ["main","foo"] );
1689 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1690 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1691 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1693 * t( "nth Element", "p:nth(1)", ["ap"] );
1694 * t( "First Element", "p:first", ["firstp"] );
1695 * t( "Last Element", "p:last", ["first"] );
1696 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1697 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1698 * t( "Position Equals", "p:eq(1)", ["ap"] );
1699 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1700 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1701 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1702 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1703 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1705 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1707 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1708 * t( "All Children of ID with no children", "#firstUL/*", [] );
1710 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1711 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1712 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1713 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1714 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1715 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1716 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1718 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1719 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1720 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1723 * @type Array<Element>
1727 find: function( t, context ) {
1728 // Make sure that the context is a DOM Element
1729 if ( context && context.nodeType == undefined )
1732 // Set the correct context (if none is provided)
1733 context = context || jQuery.context || document;
1735 if ( t.constructor != String ) return [t];
1737 if ( !t.indexOf("//") ) {
1738 context = context.documentElement;
1739 t = t.substr(2,t.length);
1740 } else if ( !t.indexOf("/") ) {
1741 context = context.documentElement;
1742 t = t.substr(1,t.length);
1743 // FIX Assume the root element is right :(
1744 if ( t.indexOf("/") >= 1 )
1745 t = t.substr(t.indexOf("/"),t.length);
1748 var ret = [context];
1752 while ( t.length > 0 && last != t ) {
1756 t = jQuery.trim(t).replace( /^\/\//i, "" );
1758 var foundToken = false;
1760 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1761 if ( foundToken ) continue;
1763 var re = new RegExp("^(" + jQuery.token[i] + ")");
1767 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1768 t = jQuery.trim( t.replace( re, "" ) );
1773 if ( !foundToken ) {
1774 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1775 if ( ret[0] == context ) ret.shift();
1776 done = jQuery.merge( done, ret );
1777 r = ret = [context];
1778 t = " " + t.substr(1,t.length);
1780 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1781 var m = re2.exec(t);
1783 if ( m[1] == "#" ) {
1784 // Ummm, should make this work in all XML docs
1785 var oid = document.getElementById(m[2]);
1786 r = ret = oid ? [oid] : [];
1787 t = t.replace( re2, "" );
1789 if ( !m[2] || m[1] == "." ) m[2] = "*";
1791 for ( var i = 0; i < ret.length; i++ )
1792 r = jQuery.merge( r,
1794 jQuery.getAll(ret[i]) :
1795 ret[i].getElementsByTagName(m[2])
1803 var val = jQuery.filter(t,r);
1805 t = jQuery.trim(val.t);
1809 if ( ret && ret[0] == context ) ret.shift();
1810 done = jQuery.merge( done, ret );
1815 getAll: function(o,r) {
1817 var s = o.childNodes;
1818 for ( var i = 0; i < s.length; i++ )
1819 if ( s[i].nodeType == 1 ) {
1821 jQuery.getAll( s[i], r );
1826 attr: function(elem, name, value){
1829 "class": "className",
1830 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1831 cssFloat: fix["float"],
1832 innerHTML: "innerHTML",
1833 className: "className",
1835 disabled: "disabled",
1839 // IE actually uses filters for opacity ... elem is actually elem.style
1840 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
1841 // IE has trouble with opacity if it does not have layout
1842 // Would prefer to check element.hasLayout first but don't have access to the element here
1844 if (value == 1) // Remove filter to avoid more IE weirdness
1845 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
1847 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
1848 } else if (name == "opacity" && jQuery.browser.msie) {
1849 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
1852 // Mozilla doesn't play well with opacity 1
1853 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
1856 if ( value != undefined ) elem[fix[name]] = value;
1857 return elem[fix[name]];
1858 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1859 return elem.getAttributeNode(name).nodeValue;
1860 } else if ( elem.getAttribute != undefined && elem.tagName ) { // IE elem.getAttribute passes even for style
1861 if ( value != undefined ) elem.setAttribute( name, value );
1862 return elem.getAttribute( name, 2 );
1864 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1865 if ( value != undefined ) elem[name] = value;
1870 // The regular expressions that power the parsing engine
1872 // Match: [@value='test'], [@foo]
1873 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1875 // Match: [div], [div p]
1876 "(\\[)\s*(.*?)\s*\\]",
1878 // Match: :contains('foo')
1879 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1881 // Match: :even, :last-chlid
1885 filter: function(t,r,not) {
1886 // Figure out if we're doing regular, or inverse, filtering
1887 var g = not !== false ? jQuery.grep :
1888 function(a,f) {return jQuery.grep(a,f,true);};
1890 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1892 var p = jQuery.parse;
1894 for ( var i = 0; i < p.length; i++ ) {
1896 // Look for, and replace, string-like sequences
1897 // and finally build a regexp out of it
1898 var re = new RegExp(
1899 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1901 var m = re.exec( t );
1904 // Re-organize the first match
1906 m = ["",m[1], m[3], m[2], m[5]];
1908 // Remove what we just matched
1909 t = t.replace( re, "" );
1915 // :not() is a special case that can be optimized by
1916 // keeping it out of the expression list
1917 if ( m[1] == ":" && m[2] == "not" )
1918 r = jQuery.filter(m[3],r,false).r;
1920 // Otherwise, find the expression to execute
1922 var f = jQuery.expr[m[1]];
1923 if ( f.constructor != String )
1924 f = jQuery.expr[m[1]][m[2]];
1926 // Build a custom macro to enclose it
1927 eval("f = function(a,i){" +
1928 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1929 "return " + f + "}");
1931 // Execute it against the current filter
1936 // Return an array of filtered elements (r)
1937 // and the modified expression string (t)
1938 return { r: r, t: t };
1942 * Remove the whitespace from the beginning and end of a string.
1944 * @example $.trim(" hello, how are you? ");
1945 * @result "hello, how are you?"
1949 * @param String str The string to trim.
1953 return t.replace(/^\s+|\s+$/g, "");
1957 * All ancestors of a given element.
1961 * @type Array<Element>
1962 * @param Element elem The element to find the ancestors of.
1963 * @cat DOM/Traversing
1965 parents: function( elem ){
1967 var cur = elem.parentNode;
1968 while ( cur && cur != document ) {
1969 matched.push( cur );
1970 cur = cur.parentNode;
1976 * All elements on a specified axis.
1981 * @param Element elem The element to find all the siblings of (including itself).
1982 * @cat DOM/Traversing
1984 sibling: function(elem, pos, not) {
1988 var siblings = elem.parentNode.childNodes;
1989 for ( var i = 0; i < siblings.length; i++ ) {
1990 if ( not === true && siblings[i] == elem ) continue;
1992 if ( siblings[i].nodeType == 1 )
1993 elems.push( siblings[i] );
1994 if ( siblings[i] == elem )
1995 elems.n = elems.length - 1;
1999 return jQuery.extend( elems, {
2000 last: elems.n == elems.length - 1,
2001 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
2002 prev: elems[elems.n - 1],
2003 next: elems[elems.n + 1]
2008 * Merge two arrays together, removing all duplicates. The final order
2009 * or the new array is: All the results from the first array, followed
2010 * by the unique results from the second array.
2012 * @example $.merge( [0,1,2], [2,3,4] )
2013 * @result [0,1,2,3,4]
2015 * @example $.merge( [3,2,1], [4,3,2] )
2020 * @param Array first The first array to merge.
2021 * @param Array second The second array to merge.
2024 merge: function(first, second) {
2027 // Move b over to the new array (this helps to avoid
2028 // StaticNodeList instances)
2029 for ( var k = 0; k < first.length; k++ )
2030 result[k] = first[k];
2032 // Now check for duplicates between a and b and only
2033 // add the unique items
2034 for ( var i = 0; i < second.length; i++ ) {
2035 var noCollision = true;
2037 // The collision-checking process
2038 for ( var j = 0; j < first.length; j++ )
2039 if ( second[i] == first[j] )
2040 noCollision = false;
2042 // If the item is unique, add it
2044 result.push( second[i] );
2051 * Filter items out of an array, by using a filter function.
2052 * The specified function will be passed two arguments: The
2053 * current array item and the index of the item in the array. The
2054 * function should return 'true' if you wish to keep the item in
2055 * the array, false if it should be removed.
2057 * @example $.grep( [0,1,2], function(i){
2064 * @param Array array The Array to find items in.
2065 * @param Function fn The function to process each item against.
2066 * @param Boolean inv Invert the selection - select the opposite of the function.
2069 grep: function(elems, fn, inv) {
2070 // If a string is passed in for the function, make a function
2071 // for it (a handy shortcut)
2072 if ( fn.constructor == String )
2073 fn = new Function("a","i","return " + fn);
2077 // Go through the array, only saving the items
2078 // that pass the validator function
2079 for ( var i = 0; i < elems.length; i++ )
2080 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2081 result.push( elems[i] );
2087 * Translate all items in an array to another array of items.
2088 * The translation function that is provided to this method is
2089 * called for each item in the array and is passed one argument:
2090 * The item to be translated. The function can then return:
2091 * The translated value, 'null' (to remove the item), or
2092 * an array of values - which will be flattened into the full array.
2094 * @example $.map( [0,1,2], function(i){
2099 * @example $.map( [0,1,2], function(i){
2100 * return i > 0 ? i + 1 : null;
2104 * @example $.map( [0,1,2], function(i){
2105 * return [ i, i + 1 ];
2107 * @result [0, 1, 1, 2, 2, 3]
2111 * @param Array array The Array to translate.
2112 * @param Function fn The function to process each item against.
2115 map: function(elems, fn) {
2116 // If a string is passed in for the function, make a function
2117 // for it (a handy shortcut)
2118 if ( fn.constructor == String )
2119 fn = new Function("a","return " + fn);
2123 // Go through the array, translating each of the items to their
2124 // new value (or values).
2125 for ( var i = 0; i < elems.length; i++ ) {
2126 var val = fn(elems[i],i);
2128 if ( val !== null && val != undefined ) {
2129 if ( val.constructor != Array ) val = [val];
2130 result = jQuery.merge( result, val );
2138 * A number of helper functions used for managing events.
2139 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2143 // Bind an event to an element
2144 // Original by Dean Edwards
2145 add: function(element, type, handler) {
2146 // For whatever reason, IE has trouble passing the window object
2147 // around, causing it to be cloned in the process
2148 if ( jQuery.browser.msie && element.setInterval != undefined )
2151 // Make sure that the function being executed has a unique ID
2152 if ( !handler.guid )
2153 handler.guid = this.guid++;
2155 // Init the element's event structure
2156 if (!element.events)
2157 element.events = {};
2159 // Get the current list of functions bound to this event
2160 var handlers = element.events[type];
2162 // If it hasn't been initialized yet
2164 // Init the event handler queue
2165 handlers = element.events[type] = {};
2167 // Remember an existing handler, if it's already there
2168 if (element["on" + type])
2169 handlers[0] = element["on" + type];
2172 // Add the function to the element's handler list
2173 handlers[handler.guid] = handler;
2175 // And bind the global event handler to the element
2176 element["on" + type] = this.handle;
2178 // Remember the function in a global list (for triggering)
2179 if (!this.global[type])
2180 this.global[type] = [];
2181 this.global[type].push( element );
2187 // Detach an event or set of events from an element
2188 remove: function(element, type, handler) {
2190 if (type && element.events[type])
2192 delete element.events[type][handler.guid];
2194 for ( var i in element.events[type] )
2195 delete element.events[type][i];
2197 for ( var j in element.events )
2198 this.remove( element, j );
2201 trigger: function(type,data,element) {
2202 // Touch up the incoming data
2205 // Handle a global trigger
2207 var g = this.global[type];
2209 for ( var i = 0; i < g.length; i++ )
2210 this.trigger( type, data, g[i] );
2212 // Handle triggering a single element
2213 } else if ( element["on" + type] ) {
2214 // Pass along a fake event
2215 data.unshift( this.fix({ type: type, target: element }) );
2217 // Trigger the event
2218 element["on" + type].apply( element, data );
2222 handle: function(event) {
2223 if ( typeof jQuery == "undefined" ) return;
2225 event = event || jQuery.event.fix( window.event );
2227 // If no correct event was found, fail
2228 if ( !event ) return;
2230 var returnValue = true;
2232 var c = this.events[event.type];
2234 var args = [].slice.call( arguments, 1 );
2235 args.unshift( event );
2237 for ( var j in c ) {
2238 if ( c[j].apply( this, args ) === false ) {
2239 event.preventDefault();
2240 event.stopPropagation();
2241 returnValue = false;
2248 fix: function(event) {
2250 event.preventDefault = function() {
2251 this.returnValue = false;
2254 event.stopPropagation = function() {
2255 this.cancelBubble = true;
2266 * Contains flags for the useragent, read from navigator.userAgent.
2267 * Available flags are: safari, opera, msie, mozilla
2268 * This property is available before the DOM is ready, therefore you can
2269 * use it to add ready events only for certain browsers.
2271 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2272 * jQBrowser plugin</a> for advanced browser detection:
2274 * @example $.browser.msie
2275 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2277 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2278 * @desc Alerts "this is safari!" only for safari browsers
2285 var b = navigator.userAgent.toLowerCase();
2287 // Figure out what browser is being used
2289 safari: /webkit/.test(b),
2290 opera: /opera/.test(b),
2291 msie: /msie/.test(b) && !/opera/.test(b),
2292 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2295 // Check to see if the W3C box model is being used
2296 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2302 * Append all of the matched elements to another, specified, set of elements.
2303 * This operation is, essentially, the reverse of doing a regular
2304 * $(A).append(B), in that instead of appending B to A, you're appending
2307 * @example $("p").appendTo("#foo");
2308 * @before <p>I would like to say: </p><div id="foo"></div>
2309 * @result <div id="foo"><p>I would like to say: </p></div>
2313 * @param String expr A jQuery expression of elements to match.
2314 * @cat DOM/Manipulation
2319 * Prepend all of the matched elements to another, specified, set of elements.
2320 * This operation is, essentially, the reverse of doing a regular
2321 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2324 * @example $("p").prependTo("#foo");
2325 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2326 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2330 * @param String expr A jQuery expression of elements to match.
2331 * @cat DOM/Manipulation
2333 prependTo: "prepend",
2336 * Insert all of the matched elements before another, specified, set of elements.
2337 * This operation is, essentially, the reverse of doing a regular
2338 * $(A).before(B), in that instead of inserting B before A, you're inserting
2341 * @example $("p").insertBefore("#foo");
2342 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2343 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2345 * @name insertBefore
2347 * @param String expr A jQuery expression of elements to match.
2348 * @cat DOM/Manipulation
2350 insertBefore: "before",
2353 * Insert all of the matched elements after another, specified, set of elements.
2354 * This operation is, essentially, the reverse of doing a regular
2355 * $(A).after(B), in that instead of inserting B after A, you're inserting
2358 * @example $("p").insertAfter("#foo");
2359 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2360 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2364 * @param String expr A jQuery expression of elements to match.
2365 * @cat DOM/Manipulation
2367 insertAfter: "after"
2371 * Get the current CSS width of the first matched element.
2373 * @example $("p").width();
2374 * @before <p>This is just a test.</p>
2383 * Set the CSS width of every matched element. Be sure to include
2384 * the "px" (or other unit of measurement) after the number that you
2385 * specify, otherwise you might get strange results.
2387 * @example $("p").width("20px");
2388 * @before <p>This is just a test.</p>
2389 * @result <p style="width:20px;">This is just a test.</p>
2393 * @param String val Set the CSS property to the specified value.
2398 * Get the current CSS height of the first matched element.
2400 * @example $("p").height();
2401 * @before <p>This is just a test.</p>
2410 * Set the CSS height of every matched element. Be sure to include
2411 * the "px" (or other unit of measurement) after the number that you
2412 * specify, otherwise you might get strange results.
2414 * @example $("p").height("20px");
2415 * @before <p>This is just a test.</p>
2416 * @result <p style="height:20px;">This is just a test.</p>
2420 * @param String val Set the CSS property to the specified value.
2425 * Get the current CSS top of the first matched element.
2427 * @example $("p").top();
2428 * @before <p>This is just a test.</p>
2437 * Set the CSS top of every matched element. Be sure to include
2438 * the "px" (or other unit of measurement) after the number that you
2439 * specify, otherwise you might get strange results.
2441 * @example $("p").top("20px");
2442 * @before <p>This is just a test.</p>
2443 * @result <p style="top:20px;">This is just a test.</p>
2447 * @param String val Set the CSS property to the specified value.
2452 * Get the current CSS left of the first matched element.
2454 * @example $("p").left();
2455 * @before <p>This is just a test.</p>
2464 * Set the CSS left of every matched element. Be sure to include
2465 * the "px" (or other unit of measurement) after the number that you
2466 * specify, otherwise you might get strange results.
2468 * @example $("p").left("20px");
2469 * @before <p>This is just a test.</p>
2470 * @result <p style="left:20px;">This is just a test.</p>
2474 * @param String val Set the CSS property to the specified value.
2479 * Get the current CSS position of the first matched element.
2481 * @example $("p").position();
2482 * @before <p>This is just a test.</p>
2491 * Set the CSS position of every matched element.
2493 * @example $("p").position("relative");
2494 * @before <p>This is just a test.</p>
2495 * @result <p style="position:relative;">This is just a test.</p>
2499 * @param String val Set the CSS property to the specified value.
2504 * Get the current CSS float of the first matched element.
2506 * @example $("p").float();
2507 * @before <p>This is just a test.</p>
2516 * Set the CSS float of every matched element.
2518 * @example $("p").float("left");
2519 * @before <p>This is just a test.</p>
2520 * @result <p style="float:left;">This is just a test.</p>
2524 * @param String val Set the CSS property to the specified value.
2529 * Get the current CSS overflow of the first matched element.
2531 * @example $("p").overflow();
2532 * @before <p>This is just a test.</p>
2541 * Set the CSS overflow of every matched element.
2543 * @example $("p").overflow("auto");
2544 * @before <p>This is just a test.</p>
2545 * @result <p style="overflow:auto;">This is just a test.</p>
2549 * @param String val Set the CSS property to the specified value.
2554 * Get the current CSS color of the first matched element.
2556 * @example $("p").color();
2557 * @before <p>This is just a test.</p>
2566 * Set the CSS color of every matched element.
2568 * @example $("p").color("blue");
2569 * @before <p>This is just a test.</p>
2570 * @result <p style="color:blue;">This is just a test.</p>
2574 * @param String val Set the CSS property to the specified value.
2579 * Get the current CSS background of the first matched element.
2581 * @example $("p").background();
2582 * @before <p style="background:blue;">This is just a test.</p>
2591 * Set the CSS background of every matched element.
2593 * @example $("p").background("blue");
2594 * @before <p>This is just a test.</p>
2595 * @result <p style="background:blue;">This is just a test.</p>
2599 * @param String val Set the CSS property to the specified value.
2603 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2606 * Reduce the set of matched elements to a single element.
2607 * The position of the element in the set of matched elements
2608 * starts at 0 and goes to length - 1.
2610 * @example $("p").eq(1)
2611 * @before <p>This is just a test.</p><p>So is this</p>
2612 * @result [ <p>So is this</p> ]
2616 * @param Number pos The index of the element that you wish to limit to.
2621 * Reduce the set of matched elements to all elements before a given position.
2622 * The position of the element in the set of matched elements
2623 * starts at 0 and goes to length - 1.
2625 * @example $("p").lt(1)
2626 * @before <p>This is just a test.</p><p>So is this</p>
2627 * @result [ <p>This is just a test.</p> ]
2631 * @param Number pos Reduce the set to all elements below this position.
2636 * Reduce the set of matched elements to all elements after a given position.
2637 * The position of the element in the set of matched elements
2638 * starts at 0 and goes to length - 1.
2640 * @example $("p").gt(0)
2641 * @before <p>This is just a test.</p><p>So is this</p>
2642 * @result [ <p>So is this</p> ]
2646 * @param Number pos Reduce the set to all elements after this position.
2651 * Filter the set of elements to those that contain the specified text.
2653 * @example $("p").contains("test")
2654 * @before <p>This is just a test.</p><p>So is this</p>
2655 * @result [ <p>This is just a test.</p> ]
2659 * @param String str The string that will be contained within the text of an element.
2660 * @cat DOM/Traversing
2663 filter: [ "eq", "lt", "gt", "contains" ],
2667 * Get the current value of the first matched element.
2669 * @example $("input").val();
2670 * @before <input type="text" value="some text"/>
2671 * @result "some text"
2673 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2674 * ok( !$("#text1").val() == "", "Check for value of input element" );
2678 * @cat DOM/Attributes
2682 * Set the value of every matched element.
2684 * @example $("input").value("test");
2685 * @before <input type="text" value="some text"/>
2686 * @result <input type="text" value="test"/>
2688 * @test document.getElementById('text1').value = "bla";
2689 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2690 * $("#text1").val('test');
2691 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2695 * @param String val Set the property to the specified value.
2696 * @cat DOM/Attributes
2701 * Get the html contents of the first matched element.
2703 * @example $("div").html();
2704 * @before <div><input/></div>
2709 * @cat DOM/Attributes
2713 * Set the html contents of every matched element.
2715 * @example $("div").html("<b>new stuff</b>");
2716 * @before <div><input/></div>
2717 * @result <div><b>new stuff</b></div>
2719 * @test var div = $("div");
2720 * div.html("<b>test</b>");
2722 * for ( var i = 0; i < div.size(); i++ ) {
2723 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2725 * ok( pass, "Set HTML" );
2729 * @param String val Set the html contents to the specified value.
2730 * @cat DOM/Attributes
2735 * Get the current id of the first matched element.
2737 * @example $("input").id();
2738 * @before <input type="text" id="test" value="some text"/>
2741 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2742 * ok( $("#foo").id() == "foo", "Check for id" );
2743 * ok( !$("head").id(), "Check for id" );
2747 * @cat DOM/Attributes
2751 * Set the id of every matched element.
2753 * @example $("input").id("newid");
2754 * @before <input type="text" id="test" value="some text"/>
2755 * @result <input type="text" id="newid" value="some text"/>
2759 * @param String val Set the property to the specified value.
2760 * @cat DOM/Attributes
2765 * Get the current title of the first matched element.
2767 * @example $("img").title();
2768 * @before <img src="test.jpg" title="my image"/>
2769 * @result "my image"
2771 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2772 * ok( !$("#yahoo").title(), "Check for title" );
2776 * @cat DOM/Attributes
2780 * Set the title of every matched element.
2782 * @example $("img").title("new title");
2783 * @before <img src="test.jpg" title="my image"/>
2784 * @result <img src="test.jpg" title="new image"/>
2788 * @param String val Set the property to the specified value.
2789 * @cat DOM/Attributes
2794 * Get the current name of the first matched element.
2796 * @example $("input").name();
2797 * @before <input type="text" name="username"/>
2798 * @result "username"
2800 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2801 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2802 * ok( !$("#area1").name(), "Check for name" );
2806 * @cat DOM/Attributes
2810 * Set the name of every matched element.
2812 * @example $("input").name("user");
2813 * @before <input type="text" name="username"/>
2814 * @result <input type="text" name="user"/>
2818 * @param String val Set the property to the specified value.
2819 * @cat DOM/Attributes
2824 * Get the current href of the first matched element.
2826 * @example $("a").href();
2827 * @before <a href="test.html">my link</a>
2828 * @result "test.html"
2832 * @cat DOM/Attributes
2836 * Set the href of every matched element.
2838 * @example $("a").href("test2.html");
2839 * @before <a href="test.html">my link</a>
2840 * @result <a href="test2.html">my link</a>
2844 * @param String val Set the property to the specified value.
2845 * @cat DOM/Attributes
2850 * Get the current src of the first matched element.
2852 * @example $("img").src();
2853 * @before <img src="test.jpg" title="my image"/>
2854 * @result "test.jpg"
2858 * @cat DOM/Attributes
2862 * Set the src of every matched element.
2864 * @example $("img").src("test2.jpg");
2865 * @before <img src="test.jpg" title="my image"/>
2866 * @result <img src="test2.jpg" title="my image"/>
2870 * @param String val Set the property to the specified value.
2871 * @cat DOM/Attributes
2876 * Get the current rel of the first matched element.
2878 * @example $("a").rel();
2879 * @before <a href="test.html" rel="nofollow">my link</a>
2880 * @result "nofollow"
2884 * @cat DOM/Attributes
2888 * Set the rel of every matched element.
2890 * @example $("a").rel("nofollow");
2891 * @before <a href="test.html">my link</a>
2892 * @result <a href="test.html" rel="nofollow">my link</a>
2896 * @param String val Set the property to the specified value.
2897 * @cat DOM/Attributes
2904 * Get a set of elements containing the unique parents of the matched
2907 * @example $("p").parent()
2908 * @before <div><p>Hello</p><p>Hello</p></div>
2909 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2913 * @cat DOM/Traversing
2917 * Get a set of elements containing the unique parents of the matched
2918 * set of elements, and filtered by an expression.
2920 * @example $("p").parent(".selected")
2921 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2922 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2926 * @param String expr An expression to filter the parents with
2927 * @cat DOM/Traversing
2929 parent: "a.parentNode",
2932 * Get a set of elements containing the unique ancestors of the matched
2933 * set of elements (except for the root element).
2935 * @example $("span").ancestors()
2936 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2937 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2941 * @cat DOM/Traversing
2945 * Get a set of elements containing the unique ancestors of the matched
2946 * set of elements, and filtered by an expression.
2948 * @example $("span").ancestors("p")
2949 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2950 * @result [ <p><span>Hello</span></p> ]
2954 * @param String expr An expression to filter the ancestors with
2955 * @cat DOM/Traversing
2957 ancestors: jQuery.parents,
2960 * Get a set of elements containing the unique ancestors of the matched
2961 * set of elements (except for the root element).
2963 * @example $("span").ancestors()
2964 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2965 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2969 * @cat DOM/Traversing
2973 * Get a set of elements containing the unique ancestors of the matched
2974 * set of elements, and filtered by an expression.
2976 * @example $("span").ancestors("p")
2977 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2978 * @result [ <p><span>Hello</span></p> ]
2982 * @param String expr An expression to filter the ancestors with
2983 * @cat DOM/Traversing
2985 parents: jQuery.parents,
2988 * Get a set of elements containing the unique next siblings of each of the
2989 * matched set of elements.
2991 * It only returns the very next sibling, not all next siblings.
2993 * @example $("p").next()
2994 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2995 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2999 * @cat DOM/Traversing
3003 * Get a set of elements containing the unique next siblings of each of the
3004 * matched set of elements, and filtered by an expression.
3006 * It only returns the very next sibling, not all next siblings.
3008 * @example $("p").next(".selected")
3009 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
3010 * @result [ <p class="selected">Hello Again</p> ]
3014 * @param String expr An expression to filter the next Elements with
3015 * @cat DOM/Traversing
3017 next: "jQuery.sibling(a).next",
3020 * Get a set of elements containing the unique previous siblings of each of the
3021 * matched set of elements.
3023 * It only returns the immediately previous sibling, not all previous siblings.
3025 * @example $("p").prev()
3026 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3027 * @result [ <div><span>Hello Again</span></div> ]
3031 * @cat DOM/Traversing
3035 * Get a set of elements containing the unique previous siblings of each of the
3036 * matched set of elements, and filtered by an expression.
3038 * It only returns the immediately previous sibling, not all previous siblings.
3040 * @example $("p").previous(".selected")
3041 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3042 * @result [ <div><span>Hello</span></div> ]
3046 * @param String expr An expression to filter the previous Elements with
3047 * @cat DOM/Traversing
3049 prev: "jQuery.sibling(a).prev",
3052 * Get a set of elements containing all of the unique siblings of each of the
3053 * matched set of elements.
3055 * @example $("div").siblings()
3056 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3057 * @result [ <p>Hello</p>, <p>And Again</p> ]
3059 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3063 * @cat DOM/Traversing
3067 * Get a set of elements containing all of the unique siblings of each of the
3068 * matched set of elements, and filtered by an expression.
3070 * @example $("div").siblings(".selected")
3071 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3072 * @result [ <p class="selected">Hello Again</p> ]
3074 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3075 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3079 * @param String expr An expression to filter the sibling Elements with
3080 * @cat DOM/Traversing
3082 siblings: "jQuery.sibling(a, null, true)",
3086 * Get a set of elements containing all of the unique children of each of the
3087 * matched set of elements.
3089 * @example $("div").children()
3090 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3091 * @result [ <span>Hello Again</span> ]
3093 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3097 * @cat DOM/Traversing
3101 * Get a set of elements containing all of the unique children of each of the
3102 * matched set of elements, and filtered by an expression.
3104 * @example $("div").children(".selected")
3105 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3106 * @result [ <p class="selected">Hello Again</p> ]
3108 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3112 * @param String expr An expression to filter the child Elements with
3113 * @cat DOM/Traversing
3115 children: "jQuery.sibling(a.firstChild)"
3121 * Remove an attribute from each of the matched elements.
3123 * @example $("input").removeAttr("disabled")
3124 * @before <input disabled="disabled"/>
3129 * @param String name The name of the attribute to remove.
3132 removeAttr: function( key ) {
3133 this.removeAttribute( key );
3137 * Displays each of the set of matched elements if they are hidden.
3139 * @example $("p").show()
3140 * @before <p style="display: none">Hello</p>
3141 * @result [ <p style="display: block">Hello</p> ]
3143 * @test var pass = true, div = $("div");
3144 * div.show().each(function(){
3145 * if ( this.style.display == "none" ) pass = false;
3147 * ok( pass, "Show" );
3154 this.style.display = this.oldblock ? this.oldblock : "";
3155 if ( jQuery.css(this,"display") == "none" )
3156 this.style.display = "block";
3160 * Hides each of the set of matched elements if they are shown.
3162 * @example $("p").hide()
3163 * @before <p>Hello</p>
3164 * @result [ <p style="display: none">Hello</p> ]
3166 * var pass = true, div = $("div");
3167 * div.hide().each(function(){
3168 * if ( this.style.display != "none" ) pass = false;
3170 * ok( pass, "Hide" );
3177 this.oldblock = this.oldblock || jQuery.css(this,"display");
3178 if ( this.oldblock == "none" )
3179 this.oldblock = "block";
3180 this.style.display = "none";
3184 * Toggles each of the set of matched elements. If they are shown,
3185 * toggle makes them hidden. If they are hidden, toggle
3188 * @example $("p").toggle()
3189 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3190 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3197 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3201 * Adds the specified class to each of the set of matched elements.
3203 * @example $("p").addClass("selected")
3204 * @before <p>Hello</p>
3205 * @result [ <p class="selected">Hello</p> ]
3207 * @test var div = $("div");
3208 * div.addClass("test");
3210 * for ( var i = 0; i < div.size(); i++ ) {
3211 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3213 * ok( pass, "Add Class" );
3217 * @param String class A CSS class to add to the elements
3220 addClass: function(c){
3221 jQuery.className.add(this,c);
3225 * Removes the specified class from the set of matched elements.
3227 * @example $("p").removeClass("selected")
3228 * @before <p class="selected">Hello</p>
3229 * @result [ <p>Hello</p> ]
3231 * @test var div = $("div").addClass("test");
3232 * div.removeClass("test");
3234 * for ( var i = 0; i < div.size(); i++ ) {
3235 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3237 * ok( pass, "Remove Class" );
3241 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3242 * div.removeClass("test").removeClass("bar").removeClass("foo");
3244 * for ( var i = 0; i < div.size(); i++ ) {
3245 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3247 * ok( pass, "Remove multiple classes" );
3251 * @param String class A CSS class to remove from the elements
3254 removeClass: function(c){
3255 jQuery.className.remove(this,c);
3259 * Adds the specified class if it is present, removes it if it is
3262 * @example $("p").toggleClass("selected")
3263 * @before <p>Hello</p><p class="selected">Hello Again</p>
3264 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3268 * @param String class A CSS class with which to toggle the elements
3271 toggleClass: function( c ){
3272 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3276 * Removes all matched elements from the DOM. This does NOT remove them from the
3277 * jQuery object, allowing you to use the matched elements further.
3279 * @example $("p").remove();
3280 * @before <p>Hello</p> how are <p>you?</p>
3285 * @cat DOM/Manipulation
3289 * Removes only elements (out of the list of matched elements) that match
3290 * the specified jQuery expression. This does NOT remove them from the
3291 * jQuery object, allowing you to use the matched elements further.
3293 * @example $("p").remove(".hello");
3294 * @before <p class="hello">Hello</p> how are <p>you?</p>
3295 * @result how are <p>you?</p>
3299 * @param String expr A jQuery expression to filter elements by.
3300 * @cat DOM/Manipulation
3302 remove: function(a){
3303 if ( !a || jQuery.filter( a, [this] ).r )
3304 this.parentNode.removeChild( this );
3308 * Removes all child nodes from the set of matched elements.
3310 * @example $("p").empty()
3311 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3312 * @result [ <p></p> ]
3316 * @cat DOM/Manipulation
3319 while ( this.firstChild )
3320 this.removeChild( this.firstChild );
3324 * Binds a handler to a particular event (like click) for each matched element.
3325 * The event handler is passed an event object that you can use to prevent
3326 * default behaviour. To stop both default action and event bubbling, your handler
3327 * has to return false.
3329 * @example $("p").bind( "click", function() {
3330 * alert( $(this).text() );
3332 * @before <p>Hello</p>
3333 * @result alert("Hello")
3335 * @example $("form").bind( "submit", function() { return false; } )
3336 * @desc Cancel a default action and prevent it from bubbling by returning false
3337 * from your function.
3339 * @example $("form").bind( "submit", function(event) {
3340 * event.preventDefault();
3342 * @desc Cancel only the default action by using the preventDefault method.
3345 * @example $("form").bind( "submit", function(event) {
3346 * event.stopPropagation();
3348 * @desc Stop only an event from bubbling by using the stopPropagation method.
3352 * @param String type An event type
3353 * @param Function fn A function to bind to the event on each of the set of matched elements
3356 bind: function( type, fn ) {
3357 if ( fn.constructor == String )
3358 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3359 jQuery.event.add( this, type, fn );
3363 * The opposite of bind, removes a bound event from each of the matched
3364 * elements. You must pass the identical function that was used in the original
3367 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3368 * @before <p onclick="alert('Hello');">Hello</p>
3369 * @result [ <p>Hello</p> ]
3373 * @param String type An event type
3374 * @param Function fn A function to unbind from the event on each of the set of matched elements
3379 * Removes all bound events of a particular type from each of the matched
3382 * @example $("p").unbind( "click" )
3383 * @before <p onclick="alert('Hello');">Hello</p>
3384 * @result [ <p>Hello</p> ]
3388 * @param String type An event type
3393 * Removes all bound events from each of the matched elements.
3395 * @example $("p").unbind()
3396 * @before <p onclick="alert('Hello');">Hello</p>
3397 * @result [ <p>Hello</p> ]
3403 unbind: function( type, fn ) {
3404 jQuery.event.remove( this, type, fn );
3408 * Trigger a type of event on every matched element.
3410 * @example $("p").trigger("click")
3411 * @before <p click="alert('hello')">Hello</p>
3412 * @result alert('hello')
3416 * @param String type An event type to trigger.
3419 trigger: function( type, data ) {
3420 jQuery.event.trigger( type, data, this );