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 (!force && elem.style[prop]) {
1467 ret = elem.style[prop];
1469 } else if (elem.currentStyle) {
1471 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1472 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1474 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1476 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1477 var cur = document.defaultView.getComputedStyle(elem, null);
1480 ret = cur.getPropertyValue(prop);
1481 else if ( prop == 'display' )
1484 jQuery.swap(elem, { display: 'block' }, function() {
1485 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1493 clean: function(a) {
1495 for ( var i = 0; i < a.length; i++ ) {
1496 if ( a[i].constructor == String ) {
1497 // trim whitespace, otherwise indexOf won't work as expected
1498 a[i] = jQuery.trim(a[i]);
1502 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1504 a[i] = "<table>" + a[i] + "</table>";
1505 } else if ( !a[i].indexOf("<tr") ) {
1507 a[i] = "<table>" + a[i] + "</table>";
1508 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1510 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1513 var div = document.createElement("div");
1514 div.innerHTML = a[i];
1517 div = div.firstChild;
1518 if ( table != "thead" ) div = div.firstChild;
1519 if ( table == "td" ) div = div.firstChild;
1522 for ( var j = 0; j < div.childNodes.length; j++ )
1523 r.push( div.childNodes[j] );
1524 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1525 for ( var k = 0; k < a[i].length; k++ )
1527 else if ( a[i] !== null )
1528 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1534 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1535 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1543 last: "i==r.length-1",
1548 "nth-child": "jQuery.sibling(a,m[3]).cur",
1549 "first-child": "jQuery.sibling(a,0).cur",
1550 "last-child": "jQuery.sibling(a,0).last",
1551 "only-child": "jQuery.sibling(a).length==1",
1554 parent: "a.childNodes.length",
1555 empty: "!a.childNodes.length",
1558 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1561 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1562 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1565 enabled: "!a.disabled",
1566 disabled: "a.disabled",
1567 checked: "a.checked",
1568 selected: "a.selected || jQuery.attr(a, 'selected')",
1571 text: "a.type=='text'",
1572 radio: "a.type=='radio'",
1573 checkbox: "a.type=='checkbox'",
1574 file: "a.type=='file'",
1575 password: "a.type=='password'",
1576 submit: "a.type=='submit'",
1577 image: "a.type=='image'",
1578 reset: "a.type=='reset'",
1579 button: "a.type=='button'",
1580 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
1582 ".": "jQuery.className.has(a,m[2])",
1586 "^=": "z && !z.indexOf(m[4])",
1587 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1588 "*=": "z && z.indexOf(m[4])>=0",
1591 "[": "jQuery.find(m[2],a).length"
1595 "\\.\\.|/\\.\\.", "a.parentNode",
1596 ">|/", "jQuery.sibling(a.firstChild)",
1597 "\\+", "jQuery.sibling(a).next",
1600 var s = jQuery.sibling(a);
1602 for ( var i = s.n; i < s.length; i++ )
1610 * @test t( "Element Selector", "div", ["main","foo"] );
1611 * t( "Element Selector", "body", ["body"] );
1612 * t( "Element Selector", "html", ["html"] );
1613 * ok( $("*").size() >= 30, "Element Selector" );
1614 * t( "Parent Element", "div div", ["foo"] );
1616 * t( "ID Selector", "#body", ["body"] );
1617 * t( "ID Selector w/ Element", "body#body", ["body"] );
1618 * t( "ID Selector w/ Element", "ul#first", [] );
1620 * t( "Class Selector", ".blog", ["mark","simon"] );
1621 * t( "Class Selector", ".blog.link", ["simon"] );
1622 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1623 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1625 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1626 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1627 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1628 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1630 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1631 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1632 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1633 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1634 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1635 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1636 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1637 * t( "Adjacent", "a + a", ["groups"] );
1638 * t( "Adjacent", "a +a", ["groups"] );
1639 * t( "Adjacent", "a+ a", ["groups"] );
1640 * t( "Adjacent", "a+a", ["groups"] );
1641 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1642 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1643 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1644 * t( "Attribute Exists", "a[@title]", ["google"] );
1645 * t( "Attribute Exists", "*[@title]", ["google"] );
1646 * t( "Attribute Exists", "[@title]", ["google"] );
1648 * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] );
1649 * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
1650 * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] );
1652 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1653 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1654 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1655 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1656 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1657 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1659 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1660 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1661 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1662 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1663 * t( "Last Child", "p:last-child", ["sap"] );
1664 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1665 * t( "Empty", "ul:empty", ["firstUL"] );
1666 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1667 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1668 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1669 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1670 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1671 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1672 * t( "Element Preceded By", "p ~ div", ["foo"] );
1673 * t( "Not", "a.blog:not(.link)", ["mark"] );
1675 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1676 * t( "All Div Elements", "//div", ["main","foo"] );
1677 * t( "Absolute Path", "/html/body", ["body"] );
1678 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1679 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1680 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1681 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1682 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1683 * t( "Attribute Exists", "//a[@title]", ["google"] );
1684 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1685 * t( "Parent Axis", "//p/..", ["main","foo"] );
1686 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1687 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1688 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1690 * t( "nth Element", "p:nth(1)", ["ap"] );
1691 * t( "First Element", "p:first", ["firstp"] );
1692 * t( "Last Element", "p:last", ["first"] );
1693 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1694 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1695 * t( "Position Equals", "p:eq(1)", ["ap"] );
1696 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1697 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1698 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1699 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1700 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1702 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1704 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1705 * t( "All Children of ID with no children", "#firstUL/*", [] );
1707 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1708 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1709 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1710 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1711 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1712 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1713 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1715 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1716 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1717 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1720 * @type Array<Element>
1724 find: function( t, context ) {
1725 // Make sure that the context is a DOM Element
1726 if ( context && context.nodeType == undefined )
1729 // Set the correct context (if none is provided)
1730 context = context || jQuery.context || document;
1732 if ( t.constructor != String ) return [t];
1734 if ( !t.indexOf("//") ) {
1735 context = context.documentElement;
1736 t = t.substr(2,t.length);
1737 } else if ( !t.indexOf("/") ) {
1738 context = context.documentElement;
1739 t = t.substr(1,t.length);
1740 // FIX Assume the root element is right :(
1741 if ( t.indexOf("/") >= 1 )
1742 t = t.substr(t.indexOf("/"),t.length);
1745 var ret = [context];
1749 while ( t.length > 0 && last != t ) {
1753 t = jQuery.trim(t).replace( /^\/\//i, "" );
1755 var foundToken = false;
1757 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1758 if ( foundToken ) continue;
1760 var re = new RegExp("^(" + jQuery.token[i] + ")");
1764 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1765 t = jQuery.trim( t.replace( re, "" ) );
1770 if ( !foundToken ) {
1771 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1772 if ( ret[0] == context ) ret.shift();
1773 done = jQuery.merge( done, ret );
1774 r = ret = [context];
1775 t = " " + t.substr(1,t.length);
1777 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1778 var m = re2.exec(t);
1780 if ( m[1] == "#" ) {
1781 // Ummm, should make this work in all XML docs
1782 var oid = document.getElementById(m[2]);
1783 r = ret = oid ? [oid] : [];
1784 t = t.replace( re2, "" );
1786 if ( !m[2] || m[1] == "." ) m[2] = "*";
1788 for ( var i = 0; i < ret.length; i++ )
1789 r = jQuery.merge( r,
1791 jQuery.getAll(ret[i]) :
1792 ret[i].getElementsByTagName(m[2])
1800 var val = jQuery.filter(t,r);
1802 t = jQuery.trim(val.t);
1806 if ( ret && ret[0] == context ) ret.shift();
1807 done = jQuery.merge( done, ret );
1812 getAll: function(o,r) {
1814 var s = o.childNodes;
1815 for ( var i = 0; i < s.length; i++ )
1816 if ( s[i].nodeType == 1 ) {
1818 jQuery.getAll( s[i], r );
1823 attr: function(elem, name, value){
1826 "class": "className",
1827 "float": "cssFloat",
1828 innerHTML: "innerHTML",
1829 className: "className",
1831 disabled: "disabled",
1835 // IE actually uses filters for opacity ... elem is actually elem.style
1836 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
1837 // IE has trouble with opacity if it does not have layout
1838 // Would prefer to check element.hasLayout first but don't have access to the element here
1840 if (value == 1) // Remove filter to avoid more IE weirdness
1841 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
1843 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
1844 } else if (name == "opacity" && jQuery.browser.msie) {
1845 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
1848 // Mozilla doesn't play well with opacity 1
1849 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
1852 if ( value != undefined ) elem[fix[name]] = value;
1853 return elem[fix[name]];
1854 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1855 return elem.getAttributeNode(name).nodeValue;
1856 } else if ( elem.getAttribute != undefined ) {
1857 if ( value != undefined ) elem.setAttribute( name, value );
1858 return elem.getAttribute( name, 2 );
1860 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1861 if ( value != undefined ) elem[name] = value;
1866 // The regular expressions that power the parsing engine
1868 // Match: [@value='test'], [@foo]
1869 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1871 // Match: [div], [div p]
1872 "(\\[)\s*(.*?)\s*\\]",
1874 // Match: :contains('foo')
1875 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1877 // Match: :even, :last-chlid
1881 filter: function(t,r,not) {
1882 // Figure out if we're doing regular, or inverse, filtering
1883 var g = not !== false ? jQuery.grep :
1884 function(a,f) {return jQuery.grep(a,f,true);};
1886 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1888 var p = jQuery.parse;
1890 for ( var i = 0; i < p.length; i++ ) {
1892 // Look for, and replace, string-like sequences
1893 // and finally build a regexp out of it
1894 var re = new RegExp(
1895 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1897 var m = re.exec( t );
1900 // Re-organize the first match
1902 m = ["",m[1], m[3], m[2], m[5]];
1904 // Remove what we just matched
1905 t = t.replace( re, "" );
1911 // :not() is a special case that can be optimized by
1912 // keeping it out of the expression list
1913 if ( m[1] == ":" && m[2] == "not" )
1914 r = jQuery.filter(m[3],r,false).r;
1916 // Otherwise, find the expression to execute
1918 var f = jQuery.expr[m[1]];
1919 if ( f.constructor != String )
1920 f = jQuery.expr[m[1]][m[2]];
1922 // Build a custom macro to enclose it
1923 eval("f = function(a,i){" +
1924 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1925 "return " + f + "}");
1927 // Execute it against the current filter
1932 // Return an array of filtered elements (r)
1933 // and the modified expression string (t)
1934 return { r: r, t: t };
1938 * Remove the whitespace from the beginning and end of a string.
1940 * @example $.trim(" hello, how are you? ");
1941 * @result "hello, how are you?"
1945 * @param String str The string to trim.
1949 return t.replace(/^\s+|\s+$/g, "");
1953 * All ancestors of a given element.
1957 * @type Array<Element>
1958 * @param Element elem The element to find the ancestors of.
1959 * @cat DOM/Traversing
1961 parents: function( elem ){
1963 var cur = elem.parentNode;
1964 while ( cur && cur != document ) {
1965 matched.push( cur );
1966 cur = cur.parentNode;
1972 * All elements on a specified axis.
1977 * @param Element elem The element to find all the siblings of (including itself).
1978 * @cat DOM/Traversing
1980 sibling: function(elem, pos, not) {
1984 var siblings = elem.parentNode.childNodes;
1985 for ( var i = 0; i < siblings.length; i++ ) {
1986 if ( not === true && siblings[i] == elem ) continue;
1988 if ( siblings[i].nodeType == 1 )
1989 elems.push( siblings[i] );
1990 if ( siblings[i] == elem )
1991 elems.n = elems.length - 1;
1995 return jQuery.extend( elems, {
1996 last: elems.n == elems.length - 1,
1997 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1998 prev: elems[elems.n - 1],
1999 next: elems[elems.n + 1]
2004 * Merge two arrays together, removing all duplicates. The final order
2005 * or the new array is: All the results from the first array, followed
2006 * by the unique results from the second array.
2008 * @example $.merge( [0,1,2], [2,3,4] )
2009 * @result [0,1,2,3,4]
2011 * @example $.merge( [3,2,1], [4,3,2] )
2016 * @param Array first The first array to merge.
2017 * @param Array second The second array to merge.
2020 merge: function(first, second) {
2023 // Move b over to the new array (this helps to avoid
2024 // StaticNodeList instances)
2025 for ( var k = 0; k < first.length; k++ )
2026 result[k] = first[k];
2028 // Now check for duplicates between a and b and only
2029 // add the unique items
2030 for ( var i = 0; i < second.length; i++ ) {
2031 var noCollision = true;
2033 // The collision-checking process
2034 for ( var j = 0; j < first.length; j++ )
2035 if ( second[i] == first[j] )
2036 noCollision = false;
2038 // If the item is unique, add it
2040 result.push( second[i] );
2047 * Filter items out of an array, by using a filter function.
2048 * The specified function will be passed two arguments: The
2049 * current array item and the index of the item in the array. The
2050 * function should return 'true' if you wish to keep the item in
2051 * the array, false if it should be removed.
2053 * @example $.grep( [0,1,2], function(i){
2060 * @param Array array The Array to find items in.
2061 * @param Function fn The function to process each item against.
2062 * @param Boolean inv Invert the selection - select the opposite of the function.
2065 grep: function(elems, fn, inv) {
2066 // If a string is passed in for the function, make a function
2067 // for it (a handy shortcut)
2068 if ( fn.constructor == String )
2069 fn = new Function("a","i","return " + fn);
2073 // Go through the array, only saving the items
2074 // that pass the validator function
2075 for ( var i = 0; i < elems.length; i++ )
2076 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2077 result.push( elems[i] );
2083 * Translate all items in an array to another array of items.
2084 * The translation function that is provided to this method is
2085 * called for each item in the array and is passed one argument:
2086 * The item to be translated. The function can then return:
2087 * The translated value, 'null' (to remove the item), or
2088 * an array of values - which will be flattened into the full array.
2090 * @example $.map( [0,1,2], function(i){
2095 * @example $.map( [0,1,2], function(i){
2096 * return i > 0 ? i + 1 : null;
2100 * @example $.map( [0,1,2], function(i){
2101 * return [ i, i + 1 ];
2103 * @result [0, 1, 1, 2, 2, 3]
2107 * @param Array array The Array to translate.
2108 * @param Function fn The function to process each item against.
2111 map: function(elems, fn) {
2112 // If a string is passed in for the function, make a function
2113 // for it (a handy shortcut)
2114 if ( fn.constructor == String )
2115 fn = new Function("a","return " + fn);
2119 // Go through the array, translating each of the items to their
2120 // new value (or values).
2121 for ( var i = 0; i < elems.length; i++ ) {
2122 var val = fn(elems[i],i);
2124 if ( val !== null && val != undefined ) {
2125 if ( val.constructor != Array ) val = [val];
2126 result = jQuery.merge( result, val );
2134 * A number of helper functions used for managing events.
2135 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2139 // Bind an event to an element
2140 // Original by Dean Edwards
2141 add: function(element, type, handler) {
2142 // For whatever reason, IE has trouble passing the window object
2143 // around, causing it to be cloned in the process
2144 if ( jQuery.browser.msie && element.setInterval != undefined )
2147 // Make sure that the function being executed has a unique ID
2148 if ( !handler.guid )
2149 handler.guid = this.guid++;
2151 // Init the element's event structure
2152 if (!element.events)
2153 element.events = {};
2155 // Get the current list of functions bound to this event
2156 var handlers = element.events[type];
2158 // If it hasn't been initialized yet
2160 // Init the event handler queue
2161 handlers = element.events[type] = {};
2163 // Remember an existing handler, if it's already there
2164 if (element["on" + type])
2165 handlers[0] = element["on" + type];
2168 // Add the function to the element's handler list
2169 handlers[handler.guid] = handler;
2171 // And bind the global event handler to the element
2172 element["on" + type] = this.handle;
2174 // Remember the function in a global list (for triggering)
2175 if (!this.global[type])
2176 this.global[type] = [];
2177 this.global[type].push( element );
2183 // Detach an event or set of events from an element
2184 remove: function(element, type, handler) {
2186 if (type && element.events[type])
2188 delete element.events[type][handler.guid];
2190 for ( var i in element.events[type] )
2191 delete element.events[type][i];
2193 for ( var j in element.events )
2194 this.remove( element, j );
2197 trigger: function(type,data,element) {
2198 // Touch up the incoming data
2201 // Handle a global trigger
2203 var g = this.global[type];
2205 for ( var i = 0; i < g.length; i++ )
2206 this.trigger( type, data, g[i] );
2208 // Handle triggering a single element
2209 } else if ( element["on" + type] ) {
2210 // Pass along a fake event
2211 data.unshift( this.fix({ type: type, target: element }) );
2213 // Trigger the event
2214 element["on" + type].apply( element, data );
2218 handle: function(event) {
2219 if ( typeof jQuery == "undefined" ) return;
2221 event = event || jQuery.event.fix( window.event );
2223 // If no correct event was found, fail
2224 if ( !event ) return;
2226 var returnValue = true;
2228 var c = this.events[event.type];
2230 var args = [].slice.call( arguments, 1 );
2231 args.unshift( event );
2233 for ( var j in c ) {
2234 if ( c[j].apply( this, args ) === false ) {
2235 event.preventDefault();
2236 event.stopPropagation();
2237 returnValue = false;
2244 fix: function(event) {
2246 event.preventDefault = function() {
2247 this.returnValue = false;
2250 event.stopPropagation = function() {
2251 this.cancelBubble = true;
2262 * Contains flags for the useragent, read from navigator.userAgent.
2263 * Available flags are: safari, opera, msie, mozilla
2264 * This property is available before the DOM is ready, therefore you can
2265 * use it to add ready events only for certain browsers.
2267 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2268 * jQBrowser plugin</a> for advanced browser detection:
2270 * @example $.browser.msie
2271 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2273 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2274 * @desc Alerts "this is safari!" only for safari browsers
2281 var b = navigator.userAgent.toLowerCase();
2283 // Figure out what browser is being used
2285 safari: /webkit/.test(b),
2286 opera: /opera/.test(b),
2287 msie: /msie/.test(b) && !/opera/.test(b),
2288 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2291 // Check to see if the W3C box model is being used
2292 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2298 * Append all of the matched elements to another, specified, set of elements.
2299 * This operation is, essentially, the reverse of doing a regular
2300 * $(A).append(B), in that instead of appending B to A, you're appending
2303 * @example $("p").appendTo("#foo");
2304 * @before <p>I would like to say: </p><div id="foo"></div>
2305 * @result <div id="foo"><p>I would like to say: </p></div>
2309 * @param String expr A jQuery expression of elements to match.
2310 * @cat DOM/Manipulation
2315 * Prepend all of the matched elements to another, specified, set of elements.
2316 * This operation is, essentially, the reverse of doing a regular
2317 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2320 * @example $("p").prependTo("#foo");
2321 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2322 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2326 * @param String expr A jQuery expression of elements to match.
2327 * @cat DOM/Manipulation
2329 prependTo: "prepend",
2332 * Insert all of the matched elements before another, specified, set of elements.
2333 * This operation is, essentially, the reverse of doing a regular
2334 * $(A).before(B), in that instead of inserting B before A, you're inserting
2337 * @example $("p").insertBefore("#foo");
2338 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2339 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2341 * @name insertBefore
2343 * @param String expr A jQuery expression of elements to match.
2344 * @cat DOM/Manipulation
2346 insertBefore: "before",
2349 * Insert all of the matched elements after another, specified, set of elements.
2350 * This operation is, essentially, the reverse of doing a regular
2351 * $(A).after(B), in that instead of inserting B after A, you're inserting
2354 * @example $("p").insertAfter("#foo");
2355 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2356 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2360 * @param String expr A jQuery expression of elements to match.
2361 * @cat DOM/Manipulation
2363 insertAfter: "after"
2367 * Get the current CSS width of the first matched element.
2369 * @example $("p").width();
2370 * @before <p>This is just a test.</p>
2379 * Set the CSS width of every matched element. Be sure to include
2380 * the "px" (or other unit of measurement) after the number that you
2381 * specify, otherwise you might get strange results.
2383 * @example $("p").width("20px");
2384 * @before <p>This is just a test.</p>
2385 * @result <p style="width:20px;">This is just a test.</p>
2389 * @param String val Set the CSS property to the specified value.
2394 * Get the current CSS height of the first matched element.
2396 * @example $("p").height();
2397 * @before <p>This is just a test.</p>
2406 * Set the CSS height of every matched element. Be sure to include
2407 * the "px" (or other unit of measurement) after the number that you
2408 * specify, otherwise you might get strange results.
2410 * @example $("p").height("20px");
2411 * @before <p>This is just a test.</p>
2412 * @result <p style="height:20px;">This is just a test.</p>
2416 * @param String val Set the CSS property to the specified value.
2421 * Get the current CSS top of the first matched element.
2423 * @example $("p").top();
2424 * @before <p>This is just a test.</p>
2433 * Set the CSS top of every matched element. Be sure to include
2434 * the "px" (or other unit of measurement) after the number that you
2435 * specify, otherwise you might get strange results.
2437 * @example $("p").top("20px");
2438 * @before <p>This is just a test.</p>
2439 * @result <p style="top:20px;">This is just a test.</p>
2443 * @param String val Set the CSS property to the specified value.
2448 * Get the current CSS left of the first matched element.
2450 * @example $("p").left();
2451 * @before <p>This is just a test.</p>
2460 * Set the CSS left of every matched element. Be sure to include
2461 * the "px" (or other unit of measurement) after the number that you
2462 * specify, otherwise you might get strange results.
2464 * @example $("p").left("20px");
2465 * @before <p>This is just a test.</p>
2466 * @result <p style="left:20px;">This is just a test.</p>
2470 * @param String val Set the CSS property to the specified value.
2475 * Get the current CSS position of the first matched element.
2477 * @example $("p").position();
2478 * @before <p>This is just a test.</p>
2487 * Set the CSS position of every matched element.
2489 * @example $("p").position("relative");
2490 * @before <p>This is just a test.</p>
2491 * @result <p style="position:relative;">This is just a test.</p>
2495 * @param String val Set the CSS property to the specified value.
2500 * Get the current CSS float of the first matched element.
2502 * @example $("p").float();
2503 * @before <p>This is just a test.</p>
2512 * Set the CSS float of every matched element.
2514 * @example $("p").float("left");
2515 * @before <p>This is just a test.</p>
2516 * @result <p style="float:left;">This is just a test.</p>
2520 * @param String val Set the CSS property to the specified value.
2525 * Get the current CSS overflow of the first matched element.
2527 * @example $("p").overflow();
2528 * @before <p>This is just a test.</p>
2537 * Set the CSS overflow of every matched element.
2539 * @example $("p").overflow("auto");
2540 * @before <p>This is just a test.</p>
2541 * @result <p style="overflow:auto;">This is just a test.</p>
2545 * @param String val Set the CSS property to the specified value.
2550 * Get the current CSS color of the first matched element.
2552 * @example $("p").color();
2553 * @before <p>This is just a test.</p>
2562 * Set the CSS color of every matched element.
2564 * @example $("p").color("blue");
2565 * @before <p>This is just a test.</p>
2566 * @result <p style="color:blue;">This is just a test.</p>
2570 * @param String val Set the CSS property to the specified value.
2575 * Get the current CSS background of the first matched element.
2577 * @example $("p").background();
2578 * @before <p style="background:blue;">This is just a test.</p>
2587 * Set the CSS background of every matched element.
2589 * @example $("p").background("blue");
2590 * @before <p>This is just a test.</p>
2591 * @result <p style="background:blue;">This is just a test.</p>
2595 * @param String val Set the CSS property to the specified value.
2599 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2602 * Reduce the set of matched elements to a single element.
2603 * The position of the element in the set of matched elements
2604 * starts at 0 and goes to length - 1.
2606 * @example $("p").eq(1)
2607 * @before <p>This is just a test.</p><p>So is this</p>
2608 * @result [ <p>So is this</p> ]
2612 * @param Number pos The index of the element that you wish to limit to.
2617 * Reduce the set of matched elements to all elements before a given position.
2618 * The position of the element in the set of matched elements
2619 * starts at 0 and goes to length - 1.
2621 * @example $("p").lt(1)
2622 * @before <p>This is just a test.</p><p>So is this</p>
2623 * @result [ <p>This is just a test.</p> ]
2627 * @param Number pos Reduce the set to all elements below this position.
2632 * Reduce the set of matched elements to all elements after a given position.
2633 * The position of the element in the set of matched elements
2634 * starts at 0 and goes to length - 1.
2636 * @example $("p").gt(0)
2637 * @before <p>This is just a test.</p><p>So is this</p>
2638 * @result [ <p>So is this</p> ]
2642 * @param Number pos Reduce the set to all elements after this position.
2647 * Filter the set of elements to those that contain the specified text.
2649 * @example $("p").contains("test")
2650 * @before <p>This is just a test.</p><p>So is this</p>
2651 * @result [ <p>This is just a test.</p> ]
2655 * @param String str The string that will be contained within the text of an element.
2656 * @cat DOM/Traversing
2659 filter: [ "eq", "lt", "gt", "contains" ],
2663 * Get the current value of the first matched element.
2665 * @example $("input").val();
2666 * @before <input type="text" value="some text"/>
2667 * @result "some text"
2669 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2670 * ok( !$("#text1").val() == "", "Check for value of input element" );
2674 * @cat DOM/Attributes
2678 * Set the value of every matched element.
2680 * @example $("input").value("test");
2681 * @before <input type="text" value="some text"/>
2682 * @result <input type="text" value="test"/>
2684 * @test document.getElementById('text1').value = "bla";
2685 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2686 * $("#text1").val('test');
2687 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2691 * @param String val Set the property to the specified value.
2692 * @cat DOM/Attributes
2697 * Get the html contents of the first matched element.
2699 * @example $("div").html();
2700 * @before <div><input/></div>
2705 * @cat DOM/Attributes
2709 * Set the html contents of every matched element.
2711 * @example $("div").html("<b>new stuff</b>");
2712 * @before <div><input/></div>
2713 * @result <div><b>new stuff</b></div>
2715 * @test var div = $("div");
2716 * div.html("<b>test</b>");
2718 * for ( var i = 0; i < div.size(); i++ ) {
2719 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2721 * ok( pass, "Set HTML" );
2725 * @param String val Set the html contents to the specified value.
2726 * @cat DOM/Attributes
2731 * Get the current id of the first matched element.
2733 * @example $("input").id();
2734 * @before <input type="text" id="test" value="some text"/>
2737 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2738 * ok( $("#foo").id() == "foo", "Check for id" );
2739 * ok( !$("head").id(), "Check for id" );
2743 * @cat DOM/Attributes
2747 * Set the id of every matched element.
2749 * @example $("input").id("newid");
2750 * @before <input type="text" id="test" value="some text"/>
2751 * @result <input type="text" id="newid" value="some text"/>
2755 * @param String val Set the property to the specified value.
2756 * @cat DOM/Attributes
2761 * Get the current title of the first matched element.
2763 * @example $("img").title();
2764 * @before <img src="test.jpg" title="my image"/>
2765 * @result "my image"
2767 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2768 * ok( !$("#yahoo").title(), "Check for title" );
2772 * @cat DOM/Attributes
2776 * Set the title of every matched element.
2778 * @example $("img").title("new title");
2779 * @before <img src="test.jpg" title="my image"/>
2780 * @result <img src="test.jpg" title="new image"/>
2784 * @param String val Set the property to the specified value.
2785 * @cat DOM/Attributes
2790 * Get the current name of the first matched element.
2792 * @example $("input").name();
2793 * @before <input type="text" name="username"/>
2794 * @result "username"
2796 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2797 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2798 * ok( !$("#area1").name(), "Check for name" );
2802 * @cat DOM/Attributes
2806 * Set the name of every matched element.
2808 * @example $("input").name("user");
2809 * @before <input type="text" name="username"/>
2810 * @result <input type="text" name="user"/>
2814 * @param String val Set the property to the specified value.
2815 * @cat DOM/Attributes
2820 * Get the current href of the first matched element.
2822 * @example $("a").href();
2823 * @before <a href="test.html">my link</a>
2824 * @result "test.html"
2828 * @cat DOM/Attributes
2832 * Set the href of every matched element.
2834 * @example $("a").href("test2.html");
2835 * @before <a href="test.html">my link</a>
2836 * @result <a href="test2.html">my link</a>
2840 * @param String val Set the property to the specified value.
2841 * @cat DOM/Attributes
2846 * Get the current src of the first matched element.
2848 * @example $("img").src();
2849 * @before <img src="test.jpg" title="my image"/>
2850 * @result "test.jpg"
2854 * @cat DOM/Attributes
2858 * Set the src of every matched element.
2860 * @example $("img").src("test2.jpg");
2861 * @before <img src="test.jpg" title="my image"/>
2862 * @result <img src="test2.jpg" title="my image"/>
2866 * @param String val Set the property to the specified value.
2867 * @cat DOM/Attributes
2872 * Get the current rel of the first matched element.
2874 * @example $("a").rel();
2875 * @before <a href="test.html" rel="nofollow">my link</a>
2876 * @result "nofollow"
2880 * @cat DOM/Attributes
2884 * Set the rel of every matched element.
2886 * @example $("a").rel("nofollow");
2887 * @before <a href="test.html">my link</a>
2888 * @result <a href="test.html" rel="nofollow">my link</a>
2892 * @param String val Set the property to the specified value.
2893 * @cat DOM/Attributes
2900 * Get a set of elements containing the unique parents of the matched
2903 * @example $("p").parent()
2904 * @before <div><p>Hello</p><p>Hello</p></div>
2905 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2909 * @cat DOM/Traversing
2913 * Get a set of elements containing the unique parents of the matched
2914 * set of elements, and filtered by an expression.
2916 * @example $("p").parent(".selected")
2917 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2918 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2922 * @param String expr An expression to filter the parents with
2923 * @cat DOM/Traversing
2925 parent: "a.parentNode",
2928 * Get a set of elements containing the unique ancestors of the matched
2929 * set of elements (except for the root element).
2931 * @example $("span").ancestors()
2932 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2933 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2937 * @cat DOM/Traversing
2941 * Get a set of elements containing the unique ancestors of the matched
2942 * set of elements, and filtered by an expression.
2944 * @example $("span").ancestors("p")
2945 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2946 * @result [ <p><span>Hello</span></p> ]
2950 * @param String expr An expression to filter the ancestors with
2951 * @cat DOM/Traversing
2953 ancestors: jQuery.parents,
2956 * Get a set of elements containing the unique ancestors of the matched
2957 * set of elements (except for the root element).
2959 * @example $("span").ancestors()
2960 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2961 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2965 * @cat DOM/Traversing
2969 * Get a set of elements containing the unique ancestors of the matched
2970 * set of elements, and filtered by an expression.
2972 * @example $("span").ancestors("p")
2973 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2974 * @result [ <p><span>Hello</span></p> ]
2978 * @param String expr An expression to filter the ancestors with
2979 * @cat DOM/Traversing
2981 parents: jQuery.parents,
2984 * Get a set of elements containing the unique next siblings of each of the
2985 * matched set of elements.
2987 * It only returns the very next sibling, not all next siblings.
2989 * @example $("p").next()
2990 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2991 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2995 * @cat DOM/Traversing
2999 * Get a set of elements containing the unique next siblings of each of the
3000 * matched set of elements, and filtered by an expression.
3002 * It only returns the very next sibling, not all next siblings.
3004 * @example $("p").next(".selected")
3005 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
3006 * @result [ <p class="selected">Hello Again</p> ]
3010 * @param String expr An expression to filter the next Elements with
3011 * @cat DOM/Traversing
3013 next: "jQuery.sibling(a).next",
3016 * Get a set of elements containing the unique previous siblings of each of the
3017 * matched set of elements.
3019 * It only returns the immediately previous sibling, not all previous siblings.
3021 * @example $("p").prev()
3022 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3023 * @result [ <div><span>Hello Again</span></div> ]
3027 * @cat DOM/Traversing
3031 * Get a set of elements containing the unique previous siblings of each of the
3032 * matched set of elements, and filtered by an expression.
3034 * It only returns the immediately previous sibling, not all previous siblings.
3036 * @example $("p").previous(".selected")
3037 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3038 * @result [ <div><span>Hello</span></div> ]
3042 * @param String expr An expression to filter the previous Elements with
3043 * @cat DOM/Traversing
3045 prev: "jQuery.sibling(a).prev",
3048 * Get a set of elements containing all of the unique siblings of each of the
3049 * matched set of elements.
3051 * @example $("div").siblings()
3052 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3053 * @result [ <p>Hello</p>, <p>And Again</p> ]
3055 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3059 * @cat DOM/Traversing
3063 * Get a set of elements containing all of the unique siblings of each of the
3064 * matched set of elements, and filtered by an expression.
3066 * @example $("div").siblings(".selected")
3067 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3068 * @result [ <p class="selected">Hello Again</p> ]
3070 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3071 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3075 * @param String expr An expression to filter the sibling Elements with
3076 * @cat DOM/Traversing
3078 siblings: "jQuery.sibling(a, null, true)",
3082 * Get a set of elements containing all of the unique children of each of the
3083 * matched set of elements.
3085 * @example $("div").children()
3086 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3087 * @result [ <span>Hello Again</span> ]
3089 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3093 * @cat DOM/Traversing
3097 * Get a set of elements containing all of the unique children of each of the
3098 * matched set of elements, and filtered by an expression.
3100 * @example $("div").children(".selected")
3101 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3102 * @result [ <p class="selected">Hello Again</p> ]
3104 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3108 * @param String expr An expression to filter the child Elements with
3109 * @cat DOM/Traversing
3111 children: "jQuery.sibling(a.firstChild)"
3117 * Remove an attribute from each of the matched elements.
3119 * @example $("input").removeAttr("disabled")
3120 * @before <input disabled="disabled"/>
3125 * @param String name The name of the attribute to remove.
3128 removeAttr: function( key ) {
3129 this.removeAttribute( key );
3133 * Displays each of the set of matched elements if they are hidden.
3135 * @example $("p").show()
3136 * @before <p style="display: none">Hello</p>
3137 * @result [ <p style="display: block">Hello</p> ]
3139 * @test var pass = true, div = $("div");
3140 * div.show().each(function(){
3141 * if ( this.style.display == "none" ) pass = false;
3143 * ok( pass, "Show" );
3150 this.style.display = this.oldblock ? this.oldblock : "";
3151 if ( jQuery.css(this,"display") == "none" )
3152 this.style.display = "block";
3156 * Hides each of the set of matched elements if they are shown.
3158 * @example $("p").hide()
3159 * @before <p>Hello</p>
3160 * @result [ <p style="display: none">Hello</p> ]
3162 * var pass = true, div = $("div");
3163 * div.hide().each(function(){
3164 * if ( this.style.display != "none" ) pass = false;
3166 * ok( pass, "Hide" );
3173 this.oldblock = this.oldblock || jQuery.css(this,"display");
3174 if ( this.oldblock == "none" )
3175 this.oldblock = "block";
3176 this.style.display = "none";
3180 * Toggles each of the set of matched elements. If they are shown,
3181 * toggle makes them hidden. If they are hidden, toggle
3184 * @example $("p").toggle()
3185 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3186 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3193 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3197 * Adds the specified class to each of the set of matched elements.
3199 * @example $("p").addClass("selected")
3200 * @before <p>Hello</p>
3201 * @result [ <p class="selected">Hello</p> ]
3203 * @test var div = $("div");
3204 * div.addClass("test");
3206 * for ( var i = 0; i < div.size(); i++ ) {
3207 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3209 * ok( pass, "Add Class" );
3213 * @param String class A CSS class to add to the elements
3216 addClass: function(c){
3217 jQuery.className.add(this,c);
3221 * Removes the specified class from the set of matched elements.
3223 * @example $("p").removeClass("selected")
3224 * @before <p class="selected">Hello</p>
3225 * @result [ <p>Hello</p> ]
3227 * @test var div = $("div").addClass("test");
3228 * div.removeClass("test");
3230 * for ( var i = 0; i < div.size(); i++ ) {
3231 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3233 * ok( pass, "Remove Class" );
3237 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3238 * div.removeClass("test").removeClass("bar").removeClass("foo");
3240 * for ( var i = 0; i < div.size(); i++ ) {
3241 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3243 * ok( pass, "Remove multiple classes" );
3247 * @param String class A CSS class to remove from the elements
3250 removeClass: function(c){
3251 jQuery.className.remove(this,c);
3255 * Adds the specified class if it is present, removes it if it is
3258 * @example $("p").toggleClass("selected")
3259 * @before <p>Hello</p><p class="selected">Hello Again</p>
3260 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3264 * @param String class A CSS class with which to toggle the elements
3267 toggleClass: function( c ){
3268 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3272 * Removes all matched elements from the DOM. This does NOT remove them from the
3273 * jQuery object, allowing you to use the matched elements further.
3275 * @example $("p").remove();
3276 * @before <p>Hello</p> how are <p>you?</p>
3281 * @cat DOM/Manipulation
3285 * Removes only elements (out of the list of matched elements) that match
3286 * the specified jQuery expression. This does NOT remove them from the
3287 * jQuery object, allowing you to use the matched elements further.
3289 * @example $("p").remove(".hello");
3290 * @before <p class="hello">Hello</p> how are <p>you?</p>
3291 * @result how are <p>you?</p>
3295 * @param String expr A jQuery expression to filter elements by.
3296 * @cat DOM/Manipulation
3298 remove: function(a){
3299 if ( !a || jQuery.filter( a, [this] ).r )
3300 this.parentNode.removeChild( this );
3304 * Removes all child nodes from the set of matched elements.
3306 * @example $("p").empty()
3307 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3308 * @result [ <p></p> ]
3312 * @cat DOM/Manipulation
3315 while ( this.firstChild )
3316 this.removeChild( this.firstChild );
3320 * Binds a handler to a particular event (like click) for each matched element.
3321 * The event handler is passed an event object that you can use to prevent
3322 * default behaviour. To stop both default action and event bubbling, your handler
3323 * has to return false.
3325 * @example $("p").bind( "click", function() {
3326 * alert( $(this).text() );
3328 * @before <p>Hello</p>
3329 * @result alert("Hello")
3331 * @example $("form").bind( "submit", function() { return false; } )
3332 * @desc Cancel a default action and prevent it from bubbling by returning false
3333 * from your function.
3335 * @example $("form").bind( "submit", function(event) {
3336 * event.preventDefault();
3338 * @desc Cancel only the default action by using the preventDefault method.
3341 * @example $("form").bind( "submit", function(event) {
3342 * event.stopPropagation();
3344 * @desc Stop only an event from bubbling by using the stopPropagation method.
3348 * @param String type An event type
3349 * @param Function fn A function to bind to the event on each of the set of matched elements
3352 bind: function( type, fn ) {
3353 if ( fn.constructor == String )
3354 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3355 jQuery.event.add( this, type, fn );
3359 * The opposite of bind, removes a bound event from each of the matched
3360 * elements. You must pass the identical function that was used in the original
3363 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3364 * @before <p onclick="alert('Hello');">Hello</p>
3365 * @result [ <p>Hello</p> ]
3369 * @param String type An event type
3370 * @param Function fn A function to unbind from the event on each of the set of matched elements
3375 * Removes all bound events of a particular type from each of the matched
3378 * @example $("p").unbind( "click" )
3379 * @before <p onclick="alert('Hello');">Hello</p>
3380 * @result [ <p>Hello</p> ]
3384 * @param String type An event type
3389 * Removes all bound events from each of the matched elements.
3391 * @example $("p").unbind()
3392 * @before <p onclick="alert('Hello');">Hello</p>
3393 * @result [ <p>Hello</p> ]
3399 unbind: function( type, fn ) {
3400 jQuery.event.remove( this, type, fn );
3404 * Trigger a type of event on every matched element.
3406 * @example $("p").trigger("click")
3407 * @before <p click="alert('hello')">Hello</p>
3408 * @result alert('hello')
3412 * @param String type An event type to trigger.
3415 trigger: function( type, data ) {
3416 jQuery.event.trigger( type, data, this );