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 if ( a.constructor == String ) {
54 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
55 if ( m ) a = jQuery.clean( [ m[1] ] );
58 // Watch for when an array is passed in
59 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
60 // Assume that it is an array of DOM Elements
61 jQuery.merge( a, [] ) :
63 // Find the matching elements and save them for later
64 jQuery.find( a, c ) );
66 // See if an extra function was provided
67 var fn = arguments[ arguments.length - 1 ];
69 // If so, execute it in context
70 if ( fn && typeof fn == "function" )
74 // Map over the $ in case of overwrite
75 if ( typeof $ != "undefined" )
79 * This function accepts a string containing a CSS selector,
80 * basic XPath, or raw HTML, which is then used to match a set of elements.
81 * The HTML string is different from the traditional selectors in that
82 * it creates the DOM elements representing that HTML string, on the fly,
83 * to be (assumedly) inserted into the document later.
85 * The core functionality of jQuery centers around this function.
86 * Everything in jQuery is based upon this, or uses this in some way.
87 * The most basic use of this function is to pass in an expression
88 * (usually consisting of CSS or XPath), which then finds all matching
89 * elements and remembers them for later use.
91 * By default, $() looks for DOM elements within the context of the
92 * current HTML document.
94 * @example $("div > p")
95 * @desc This finds all p elements that are children of a div element.
96 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
97 * @result [ <p>two</p> ]
99 * @example $("<div><p>Hello</p></div>").appendTo("#body")
100 * @desc Creates a div element (and all of its contents) dynamically,
101 * and appends it to the element with the ID of body. Internally, an
102 * element is created and it's innerHTML property set to the given markup.
103 * It is therefore both quite flexible and limited.
106 * @param String expr An expression to search with, or a string of HTML to create on the fly.
112 * This function accepts a string containing a CSS selector, or
113 * basic XPath, which is then used to match a set of elements with the
114 * context of the specified DOM element, or document
116 * @example $("div", xml.responseXML)
117 * @desc This finds all div elements within the specified XML document.
120 * @param String expr An expression to search with.
121 * @param Element context A DOM Element, or Document, representing the base context.
127 * Wrap jQuery functionality around a specific DOM Element.
128 * This function also accepts XML Documents and Window objects
129 * as valid arguments (even though they are not DOM Elements).
131 * @example $(document).find("div > p")
132 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
133 * @result [ <p>two</p> ]
135 * @example $(document.body).background( "black" );
136 * @desc Sets the background color of the page to black.
139 * @param Element elem A DOM element to be encapsulated by a jQuery object.
145 * Wrap jQuery functionality around a set of DOM Elements.
147 * @example $( myForm.elements ).hide()
148 * @desc Hides all the input elements within a form
151 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
157 * A shorthand for $(document).ready(), allowing you to bind a function
158 * to be executed when the DOM document has finished loading. This function
159 * behaves just like $(document).ready(), in that it should be used to wrap
160 * all of the other $() operations on your page. While this function is,
161 * technically, chainable - there really isn't much use for chaining against it.
162 * You can have as many $(document).ready events on your page as you like.
164 * @example $(function(){
165 * // Document is ready
167 * @desc Executes the function when the DOM is ready to be used.
170 * @param Function fn The function to execute when the DOM is ready.
176 * A means of creating a cloned copy of a jQuery object. This function
177 * copies the set of matched elements from one jQuery object and creates
178 * another, new, jQuery object containing the same elements.
180 * @example var div = $("div");
181 * $( div ).find("p");
182 * @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).
185 * @param jQuery obj The jQuery object to be cloned.
190 // Map the jQuery namespace to the '$' one
193 jQuery.fn = jQuery.prototype = {
195 * The current version of jQuery.
206 * The number of elements currently matched.
208 * @example $("img").length;
209 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
212 * @test ok( $("div").length == 2, "Get Number of Elements Found" );
221 * The number of elements currently matched.
223 * @example $("img").size();
224 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
227 * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
238 * Access all matched elements. This serves as a backwards-compatible
239 * way of accessing all matched elements (other than the jQuery object
240 * itself, which is, in fact, an array of elements).
242 * @example $("img").get();
243 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
244 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
246 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
249 * @type Array<Element>
254 * Access a single matched element. num is used to access the
255 * Nth element matched.
257 * @example $("img").get(1);
258 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
259 * @result [ <img src="test1.jpg"/> ]
261 * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
265 * @param Number num Access the element in the Nth position.
270 * Set the jQuery object to an array of elements.
272 * @example $("img").get([ document.body ]);
273 * @result $("img").get() == [ document.body ]
278 * @param Elements elems An array of elements
281 get: function( num ) {
282 // Watch for when an array (of elements) is passed in
283 if ( num && num.constructor == Array ) {
285 // Use a tricky hack to make the jQuery object
286 // look and feel like an array
288 [].push.apply( this, num );
292 return num == undefined ?
294 // Return a 'clean' array
295 jQuery.merge( this, [] ) :
297 // Return just the object
302 * Execute a function within the context of every matched element.
303 * This means that every time the passed-in function is executed
304 * (which is once for every element matched) the 'this' keyword
305 * points to the specific element.
307 * Additionally, the function, when executed, is passed a single
308 * argument representing the position of the element in the matched
311 * @example $("img").each(function(){
312 * this.src = "test.jpg";
314 * @before <img/> <img/>
315 * @result <img src="test.jpg"/> <img src="test.jpg"/>
317 * @example $("img").each(function(i){
318 * alert( "Image #" + i + " is " + this );
320 * @before <img/> <img/>
321 * @result <img src="test.jpg"/> <img src="test.jpg"/>
323 * @test var div = $("div");
324 * div.each(function(){this.foo = 'zoo';});
326 * for ( var i = 0; i < div.size(); i++ ) {
327 * if ( div.get(i).foo != "zoo" ) pass = false;
329 * ok( pass, "Execute a function, Relative" );
333 * @param Function fn A function to execute
336 each: function( fn, args ) {
337 return jQuery.each( this, fn, args );
341 * Searches every matched element for the object and returns
342 * the index of the element, if found, starting with zero.
343 * Returns -1 if the object wasn't found.
345 * @example $("*").index(document.getElementById('foobar'))
346 * @before <div id="foobar"></div><b></b><span id="foo"></span>
349 * @example $("*").index(document.getElementById('foo'))
350 * @before <div id="foobar"></div><b></b><span id="foo"></span>
353 * @example $("*").index(document.getElementById('bar'))
354 * @before <div id="foobar"></div><b></b><span id="foo"></span>
357 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
358 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
359 * var inputElements = $('#radio1,#radio2,#check1,#check2');
360 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
361 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
362 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
363 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
364 * ok( inputElements.index(window) == -1, "Check for not found index" );
365 * ok( inputElements.index(document) == -1, "Check for not found index" );
369 * @param Object obj Object to search for
372 index: function( obj ) {
374 this.each(function(i){
375 if ( this == obj ) pos = i;
381 * Access a property on the first matched element.
382 * This method makes it easy to retrieve a property value
383 * from the first matched element.
385 * @example $("img").attr("src");
386 * @before <img src="test.jpg"/>
389 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
390 * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
391 * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
392 * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
393 * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
394 * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
395 * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
396 * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
397 * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
398 * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
399 * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
400 * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
404 * @param String name The name of the property to access.
409 * Set a hash of key/value object properties to all matched elements.
410 * This serves as the best way to set a large number of properties
411 * on all matched elements.
413 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
415 * @result <img src="test.jpg" alt="Test Image"/>
417 * @test var pass = true;
418 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
419 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
421 * ok( pass, "Set Multiple Attributes" );
425 * @param Hash prop A set of key/value pairs to set as object properties.
430 * Set a single property to a value, on all matched elements.
432 * @example $("img").attr("src","test.jpg");
434 * @result <img src="test.jpg"/>
436 * @test var div = $("div");
437 * div.attr("foo", "bar");
439 * for ( var i = 0; i < div.size(); i++ ) {
440 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
442 * ok( pass, "Set Attribute" );
444 * $("#name").attr('name', 'something');
445 * ok( $("#name").name() == 'something', 'Set name attribute' );
446 * $("#check2").attr('checked', true);
447 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
448 * $("#check2").attr('checked', false);
449 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
452 * $.get('data/dashboard.xml', function(xml) {
454 * $('tab', xml).each(function() {
455 * titles.push($(this).attr('title'));
457 * ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
458 * ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
464 * @param String key The name of the property to set.
465 * @param Object value The value to set the property to.
468 attr: function( key, value, type ) {
469 // Check to see if we're setting style values
470 return key.constructor != String || value != undefined ?
471 this.each(function(){
472 // See if we're setting a hash of styles
473 if ( value == undefined )
474 // Set all the styles
475 for ( var prop in key )
477 type ? this.style : this,
481 // See if we're setting a single key/value style
484 type ? this.style : this,
489 // Look for the case where we're accessing a style value
490 jQuery[ type || "attr" ]( this[0], key );
494 * Access a style property on the first matched element.
495 * This method makes it easy to retrieve a style property value
496 * from the first matched element.
498 * @example $("p").css("color");
499 * @before <p style="color:red;">Test Paragraph.</p>
501 * @desc Retrieves the color style of the first paragraph
503 * @example $("p").css("fontWeight");
504 * @before <p style="font-weight: bold;">Test Paragraph.</p>
506 * @desc Retrieves the font-weight style of the first paragraph.
507 * Note that for all style properties with a dash (like 'font-weight'), you have to
508 * write it in camelCase. In other words: Every time you have a '-' in a
509 * property, remove it and replace the next character with an uppercase
510 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
511 * borderStyle, borderBottomWidth etc.
513 * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
517 * @param String name The name of the property to access.
522 * Set a hash of key/value style properties to all matched elements.
523 * This serves as the best way to set a large number of style properties
524 * on all matched elements.
526 * @example $("p").css({ color: "red", background: "blue" });
527 * @before <p>Test Paragraph.</p>
528 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
530 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
531 * $('#foo').css({display: 'none'});
532 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
533 * $('#foo').css({display: 'block'});
534 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
538 * @param Hash prop A set of key/value pairs to set as style properties.
543 * Set a single style property to a value, on all matched elements.
545 * @example $("p").css("color","red");
546 * @before <p>Test Paragraph.</p>
547 * @result <p style="color:red;">Test Paragraph.</p>
548 * @desc Changes the color of all paragraphs to red
551 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
552 * $('#foo').css('display', 'none');
553 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
554 * $('#foo').css('display', 'block');
555 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
559 * @param String key The name of the property to set.
560 * @param Object value The value to set the property to.
563 css: function( key, value ) {
564 return this.attr( key, value, "curCSS" );
568 * Retrieve the text contents of all matched elements. The result is
569 * a string that contains the combined text contents of all matched
570 * elements. This method works on both HTML and XML documents.
572 * @example $("p").text();
573 * @before <p>Test Paragraph.</p>
574 * @result Test Paragraph.
576 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
577 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
586 for ( var j = 0; j < e.length; j++ ) {
587 var r = e[j].childNodes;
588 for ( var i = 0; i < r.length; i++ )
589 if ( r[i].nodeType != 8 )
590 t += r[i].nodeType != 1 ?
591 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
597 * Wrap all matched elements with a structure of other elements.
598 * This wrapping process is most useful for injecting additional
599 * stucture into a document, without ruining the original semantic
600 * qualities of a document.
602 * This works by going through the first element
603 * provided (which is generated, on the fly, from the provided HTML)
604 * and finds the deepest ancestor element within its
605 * structure - it is that element that will en-wrap everything else.
607 * This does not work with elements that contain text. Any necessary text
608 * must be added after the wrapping is done.
610 * @example $("p").wrap("<div class='wrap'></div>");
611 * @before <p>Test Paragraph.</p>
612 * @result <div class='wrap'><p>Test Paragraph.</p></div>
614 * @test var defaultText = 'Try them out:'
615 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
616 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
617 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
621 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
622 * @cat DOM/Manipulation
626 * Wrap all matched elements with a structure of other elements.
627 * This wrapping process is most useful for injecting additional
628 * stucture into a document, without ruining the original semantic
629 * qualities of a document.
631 * This works by going through the first element
632 * provided and finding the deepest ancestor element within its
633 * structure - it is that element that will en-wrap everything else.
635 * This does not work with elements that contain text. Any necessary text
636 * must be added after the wrapping is done.
638 * @example $("p").wrap( document.getElementById('content') );
639 * @before <p>Test Paragraph.</p><div id="content"></div>
640 * @result <div id="content"><p>Test Paragraph.</p></div>
642 * @test var defaultText = 'Try them out:'
643 * var result = $('#first').wrap(document.getElementById('empty')).parent();
644 * ok( result.is('ol'), 'Check for element wrapping' );
645 * ok( result.text() == defaultText, 'Check for element wrapping' );
649 * @param Element elem A DOM element that will be wrapped.
650 * @cat DOM/Manipulation
653 // The elements to wrap the target around
654 var a = jQuery.clean(arguments);
656 // Wrap each of the matched elements individually
657 return this.each(function(){
658 // Clone the structure that we're using to wrap
659 var b = a[0].cloneNode(true);
661 // Insert it before the element to be wrapped
662 this.parentNode.insertBefore( b, this );
664 // Find the deepest point in the wrap structure
665 while ( b.firstChild )
668 // Move the matched element to within the wrap structure
669 b.appendChild( this );
674 * Append any number of elements to the inside of every matched elements,
675 * generated from the provided HTML.
676 * This operation is similar to doing an appendChild to all the
677 * specified elements, adding them into the document.
679 * @example $("p").append("<b>Hello</b>");
680 * @before <p>I would like to say: </p>
681 * @result <p>I would like to say: <b>Hello</b></p>
683 * @test var defaultText = 'Try them out:'
684 * var result = $('#first').append('<b>buga</b>');
685 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
689 * @param String html A string of HTML, that will be created on the fly and appended to the target.
690 * @cat DOM/Manipulation
694 * Append an element to the inside of all matched elements.
695 * This operation is similar to doing an appendChild to all the
696 * specified elements, adding them into the document.
698 * @example $("p").append( $("#foo")[0] );
699 * @before <p>I would like to say: </p><b id="foo">Hello</b>
700 * @result <p>I would like to say: <b id="foo">Hello</b></p>
702 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
703 * $('#sap').append(document.getElementById('first'));
704 * ok( expected == $('#sap').text(), "Check for appending of element" );
708 * @param Element elem A DOM element that will be appended.
709 * @cat DOM/Manipulation
713 * Append any number of elements to the inside of all matched elements.
714 * This operation is similar to doing an appendChild to all the
715 * specified elements, adding them into the document.
717 * @example $("p").append( $("b") );
718 * @before <p>I would like to say: </p><b>Hello</b>
719 * @result <p>I would like to say: <b>Hello</b></p>
721 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
722 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
723 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
727 * @param Array<Element> elems An array of elements, all of which will be appended.
728 * @cat DOM/Manipulation
731 return this.domManip(arguments, true, 1, function(a){
732 this.appendChild( a );
737 * Prepend any number of elements to the inside of every matched elements,
738 * generated from the provided HTML.
739 * This operation is the best way to insert dynamically created elements
740 * inside, at the beginning, of all the matched element.
742 * @example $("p").prepend("<b>Hello</b>");
743 * @before <p>I would like to say: </p>
744 * @result <p><b>Hello</b>I would like to say: </p>
746 * @test var defaultText = 'Try them out:'
747 * var result = $('#first').prepend('<b>buga</b>');
748 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
752 * @param String html A string of HTML, that will be created on the fly and appended to the target.
753 * @cat DOM/Manipulation
757 * Prepend an element to the inside of all matched elements.
758 * This operation is the best way to insert an element inside, at the
759 * beginning, of all the matched element.
761 * @example $("p").prepend( $("#foo")[0] );
762 * @before <p>I would like to say: </p><b id="foo">Hello</b>
763 * @result <p><b id="foo">Hello</b>I would like to say: </p>
765 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
766 * $('#sap').prepend(document.getElementById('first'));
767 * ok( expected == $('#sap').text(), "Check for prepending of element" );
771 * @param Element elem A DOM element that will be appended.
772 * @cat DOM/Manipulation
776 * Prepend any number of elements to the inside of all matched elements.
777 * This operation is the best way to insert a set of elements inside, at the
778 * beginning, of all the matched element.
780 * @example $("p").prepend( $("b") );
781 * @before <p>I would like to say: </p><b>Hello</b>
782 * @result <p><b>Hello</b>I would like to say: </p>
784 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
785 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
786 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
790 * @param Array<Element> elems An array of elements, all of which will be appended.
791 * @cat DOM/Manipulation
793 prepend: function() {
794 return this.domManip(arguments, true, -1, function(a){
795 this.insertBefore( a, this.firstChild );
800 * Insert any number of dynamically generated elements before each of the
803 * @example $("p").before("<b>Hello</b>");
804 * @before <p>I would like to say: </p>
805 * @result <b>Hello</b><p>I would like to say: </p>
807 * @test var expected = 'This is a normal link: bugaYahoo';
808 * $('#yahoo').before('<b>buga</b>');
809 * ok( expected == $('#en').text(), 'Insert String before' );
813 * @param String html A string of HTML, that will be created on the fly and appended to the target.
814 * @cat DOM/Manipulation
818 * Insert an element before each of the matched elements.
820 * @example $("p").before( $("#foo")[0] );
821 * @before <p>I would like to say: </p><b id="foo">Hello</b>
822 * @result <b id="foo">Hello</b><p>I would like to say: </p>
824 * @test var expected = "This is a normal link: Try them out:Yahoo";
825 * $('#yahoo').before(document.getElementById('first'));
826 * ok( expected == $('#en').text(), "Insert element before" );
830 * @param Element elem A DOM element that will be appended.
831 * @cat DOM/Manipulation
835 * Insert any number of elements before each of the matched elements.
837 * @example $("p").before( $("b") );
838 * @before <p>I would like to say: </p><b>Hello</b>
839 * @result <b>Hello</b><p>I would like to say: </p>
841 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
842 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
843 * ok( expected == $('#en').text(), "Insert array of elements before" );
847 * @param Array<Element> elems An array of elements, all of which will be appended.
848 * @cat DOM/Manipulation
851 return this.domManip(arguments, false, 1, function(a){
852 this.parentNode.insertBefore( a, this );
857 * Insert any number of dynamically generated elements after each of the
860 * @example $("p").after("<b>Hello</b>");
861 * @before <p>I would like to say: </p>
862 * @result <p>I would like to say: </p><b>Hello</b>
864 * @test var expected = 'This is a normal link: Yahoobuga';
865 * $('#yahoo').after('<b>buga</b>');
866 * ok( expected == $('#en').text(), 'Insert String after' );
870 * @param String html A string of HTML, that will be created on the fly and appended to the target.
871 * @cat DOM/Manipulation
875 * Insert an element after each of the matched elements.
877 * @example $("p").after( $("#foo")[0] );
878 * @before <b id="foo">Hello</b><p>I would like to say: </p>
879 * @result <p>I would like to say: </p><b id="foo">Hello</b>
881 * @test var expected = "This is a normal link: YahooTry them out:";
882 * $('#yahoo').after(document.getElementById('first'));
883 * ok( expected == $('#en').text(), "Insert element after" );
887 * @param Element elem A DOM element that will be appended.
888 * @cat DOM/Manipulation
892 * Insert any number of elements after each of the matched elements.
894 * @example $("p").after( $("b") );
895 * @before <b>Hello</b><p>I would like to say: </p>
896 * @result <p>I would like to say: </p><b>Hello</b>
898 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
899 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
900 * ok( expected == $('#en').text(), "Insert array of elements after" );
904 * @param Array<Element> elems An array of elements, all of which will be appended.
905 * @cat DOM/Manipulation
908 return this.domManip(arguments, false, -1, function(a){
909 this.parentNode.insertBefore( a, this.nextSibling );
914 * End the most recent 'destructive' operation, reverting the list of matched elements
915 * back to its previous state. After an end operation, the list of matched elements will
916 * revert to the last state of matched elements.
918 * @example $("p").find("span").end();
919 * @before <p><span>Hello</span>, how are you?</p>
920 * @result $("p").find("span").end() == [ <p>...</p> ]
922 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
926 * @cat DOM/Traversing
929 return this.get( this.stack.pop() );
933 * Searches for all elements that match the specified expression.
934 * This method is the optimal way of finding additional descendant
935 * elements with which to process.
937 * All searching is done using a jQuery expression. The expression can be
938 * written using CSS 1-3 Selector syntax, or basic XPath.
940 * @example $("p").find("span");
941 * @before <p><span>Hello</span>, how are you?</p>
942 * @result $("p").find("span") == [ <span>Hello</span> ]
944 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
948 * @param String expr An expression to search with.
949 * @cat DOM/Traversing
952 return this.pushStack( jQuery.map( this, function(a){
953 return jQuery.find(t,a);
958 * Create cloned copies of all matched DOM Elements. This does
959 * not create a cloned copy of this particular jQuery object,
960 * instead it creates duplicate copies of all DOM Elements.
961 * This is useful for moving copies of the elements to another
962 * location in the DOM.
964 * @example $("b").clone().prependTo("p");
965 * @before <b>Hello</b><p>, how are you?</p>
966 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
968 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
969 * var clone = $('#yahoo').clone();
970 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
971 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
975 * @cat DOM/Manipulation
977 clone: function(deep) {
978 return this.pushStack( jQuery.map( this, function(a){
979 return a.cloneNode( deep != undefined ? deep : true );
984 * Removes all elements from the set of matched elements that do not
985 * match the specified expression. This method is used to narrow down
986 * the results of a search.
988 * All searching is done using a jQuery expression. The expression
989 * can be written using CSS 1-3 Selector syntax, or basic XPath.
991 * @example $("p").filter(".selected")
992 * @before <p class="selected">Hello</p><p>How are you?</p>
993 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
995 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
996 * @test $("input").filter(":checked",function(i){
997 * ok( this == q("radio2", "check1")[i], "Filter elements, context" );
999 * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){
1000 * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
1005 * @param String expr An expression to search with.
1006 * @cat DOM/Traversing
1010 * Removes all elements from the set of matched elements that do not
1011 * match at least one of the expressions passed to the function. This
1012 * method is used when you want to filter the set of matched elements
1013 * through more than one expression.
1015 * Elements will be retained in the jQuery object if they match at
1016 * least one of the expressions passed.
1018 * @example $("p").filter([".selected", ":first"])
1019 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
1020 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
1024 * @param Array<String> exprs A set of expressions to evaluate against
1025 * @cat DOM/Traversing
1027 filter: function(t) {
1028 return this.pushStack(
1029 t.constructor == Array &&
1030 jQuery.map(this,function(a){
1031 for ( var i = 0; i < t.length; i++ )
1032 if ( jQuery.filter(t[i],[a]).r.length )
1036 t.constructor == Boolean &&
1037 ( t ? this.get() : [] ) ||
1039 typeof t == "function" &&
1040 jQuery.grep( this, t ) ||
1042 jQuery.filter(t,this).r, arguments );
1046 * Removes the specified Element from the set of matched elements. This
1047 * method is used to remove a single Element from a jQuery object.
1049 * @example $("p").not( document.getElementById("selected") )
1050 * @before <p>Hello</p><p id="selected">Hello Again</p>
1051 * @result [ <p>Hello</p> ]
1055 * @param Element el An element to remove from the set
1056 * @cat DOM/Traversing
1060 * Removes elements matching the specified expression from the set
1061 * of matched elements. This method is used to remove one or more
1062 * elements from a jQuery object.
1064 * @example $("p").not("#selected")
1065 * @before <p>Hello</p><p id="selected">Hello Again</p>
1066 * @result [ <p>Hello</p> ]
1068 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
1072 * @param String expr An expression with which to remove matching elements
1073 * @cat DOM/Traversing
1076 return this.pushStack( t.constructor == String ?
1077 jQuery.filter(t,this,false).r :
1078 jQuery.grep(this,function(a){ return a != t; }), arguments );
1082 * Adds the elements matched by the expression to the jQuery object. This
1083 * can be used to concatenate the result sets of two expressions.
1085 * @example $("p").add("span")
1086 * @before <p>Hello</p><p><span>Hello Again</span></p>
1087 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1091 * @param String expr An expression whose matched elements are added
1092 * @cat DOM/Traversing
1096 * Adds each of the Elements in the array to the set of matched elements.
1097 * This is used to add a set of Elements to a jQuery object.
1099 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1100 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1101 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1105 * @param Array<Element> els An array of Elements to add
1106 * @cat DOM/Traversing
1110 * Adds a single Element to the set of matched elements. This is used to
1111 * add a single Element to a jQuery object.
1113 * @example $("p").add( document.getElementById("a") )
1114 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1115 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1119 * @param Element el An Element to add
1120 * @cat DOM/Traversing
1123 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1124 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1128 * Checks the current selection against an expression and returns true,
1129 * if the selection fits the given expression. Does return false, if the
1130 * selection does not fit or the expression is not valid.
1132 * @example $("input[@type='checkbox']").parent().is("form")
1133 * @before <form><input type="checkbox" /></form>
1135 * @desc Returns true, because the parent of the input is a form element
1137 * @example $("input[@type='checkbox']").parent().is("form")
1138 * @before <form><p><input type="checkbox" /></p></form>
1140 * @desc Returns false, because the parent of the input is a p element
1142 * @example $("form").is(null)
1143 * @before <form></form>
1145 * @desc An invalid expression always returns false.
1147 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1148 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1149 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1150 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1151 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1152 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1153 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1154 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1155 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1156 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1157 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1158 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1159 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1160 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1161 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1162 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1163 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1164 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1165 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1166 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1167 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1168 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1172 * @param String expr The expression with which to filter
1173 * @cat DOM/Traversing
1175 is: function(expr) {
1176 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1185 * @param Boolean table
1187 * @param Function fn The function doing the DOM manipulation.
1191 domManip: function(args, table, dir, fn){
1192 var clone = this.size() > 1;
1193 var a = jQuery.clean(args);
1195 return this.each(function(){
1198 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
1199 var tbody = this.getElementsByTagName("tbody");
1201 if ( !tbody.length ) {
1202 obj = document.createElement("tbody");
1203 this.appendChild( obj );
1208 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1209 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1210 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1225 pushStack: function(a,args) {
1226 var fn = args && args[args.length-1];
1227 var fn2 = args && args[args.length-2];
1229 if ( fn && fn.constructor != Function ) fn = null;
1230 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1233 if ( !this.stack ) this.stack = [];
1234 this.stack.push( this.get() );
1237 var old = this.get();
1240 if ( fn2 && a.length || !fn2 )
1241 this.each( fn2 || fn ).get( old );
1243 this.get( old ).each( fn );
1251 * Extends the jQuery object itself. Can be used to add both static
1252 * functions and plugin methods.
1254 * @example $.fn.extend({
1255 * check: function() {
1256 * this.each(function() { this.checked = true; });
1258 * uncheck: function() {
1259 * this.each(function() { this.checked = false; });
1262 * $("input[@type=checkbox]").check();
1263 * $("input[@type=radio]").uncheck();
1264 * @desc Adds two plugin methods.
1274 * Extend one object with another, returning the original,
1275 * modified, object. This is a great utility for simple inheritance.
1277 * @example var settings = { validate: false, limit: 5, name: "foo" };
1278 * var options = { validate: true, name: "bar" };
1279 * jQuery.extend(settings, options);
1280 * @result settings == { validate: true, limit: 5, name: "bar" }
1282 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1283 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1284 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1285 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1286 * jQuery.extend(settings, options);
1287 * isSet( settings, merged, "Check if extended: settings must be extended" );
1288 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1291 * @param Object obj The object to extend
1292 * @param Object prop The object that will be merged into the first.
1296 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1297 if ( !prop ) { prop = obj; obj = this; }
1298 for ( var i in prop ) obj[i] = prop[i];
1310 jQuery.initDone = true;
1312 jQuery.each( jQuery.macros.axis, function(i,n){
1313 jQuery.fn[ i ] = function(a) {
1314 var ret = jQuery.map(this,n);
1315 if ( a && a.constructor == String )
1316 ret = jQuery.filter(a,ret).r;
1317 return this.pushStack( ret, arguments );
1321 jQuery.each( jQuery.macros.to, function(i,n){
1322 jQuery.fn[ i ] = function(){
1324 return this.each(function(){
1325 for ( var j = 0; j < a.length; j++ )
1326 jQuery(a[j])[n]( this );
1331 jQuery.each( jQuery.macros.each, function(i,n){
1332 jQuery.fn[ i ] = function() {
1333 return this.each( n, arguments );
1337 jQuery.each( jQuery.macros.filter, function(i,n){
1338 jQuery.fn[ n ] = function(num,fn) {
1339 return this.filter( ":" + n + "(" + num + ")", fn );
1343 jQuery.each( jQuery.macros.attr, function(i,n){
1345 jQuery.fn[ i ] = function(h) {
1346 return h == undefined ?
1347 this.length ? this[0][n] : null :
1352 jQuery.each( jQuery.macros.css, function(i,n){
1353 jQuery.fn[ n ] = function(h) {
1354 return h == undefined ?
1355 ( this.length ? jQuery.css( this[0], n ) : null ) :
1363 * A generic iterator function, which can be used to seemlessly
1364 * iterate over both objects and arrays. This function is not the same
1365 * as $().each() - which is used to iterate, exclusively, over a jQuery
1366 * object. This function can be used to iterate over anything.
1368 * @example $.each( [0,1,2], function(i){
1369 * alert( "Item #" + i + ": " + this );
1371 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1373 * @example $.each( { name: "John", lang: "JS" }, function(i){
1374 * alert( "Name: " + i + ", Value: " + this );
1376 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1379 * @param Object obj The object, or array, to iterate over.
1380 * @param Function fn The function that will be executed on every object.
1384 each: function( obj, fn, args ) {
1385 if ( obj.length == undefined )
1386 for ( var i in obj )
1387 fn.apply( obj[i], args || [i, obj[i]] );
1389 for ( var i = 0; i < obj.length; i++ )
1390 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1396 if (jQuery.className.has(o,c)) return;
1397 o.className += ( o.className ? " " : "" ) + c;
1399 remove: function(o,c){
1403 var classes = o.className.split(" ");
1404 for(var i=0; i<classes.length; i++) {
1405 if(classes[i] == c) {
1406 classes.splice(i, 1);
1410 o.className = classes.join(' ');
1413 has: function(e,a) {
1414 if ( e.className != undefined )
1416 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1421 * Swap in/out style options.
1424 swap: function(e,o,f) {
1425 for ( var i in o ) {
1426 e.style["old"+i] = e.style[i];
1431 e.style[i] = e.style["old"+i];
1434 css: function(e,p) {
1435 if ( p == "height" || p == "width" ) {
1436 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1438 for ( var i in d ) {
1439 old["padding" + d[i]] = 0;
1440 old["border" + d[i] + "Width"] = 0;
1443 jQuery.swap( e, old, function() {
1444 if (jQuery.css(e,"display") != "none") {
1445 oHeight = e.offsetHeight;
1446 oWidth = e.offsetWidth;
1448 e = jQuery(e.cloneNode(true)).css({
1449 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1450 }).appendTo(e.parentNode)[0];
1452 var parPos = jQuery.css(e.parentNode,"position");
1453 if ( parPos == "" || parPos == "static" )
1454 e.parentNode.style.position = "relative";
1456 oHeight = e.clientHeight;
1457 oWidth = e.clientWidth;
1459 if ( parPos == "" || parPos == "static" )
1460 e.parentNode.style.position = "static";
1462 e.parentNode.removeChild(e);
1466 return p == "height" ? oHeight : oWidth;
1469 return jQuery.curCSS( e, p );
1472 curCSS: function(elem, prop, force) {
1475 if (prop == 'opacity' && jQuery.browser.msie)
1476 return jQuery.attr(elem.style, 'opacity');
1478 if (prop == "float" || prop == "cssFloat")
1479 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1481 if (!force && elem.style[prop]) {
1483 ret = elem.style[prop];
1485 } else if (elem.currentStyle) {
1487 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1488 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1490 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1492 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1493 var cur = document.defaultView.getComputedStyle(elem, null);
1496 ret = cur.getPropertyValue(prop);
1497 else if ( prop == 'display' )
1500 jQuery.swap(elem, { display: 'block' }, function() {
1501 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1509 clean: function(a) {
1511 for ( var i = 0; i < a.length; i++ ) {
1512 if ( a[i].constructor == String ) {
1513 // trim whitespace, otherwise indexOf won't work as expected
1514 a[i] = jQuery.trim(a[i]);
1518 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1520 a[i] = "<table>" + a[i] + "</table>";
1521 } else if ( !a[i].indexOf("<tr") ) {
1523 a[i] = "<table>" + a[i] + "</table>";
1524 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1526 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1529 var div = document.createElement("div");
1530 div.innerHTML = a[i];
1533 div = div.firstChild;
1534 if ( table != "thead" ) div = div.firstChild;
1535 if ( table == "td" ) div = div.firstChild;
1538 for ( var j = 0; j < div.childNodes.length; j++ )
1539 r.push( div.childNodes[j] );
1540 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1541 for ( var k = 0; k < a[i].length; k++ )
1543 else if ( a[i] !== null )
1544 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1550 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1551 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1559 last: "i==r.length-1",
1564 "nth-child": "jQuery.sibling(a,m[3]).cur",
1565 "first-child": "jQuery.sibling(a,0).cur",
1566 "last-child": "jQuery.sibling(a,0).last",
1567 "only-child": "jQuery.sibling(a).length==1",
1570 parent: "a.childNodes.length",
1571 empty: "!a.childNodes.length",
1574 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
1577 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1578 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1581 enabled: "!a.disabled",
1582 disabled: "a.disabled",
1583 checked: "a.checked",
1584 selected: "a.selected || jQuery.attr(a, 'selected')",
1587 text: "a.type=='text'",
1588 radio: "a.type=='radio'",
1589 checkbox: "a.type=='checkbox'",
1590 file: "a.type=='file'",
1591 password: "a.type=='password'",
1592 submit: "a.type=='submit'",
1593 image: "a.type=='image'",
1594 reset: "a.type=='reset'",
1595 button: "a.type=='button'",
1596 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
1598 ".": "jQuery.className.has(a,m[2])",
1602 "^=": "z && !z.indexOf(m[4])",
1603 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1604 "*=": "z && z.indexOf(m[4])>=0",
1607 "[": "jQuery.find(m[2],a).length"
1611 "\\.\\.|/\\.\\.", "a.parentNode",
1612 ">|/", "jQuery.sibling(a.firstChild)",
1613 "\\+", "jQuery.sibling(a).next",
1616 var s = jQuery.sibling(a);
1618 for ( var i = s.n; i < s.length; i++ )
1626 * @test t( "Element Selector", "div", ["main","foo"] );
1627 * t( "Element Selector", "body", ["body"] );
1628 * t( "Element Selector", "html", ["html"] );
1629 * ok( $("*").size() >= 30, "Element Selector" );
1630 * t( "Parent Element", "div div", ["foo"] );
1632 * t( "ID Selector", "#body", ["body"] );
1633 * t( "ID Selector w/ Element", "body#body", ["body"] );
1634 * t( "ID Selector w/ Element", "ul#first", [] );
1636 * t( "Class Selector", ".blog", ["mark","simon"] );
1637 * t( "Class Selector", ".blog.link", ["simon"] );
1638 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1639 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1641 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1642 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1643 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1644 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1646 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1647 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1648 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1649 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1650 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1651 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1652 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1653 * t( "Adjacent", "a + a", ["groups"] );
1654 * t( "Adjacent", "a +a", ["groups"] );
1655 * t( "Adjacent", "a+ a", ["groups"] );
1656 * t( "Adjacent", "a+a", ["groups"] );
1657 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1658 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1659 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1660 * t( "Attribute Exists", "a[@title]", ["google"] );
1661 * t( "Attribute Exists", "*[@title]", ["google"] );
1662 * t( "Attribute Exists", "[@title]", ["google"] );
1664 * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] );
1665 * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
1666 * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] );
1668 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1669 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1670 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1671 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1672 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1673 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1675 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1676 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1677 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1678 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1679 * t( "Last Child", "p:last-child", ["sap"] );
1680 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1681 * t( "Empty", "ul:empty", ["firstUL"] );
1682 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1683 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1684 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1685 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1686 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1687 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1688 * t( "Element Preceded By", "p ~ div", ["foo"] );
1689 * t( "Not", "a.blog:not(.link)", ["mark"] );
1691 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1692 * t( "All Div Elements", "//div", ["main","foo"] );
1693 * t( "Absolute Path", "/html/body", ["body"] );
1694 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1695 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1696 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1697 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1698 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1699 * t( "Attribute Exists", "//a[@title]", ["google"] );
1700 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1701 * t( "Parent Axis", "//p/..", ["main","foo"] );
1702 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1703 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1704 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1706 * t( "nth Element", "p:nth(1)", ["ap"] );
1707 * t( "First Element", "p:first", ["firstp"] );
1708 * t( "Last Element", "p:last", ["first"] );
1709 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1710 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1711 * t( "Position Equals", "p:eq(1)", ["ap"] );
1712 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1713 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1714 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1715 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1716 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1718 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1720 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1721 * t( "All Children of ID with no children", "#firstUL/*", [] );
1723 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1724 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1725 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1726 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1727 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1728 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1729 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1731 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1732 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1733 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1736 * @type Array<Element>
1740 find: function( t, context ) {
1741 // Make sure that the context is a DOM Element
1742 if ( context && context.nodeType == undefined )
1745 // Set the correct context (if none is provided)
1746 context = context || jQuery.context || document;
1748 if ( t.constructor != String ) return [t];
1750 if ( !t.indexOf("//") ) {
1751 context = context.documentElement;
1752 t = t.substr(2,t.length);
1753 } else if ( !t.indexOf("/") ) {
1754 context = context.documentElement;
1755 t = t.substr(1,t.length);
1756 // FIX Assume the root element is right :(
1757 if ( t.indexOf("/") >= 1 )
1758 t = t.substr(t.indexOf("/"),t.length);
1761 var ret = [context];
1765 while ( t.length > 0 && last != t ) {
1769 t = jQuery.trim(t).replace( /^\/\//i, "" );
1771 var foundToken = false;
1773 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1774 if ( foundToken ) continue;
1776 var re = new RegExp("^(" + jQuery.token[i] + ")");
1780 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1781 t = jQuery.trim( t.replace( re, "" ) );
1786 if ( !foundToken ) {
1787 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1788 if ( ret[0] == context ) ret.shift();
1789 done = jQuery.merge( done, ret );
1790 r = ret = [context];
1791 t = " " + t.substr(1,t.length);
1793 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1794 var m = re2.exec(t);
1796 if ( m[1] == "#" ) {
1797 // Ummm, should make this work in all XML docs
1798 var oid = document.getElementById(m[2]);
1799 r = ret = oid ? [oid] : [];
1800 t = t.replace( re2, "" );
1802 if ( !m[2] || m[1] == "." ) m[2] = "*";
1804 for ( var i = 0; i < ret.length; i++ )
1805 r = jQuery.merge( r,
1807 jQuery.getAll(ret[i]) :
1808 ret[i].getElementsByTagName(m[2])
1816 var val = jQuery.filter(t,r);
1818 t = jQuery.trim(val.t);
1822 if ( ret && ret[0] == context ) ret.shift();
1823 done = jQuery.merge( done, ret );
1828 getAll: function(o,r) {
1830 var s = o.childNodes;
1831 for ( var i = 0; i < s.length; i++ )
1832 if ( s[i].nodeType == 1 ) {
1834 jQuery.getAll( s[i], r );
1839 attr: function(elem, name, value){
1842 "class": "className",
1843 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1844 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1845 innerHTML: "innerHTML",
1846 className: "className",
1848 disabled: "disabled",
1852 // IE actually uses filters for opacity ... elem is actually elem.style
1853 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
1854 // IE has trouble with opacity if it does not have layout
1855 // Would prefer to check element.hasLayout first but don't have access to the element here
1857 if (value == 1) // Remove filter to avoid more IE weirdness
1858 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
1860 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
1861 } else if (name == "opacity" && jQuery.browser.msie) {
1862 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
1865 // Mozilla doesn't play well with opacity 1
1866 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
1869 if ( value != undefined ) elem[fix[name]] = value;
1870 return elem[fix[name]];
1871 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1872 return elem.getAttributeNode(name).nodeValue;
1873 } else if ( elem.getAttribute != undefined && elem.tagName ) { // IE elem.getAttribute passes even for style
1874 if ( value != undefined ) elem.setAttribute( name, value );
1875 return elem.getAttribute( name );
1877 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1878 if ( value != undefined ) elem[name] = value;
1883 // The regular expressions that power the parsing engine
1885 // Match: [@value='test'], [@foo]
1886 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1888 // Match: [div], [div p]
1889 "(\\[)\s*(.*?)\s*\\]",
1891 // Match: :contains('foo')
1892 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1894 // Match: :even, :last-chlid
1898 filter: function(t,r,not) {
1899 // Figure out if we're doing regular, or inverse, filtering
1900 var g = not !== false ? jQuery.grep :
1901 function(a,f) {return jQuery.grep(a,f,true);};
1903 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1905 var p = jQuery.parse;
1907 for ( var i = 0; i < p.length; i++ ) {
1909 // Look for, and replace, string-like sequences
1910 // and finally build a regexp out of it
1911 var re = new RegExp(
1912 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1914 var m = re.exec( t );
1917 // Re-organize the first match
1919 m = ["",m[1], m[3], m[2], m[5]];
1921 // Remove what we just matched
1922 t = t.replace( re, "" );
1928 // :not() is a special case that can be optimized by
1929 // keeping it out of the expression list
1930 if ( m[1] == ":" && m[2] == "not" )
1931 r = jQuery.filter(m[3],r,false).r;
1933 // Otherwise, find the expression to execute
1935 var f = jQuery.expr[m[1]];
1936 if ( f.constructor != String )
1937 f = jQuery.expr[m[1]][m[2]];
1939 // Build a custom macro to enclose it
1940 eval("f = function(a,i){" +
1941 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1942 "return " + f + "}");
1944 // Execute it against the current filter
1949 // Return an array of filtered elements (r)
1950 // and the modified expression string (t)
1951 return { r: r, t: t };
1955 * Remove the whitespace from the beginning and end of a string.
1957 * @example $.trim(" hello, how are you? ");
1958 * @result "hello, how are you?"
1962 * @param String str The string to trim.
1966 return t.replace(/^\s+|\s+$/g, "");
1970 * All ancestors of a given element.
1974 * @type Array<Element>
1975 * @param Element elem The element to find the ancestors of.
1976 * @cat DOM/Traversing
1978 parents: function( elem ){
1980 var cur = elem.parentNode;
1981 while ( cur && cur != document ) {
1982 matched.push( cur );
1983 cur = cur.parentNode;
1989 * All elements on a specified axis.
1994 * @param Element elem The element to find all the siblings of (including itself).
1995 * @cat DOM/Traversing
1997 sibling: function(elem, pos, not) {
2001 var siblings = elem.parentNode.childNodes;
2002 for ( var i = 0; i < siblings.length; i++ ) {
2003 if ( not === true && siblings[i] == elem ) continue;
2005 if ( siblings[i].nodeType == 1 )
2006 elems.push( siblings[i] );
2007 if ( siblings[i] == elem )
2008 elems.n = elems.length - 1;
2012 return jQuery.extend( elems, {
2013 last: elems.n == elems.length - 1,
2014 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
2015 prev: elems[elems.n - 1],
2016 next: elems[elems.n + 1]
2021 * Merge two arrays together, removing all duplicates. The final order
2022 * or the new array is: All the results from the first array, followed
2023 * by the unique results from the second array.
2025 * @example $.merge( [0,1,2], [2,3,4] )
2026 * @result [0,1,2,3,4]
2028 * @example $.merge( [3,2,1], [4,3,2] )
2033 * @param Array first The first array to merge.
2034 * @param Array second The second array to merge.
2037 merge: function(first, second) {
2040 // Move b over to the new array (this helps to avoid
2041 // StaticNodeList instances)
2042 for ( var k = 0; k < first.length; k++ )
2043 result[k] = first[k];
2045 // Now check for duplicates between a and b and only
2046 // add the unique items
2047 for ( var i = 0; i < second.length; i++ ) {
2048 var noCollision = true;
2050 // The collision-checking process
2051 for ( var j = 0; j < first.length; j++ )
2052 if ( second[i] == first[j] )
2053 noCollision = false;
2055 // If the item is unique, add it
2057 result.push( second[i] );
2064 * Filter items out of an array, by using a filter function.
2065 * The specified function will be passed two arguments: The
2066 * current array item and the index of the item in the array. The
2067 * function should return 'true' if you wish to keep the item in
2068 * the array, false if it should be removed.
2070 * @example $.grep( [0,1,2], function(i){
2077 * @param Array array The Array to find items in.
2078 * @param Function fn The function to process each item against.
2079 * @param Boolean inv Invert the selection - select the opposite of the function.
2082 grep: function(elems, fn, inv) {
2083 // If a string is passed in for the function, make a function
2084 // for it (a handy shortcut)
2085 if ( fn.constructor == String )
2086 fn = new Function("a","i","return " + fn);
2090 // Go through the array, only saving the items
2091 // that pass the validator function
2092 for ( var i = 0; i < elems.length; i++ )
2093 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2094 result.push( elems[i] );
2100 * Translate all items in an array to another array of items.
2101 * The translation function that is provided to this method is
2102 * called for each item in the array and is passed one argument:
2103 * The item to be translated. The function can then return:
2104 * The translated value, 'null' (to remove the item), or
2105 * an array of values - which will be flattened into the full array.
2107 * @example $.map( [0,1,2], function(i){
2112 * @example $.map( [0,1,2], function(i){
2113 * return i > 0 ? i + 1 : null;
2117 * @example $.map( [0,1,2], function(i){
2118 * return [ i, i + 1 ];
2120 * @result [0, 1, 1, 2, 2, 3]
2124 * @param Array array The Array to translate.
2125 * @param Function fn The function to process each item against.
2128 map: function(elems, fn) {
2129 // If a string is passed in for the function, make a function
2130 // for it (a handy shortcut)
2131 if ( fn.constructor == String )
2132 fn = new Function("a","return " + fn);
2136 // Go through the array, translating each of the items to their
2137 // new value (or values).
2138 for ( var i = 0; i < elems.length; i++ ) {
2139 var val = fn(elems[i],i);
2141 if ( val !== null && val != undefined ) {
2142 if ( val.constructor != Array ) val = [val];
2143 result = jQuery.merge( result, val );
2151 * A number of helper functions used for managing events.
2152 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2156 // Bind an event to an element
2157 // Original by Dean Edwards
2158 add: function(element, type, handler) {
2159 // For whatever reason, IE has trouble passing the window object
2160 // around, causing it to be cloned in the process
2161 if ( jQuery.browser.msie && element.setInterval != undefined )
2164 // Make sure that the function being executed has a unique ID
2165 if ( !handler.guid )
2166 handler.guid = this.guid++;
2168 // Init the element's event structure
2169 if (!element.events)
2170 element.events = {};
2172 // Get the current list of functions bound to this event
2173 var handlers = element.events[type];
2175 // If it hasn't been initialized yet
2177 // Init the event handler queue
2178 handlers = element.events[type] = {};
2180 // Remember an existing handler, if it's already there
2181 if (element["on" + type])
2182 handlers[0] = element["on" + type];
2185 // Add the function to the element's handler list
2186 handlers[handler.guid] = handler;
2188 // And bind the global event handler to the element
2189 element["on" + type] = this.handle;
2191 // Remember the function in a global list (for triggering)
2192 if (!this.global[type])
2193 this.global[type] = [];
2194 this.global[type].push( element );
2200 // Detach an event or set of events from an element
2201 remove: function(element, type, handler) {
2203 if (type && element.events[type])
2205 delete element.events[type][handler.guid];
2207 for ( var i in element.events[type] )
2208 delete element.events[type][i];
2210 for ( var j in element.events )
2211 this.remove( element, j );
2214 trigger: function(type,data,element) {
2215 // Touch up the incoming data
2218 // Handle a global trigger
2220 var g = this.global[type];
2222 for ( var i = 0; i < g.length; i++ )
2223 this.trigger( type, data, g[i] );
2225 // Handle triggering a single element
2226 } else if ( element["on" + type] ) {
2227 // Pass along a fake event
2228 data.unshift( this.fix({ type: type, target: element }) );
2230 // Trigger the event
2231 element["on" + type].apply( element, data );
2235 handle: function(event) {
2236 if ( typeof jQuery == "undefined" ) return;
2238 event = event || jQuery.event.fix( window.event );
2240 // If no correct event was found, fail
2241 if ( !event ) return;
2243 var returnValue = true;
2245 var c = this.events[event.type];
2247 var args = [].slice.call( arguments, 1 );
2248 args.unshift( event );
2250 for ( var j in c ) {
2251 if ( c[j].apply( this, args ) === false ) {
2252 event.preventDefault();
2253 event.stopPropagation();
2254 returnValue = false;
2261 fix: function(event) {
2263 event.preventDefault = function() {
2264 this.returnValue = false;
2267 event.stopPropagation = function() {
2268 this.cancelBubble = true;
2279 * Contains flags for the useragent, read from navigator.userAgent.
2280 * Available flags are: safari, opera, msie, mozilla
2281 * This property is available before the DOM is ready, therefore you can
2282 * use it to add ready events only for certain browsers.
2284 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2285 * jQBrowser plugin</a> for advanced browser detection:
2287 * @example $.browser.msie
2288 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2290 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2291 * @desc Alerts "this is safari!" only for safari browsers
2298 var b = navigator.userAgent.toLowerCase();
2300 // Figure out what browser is being used
2302 safari: /webkit/.test(b),
2303 opera: /opera/.test(b),
2304 msie: /msie/.test(b) && !/opera/.test(b),
2305 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2308 // Check to see if the W3C box model is being used
2309 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2315 * Append all of the matched elements to another, specified, set of elements.
2316 * This operation is, essentially, the reverse of doing a regular
2317 * $(A).append(B), in that instead of appending B to A, you're appending
2320 * @example $("p").appendTo("#foo");
2321 * @before <p>I would like to say: </p><div id="foo"></div>
2322 * @result <div id="foo"><p>I would like to say: </p></div>
2326 * @param String expr A jQuery expression of elements to match.
2327 * @cat DOM/Manipulation
2332 * Prepend all of the matched elements to another, specified, set of elements.
2333 * This operation is, essentially, the reverse of doing a regular
2334 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2337 * @example $("p").prependTo("#foo");
2338 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2339 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2343 * @param String expr A jQuery expression of elements to match.
2344 * @cat DOM/Manipulation
2346 prependTo: "prepend",
2349 * Insert all of the matched elements before another, specified, set of elements.
2350 * This operation is, essentially, the reverse of doing a regular
2351 * $(A).before(B), in that instead of inserting B before A, you're inserting
2354 * @example $("p").insertBefore("#foo");
2355 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2356 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2358 * @name insertBefore
2360 * @param String expr A jQuery expression of elements to match.
2361 * @cat DOM/Manipulation
2363 insertBefore: "before",
2366 * Insert all of the matched elements after another, specified, set of elements.
2367 * This operation is, essentially, the reverse of doing a regular
2368 * $(A).after(B), in that instead of inserting B after A, you're inserting
2371 * @example $("p").insertAfter("#foo");
2372 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2373 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2377 * @param String expr A jQuery expression of elements to match.
2378 * @cat DOM/Manipulation
2380 insertAfter: "after"
2384 * Get the current CSS width of the first matched element.
2386 * @example $("p").width();
2387 * @before <p>This is just a test.</p>
2396 * Set the CSS width of every matched element. Be sure to include
2397 * the "px" (or other unit of measurement) after the number that you
2398 * specify, otherwise you might get strange results.
2400 * @example $("p").width("20px");
2401 * @before <p>This is just a test.</p>
2402 * @result <p style="width:20px;">This is just a test.</p>
2406 * @param String val Set the CSS property to the specified value.
2411 * Get the current CSS height of the first matched element.
2413 * @example $("p").height();
2414 * @before <p>This is just a test.</p>
2423 * Set the CSS height of every matched element. Be sure to include
2424 * the "px" (or other unit of measurement) after the number that you
2425 * specify, otherwise you might get strange results.
2427 * @example $("p").height("20px");
2428 * @before <p>This is just a test.</p>
2429 * @result <p style="height:20px;">This is just a test.</p>
2433 * @param String val Set the CSS property to the specified value.
2438 * Get the current CSS top of the first matched element.
2440 * @example $("p").top();
2441 * @before <p>This is just a test.</p>
2450 * Set the CSS top of every matched element. Be sure to include
2451 * the "px" (or other unit of measurement) after the number that you
2452 * specify, otherwise you might get strange results.
2454 * @example $("p").top("20px");
2455 * @before <p>This is just a test.</p>
2456 * @result <p style="top:20px;">This is just a test.</p>
2460 * @param String val Set the CSS property to the specified value.
2465 * Get the current CSS left of the first matched element.
2467 * @example $("p").left();
2468 * @before <p>This is just a test.</p>
2477 * Set the CSS left of every matched element. Be sure to include
2478 * the "px" (or other unit of measurement) after the number that you
2479 * specify, otherwise you might get strange results.
2481 * @example $("p").left("20px");
2482 * @before <p>This is just a test.</p>
2483 * @result <p style="left:20px;">This is just a test.</p>
2487 * @param String val Set the CSS property to the specified value.
2492 * Get the current CSS position of the first matched element.
2494 * @example $("p").position();
2495 * @before <p>This is just a test.</p>
2504 * Set the CSS position of every matched element.
2506 * @example $("p").position("relative");
2507 * @before <p>This is just a test.</p>
2508 * @result <p style="position:relative;">This is just a test.</p>
2512 * @param String val Set the CSS property to the specified value.
2517 * Get the current CSS float of the first matched element.
2519 * @example $("p").float();
2520 * @before <p>This is just a test.</p>
2529 * Set the CSS float of every matched element.
2531 * @example $("p").float("left");
2532 * @before <p>This is just a test.</p>
2533 * @result <p style="float:left;">This is just a test.</p>
2537 * @param String val Set the CSS property to the specified value.
2542 * Get the current CSS overflow of the first matched element.
2544 * @example $("p").overflow();
2545 * @before <p>This is just a test.</p>
2554 * Set the CSS overflow of every matched element.
2556 * @example $("p").overflow("auto");
2557 * @before <p>This is just a test.</p>
2558 * @result <p style="overflow:auto;">This is just a test.</p>
2562 * @param String val Set the CSS property to the specified value.
2567 * Get the current CSS color of the first matched element.
2569 * @example $("p").color();
2570 * @before <p>This is just a test.</p>
2579 * Set the CSS color of every matched element.
2581 * @example $("p").color("blue");
2582 * @before <p>This is just a test.</p>
2583 * @result <p style="color:blue;">This is just a test.</p>
2587 * @param String val Set the CSS property to the specified value.
2592 * Get the current CSS background of the first matched element.
2594 * @example $("p").background();
2595 * @before <p style="background:blue;">This is just a test.</p>
2604 * Set the CSS background of every matched element.
2606 * @example $("p").background("blue");
2607 * @before <p>This is just a test.</p>
2608 * @result <p style="background:blue;">This is just a test.</p>
2612 * @param String val Set the CSS property to the specified value.
2616 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2619 * Reduce the set of matched elements to a single element.
2620 * The position of the element in the set of matched elements
2621 * starts at 0 and goes to length - 1.
2623 * @example $("p").eq(1)
2624 * @before <p>This is just a test.</p><p>So is this</p>
2625 * @result [ <p>So is this</p> ]
2629 * @param Number pos The index of the element that you wish to limit to.
2634 * Reduce the set of matched elements to all elements before a given position.
2635 * The position of the element in the set of matched elements
2636 * starts at 0 and goes to length - 1.
2638 * @example $("p").lt(1)
2639 * @before <p>This is just a test.</p><p>So is this</p>
2640 * @result [ <p>This is just a test.</p> ]
2644 * @param Number pos Reduce the set to all elements below this position.
2649 * Reduce the set of matched elements to all elements after a given position.
2650 * The position of the element in the set of matched elements
2651 * starts at 0 and goes to length - 1.
2653 * @example $("p").gt(0)
2654 * @before <p>This is just a test.</p><p>So is this</p>
2655 * @result [ <p>So is this</p> ]
2659 * @param Number pos Reduce the set to all elements after this position.
2664 * Filter the set of elements to those that contain the specified text.
2666 * @example $("p").contains("test")
2667 * @before <p>This is just a test.</p><p>So is this</p>
2668 * @result [ <p>This is just a test.</p> ]
2672 * @param String str The string that will be contained within the text of an element.
2673 * @cat DOM/Traversing
2676 filter: [ "eq", "lt", "gt", "contains" ],
2680 * Get the current value of the first matched element.
2682 * @example $("input").val();
2683 * @before <input type="text" value="some text"/>
2684 * @result "some text"
2686 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2687 * ok( !$("#text1").val() == "", "Check for value of input element" );
2691 * @cat DOM/Attributes
2695 * Set the value of every matched element.
2697 * @example $("input").val("test");
2698 * @before <input type="text" value="some text"/>
2699 * @result <input type="text" value="test"/>
2701 * @test document.getElementById('text1').value = "bla";
2702 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2703 * $("#text1").val('test');
2704 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2708 * @param String val Set the property to the specified value.
2709 * @cat DOM/Attributes
2714 * Get the html contents of the first matched element.
2716 * @example $("div").html();
2717 * @before <div><input/></div>
2722 * @cat DOM/Attributes
2726 * Set the html contents of every matched element.
2728 * @example $("div").html("<b>new stuff</b>");
2729 * @before <div><input/></div>
2730 * @result <div><b>new stuff</b></div>
2732 * @test var div = $("div");
2733 * div.html("<b>test</b>");
2735 * for ( var i = 0; i < div.size(); i++ ) {
2736 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2738 * ok( pass, "Set HTML" );
2742 * @param String val Set the html contents to the specified value.
2743 * @cat DOM/Attributes
2748 * Get the current id of the first matched element.
2750 * @example $("input").id();
2751 * @before <input type="text" id="test" value="some text"/>
2754 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2755 * ok( $("#foo").id() == "foo", "Check for id" );
2756 * ok( !$("head").id(), "Check for id" );
2760 * @cat DOM/Attributes
2764 * Set the id of every matched element.
2766 * @example $("input").id("newid");
2767 * @before <input type="text" id="test" value="some text"/>
2768 * @result <input type="text" id="newid" value="some text"/>
2772 * @param String val Set the property to the specified value.
2773 * @cat DOM/Attributes
2778 * Get the current title of the first matched element.
2780 * @example $("img").title();
2781 * @before <img src="test.jpg" title="my image"/>
2782 * @result "my image"
2784 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2785 * ok( !$("#yahoo").title(), "Check for title" );
2789 * @cat DOM/Attributes
2793 * Set the title of every matched element.
2795 * @example $("img").title("new title");
2796 * @before <img src="test.jpg" title="my image"/>
2797 * @result <img src="test.jpg" title="new image"/>
2801 * @param String val Set the property to the specified value.
2802 * @cat DOM/Attributes
2807 * Get the current name of the first matched element.
2809 * @example $("input").name();
2810 * @before <input type="text" name="username"/>
2811 * @result "username"
2813 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2814 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2815 * ok( !$("#area1").name(), "Check for name" );
2819 * @cat DOM/Attributes
2823 * Set the name of every matched element.
2825 * @example $("input").name("user");
2826 * @before <input type="text" name="username"/>
2827 * @result <input type="text" name="user"/>
2831 * @param String val Set the property to the specified value.
2832 * @cat DOM/Attributes
2837 * Get the current href of the first matched element.
2839 * @example $("a").href();
2840 * @before <a href="test.html">my link</a>
2841 * @result "test.html"
2845 * @cat DOM/Attributes
2849 * Set the href of every matched element.
2851 * @example $("a").href("test2.html");
2852 * @before <a href="test.html">my link</a>
2853 * @result <a href="test2.html">my link</a>
2857 * @param String val Set the property to the specified value.
2858 * @cat DOM/Attributes
2863 * Get the current src of the first matched element.
2865 * @example $("img").src();
2866 * @before <img src="test.jpg" title="my image"/>
2867 * @result "test.jpg"
2871 * @cat DOM/Attributes
2875 * Set the src of every matched element.
2877 * @example $("img").src("test2.jpg");
2878 * @before <img src="test.jpg" title="my image"/>
2879 * @result <img src="test2.jpg" title="my image"/>
2883 * @param String val Set the property to the specified value.
2884 * @cat DOM/Attributes
2889 * Get the current rel of the first matched element.
2891 * @example $("a").rel();
2892 * @before <a href="test.html" rel="nofollow">my link</a>
2893 * @result "nofollow"
2897 * @cat DOM/Attributes
2901 * Set the rel of every matched element.
2903 * @example $("a").rel("nofollow");
2904 * @before <a href="test.html">my link</a>
2905 * @result <a href="test.html" rel="nofollow">my link</a>
2909 * @param String val Set the property to the specified value.
2910 * @cat DOM/Attributes
2917 * Get a set of elements containing the unique parents of the matched
2920 * @example $("p").parent()
2921 * @before <div><p>Hello</p><p>Hello</p></div>
2922 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2926 * @cat DOM/Traversing
2930 * Get a set of elements containing the unique parents of the matched
2931 * set of elements, and filtered by an expression.
2933 * @example $("p").parent(".selected")
2934 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2935 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2939 * @param String expr An expression to filter the parents with
2940 * @cat DOM/Traversing
2942 parent: "a.parentNode",
2945 * Get a set of elements containing the unique ancestors of the matched
2946 * set of elements (except for the root element).
2948 * @example $("span").ancestors()
2949 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2950 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2954 * @cat DOM/Traversing
2958 * Get a set of elements containing the unique ancestors of the matched
2959 * set of elements, and filtered by an expression.
2961 * @example $("span").ancestors("p")
2962 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2963 * @result [ <p><span>Hello</span></p> ]
2967 * @param String expr An expression to filter the ancestors with
2968 * @cat DOM/Traversing
2970 ancestors: jQuery.parents,
2973 * Get a set of elements containing the unique ancestors of the matched
2974 * set of elements (except for the root element).
2976 * @example $("span").ancestors()
2977 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2978 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2982 * @cat DOM/Traversing
2986 * Get a set of elements containing the unique ancestors of the matched
2987 * set of elements, and filtered by an expression.
2989 * @example $("span").ancestors("p")
2990 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2991 * @result [ <p><span>Hello</span></p> ]
2995 * @param String expr An expression to filter the ancestors with
2996 * @cat DOM/Traversing
2998 parents: jQuery.parents,
3001 * Get a set of elements containing the unique next siblings of each of the
3002 * matched set of elements.
3004 * It only returns the very next sibling, not all next siblings.
3006 * @example $("p").next()
3007 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
3008 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
3012 * @cat DOM/Traversing
3016 * Get a set of elements containing the unique next siblings of each of the
3017 * matched set of elements, and filtered by an expression.
3019 * It only returns the very next sibling, not all next siblings.
3021 * @example $("p").next(".selected")
3022 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
3023 * @result [ <p class="selected">Hello Again</p> ]
3027 * @param String expr An expression to filter the next Elements with
3028 * @cat DOM/Traversing
3030 next: "jQuery.sibling(a).next",
3033 * Get a set of elements containing the unique previous siblings of each of the
3034 * matched set of elements.
3036 * It only returns the immediately previous sibling, not all previous siblings.
3038 * @example $("p").prev()
3039 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3040 * @result [ <div><span>Hello Again</span></div> ]
3044 * @cat DOM/Traversing
3048 * Get a set of elements containing the unique previous siblings of each of the
3049 * matched set of elements, and filtered by an expression.
3051 * It only returns the immediately previous sibling, not all previous siblings.
3053 * @example $("p").previous(".selected")
3054 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3055 * @result [ <div><span>Hello</span></div> ]
3059 * @param String expr An expression to filter the previous Elements with
3060 * @cat DOM/Traversing
3062 prev: "jQuery.sibling(a).prev",
3065 * Get a set of elements containing all of the unique siblings of each of the
3066 * matched set of elements.
3068 * @example $("div").siblings()
3069 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3070 * @result [ <p>Hello</p>, <p>And Again</p> ]
3072 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3076 * @cat DOM/Traversing
3080 * Get a set of elements containing all of the unique siblings of each of the
3081 * matched set of elements, and filtered by an expression.
3083 * @example $("div").siblings(".selected")
3084 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3085 * @result [ <p class="selected">Hello Again</p> ]
3087 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3088 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3092 * @param String expr An expression to filter the sibling Elements with
3093 * @cat DOM/Traversing
3095 siblings: "jQuery.sibling(a, null, true)",
3099 * Get a set of elements containing all of the unique children of each of the
3100 * matched set of elements.
3102 * @example $("div").children()
3103 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3104 * @result [ <span>Hello Again</span> ]
3106 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3110 * @cat DOM/Traversing
3114 * Get a set of elements containing all of the unique children of each of the
3115 * matched set of elements, and filtered by an expression.
3117 * @example $("div").children(".selected")
3118 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3119 * @result [ <p class="selected">Hello Again</p> ]
3121 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3125 * @param String expr An expression to filter the child Elements with
3126 * @cat DOM/Traversing
3128 children: "jQuery.sibling(a.firstChild)"
3134 * Remove an attribute from each of the matched elements.
3136 * @example $("input").removeAttr("disabled")
3137 * @before <input disabled="disabled"/>
3142 * @param String name The name of the attribute to remove.
3145 removeAttr: function( key ) {
3146 this.removeAttribute( key );
3150 * Displays each of the set of matched elements if they are hidden.
3152 * @example $("p").show()
3153 * @before <p style="display: none">Hello</p>
3154 * @result [ <p style="display: block">Hello</p> ]
3156 * @test var pass = true, div = $("div");
3157 * div.show().each(function(){
3158 * if ( this.style.display == "none" ) pass = false;
3160 * ok( pass, "Show" );
3167 this.style.display = this.oldblock ? this.oldblock : "";
3168 if ( jQuery.css(this,"display") == "none" )
3169 this.style.display = "block";
3173 * Hides each of the set of matched elements if they are shown.
3175 * @example $("p").hide()
3176 * @before <p>Hello</p>
3177 * @result [ <p style="display: none">Hello</p> ]
3179 * var pass = true, div = $("div");
3180 * div.hide().each(function(){
3181 * if ( this.style.display != "none" ) pass = false;
3183 * ok( pass, "Hide" );
3190 this.oldblock = this.oldblock || jQuery.css(this,"display");
3191 if ( this.oldblock == "none" )
3192 this.oldblock = "block";
3193 this.style.display = "none";
3197 * Toggles each of the set of matched elements. If they are shown,
3198 * toggle makes them hidden. If they are hidden, toggle
3201 * @example $("p").toggle()
3202 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3203 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3210 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3214 * Adds the specified class to each of the set of matched elements.
3216 * @example $("p").addClass("selected")
3217 * @before <p>Hello</p>
3218 * @result [ <p class="selected">Hello</p> ]
3220 * @test var div = $("div");
3221 * div.addClass("test");
3223 * for ( var i = 0; i < div.size(); i++ ) {
3224 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3226 * ok( pass, "Add Class" );
3230 * @param String class A CSS class to add to the elements
3233 addClass: function(c){
3234 jQuery.className.add(this,c);
3238 * Removes the specified class from the set of matched elements.
3240 * @example $("p").removeClass("selected")
3241 * @before <p class="selected">Hello</p>
3242 * @result [ <p>Hello</p> ]
3244 * @test var div = $("div").addClass("test");
3245 * div.removeClass("test");
3247 * for ( var i = 0; i < div.size(); i++ ) {
3248 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3250 * ok( pass, "Remove Class" );
3254 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3255 * div.removeClass("test").removeClass("bar").removeClass("foo");
3257 * for ( var i = 0; i < div.size(); i++ ) {
3258 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3260 * ok( pass, "Remove multiple classes" );
3264 * @param String class A CSS class to remove from the elements
3267 removeClass: function(c){
3268 jQuery.className.remove(this,c);
3272 * Adds the specified class if it is present, removes it if it is
3275 * @example $("p").toggleClass("selected")
3276 * @before <p>Hello</p><p class="selected">Hello Again</p>
3277 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3281 * @param String class A CSS class with which to toggle the elements
3284 toggleClass: function( c ){
3285 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3289 * Removes all matched elements from the DOM. This does NOT remove them from the
3290 * jQuery object, allowing you to use the matched elements further.
3292 * @example $("p").remove();
3293 * @before <p>Hello</p> how are <p>you?</p>
3298 * @cat DOM/Manipulation
3302 * Removes only elements (out of the list of matched elements) that match
3303 * the specified jQuery expression. This does NOT remove them from the
3304 * jQuery object, allowing you to use the matched elements further.
3306 * @example $("p").remove(".hello");
3307 * @before <p class="hello">Hello</p> how are <p>you?</p>
3308 * @result how are <p>you?</p>
3312 * @param String expr A jQuery expression to filter elements by.
3313 * @cat DOM/Manipulation
3315 remove: function(a){
3316 if ( !a || jQuery.filter( a, [this] ).r )
3317 this.parentNode.removeChild( this );
3321 * Removes all child nodes from the set of matched elements.
3323 * @example $("p").empty()
3324 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3325 * @result [ <p></p> ]
3329 * @cat DOM/Manipulation
3332 while ( this.firstChild )
3333 this.removeChild( this.firstChild );
3337 * Binds a handler to a particular event (like click) for each matched element.
3338 * The event handler is passed an event object that you can use to prevent
3339 * default behaviour. To stop both default action and event bubbling, your handler
3340 * has to return false.
3342 * @example $("p").bind( "click", function() {
3343 * alert( $(this).text() );
3345 * @before <p>Hello</p>
3346 * @result alert("Hello")
3348 * @example $("form").bind( "submit", function() { return false; } )
3349 * @desc Cancel a default action and prevent it from bubbling by returning false
3350 * from your function.
3352 * @example $("form").bind( "submit", function(event) {
3353 * event.preventDefault();
3355 * @desc Cancel only the default action by using the preventDefault method.
3358 * @example $("form").bind( "submit", function(event) {
3359 * event.stopPropagation();
3361 * @desc Stop only an event from bubbling by using the stopPropagation method.
3365 * @param String type An event type
3366 * @param Function fn A function to bind to the event on each of the set of matched elements
3369 bind: function( type, fn ) {
3370 if ( fn.constructor == String )
3371 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3372 jQuery.event.add( this, type, fn );
3376 * The opposite of bind, removes a bound event from each of the matched
3377 * elements. You must pass the identical function that was used in the original
3380 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3381 * @before <p onclick="alert('Hello');">Hello</p>
3382 * @result [ <p>Hello</p> ]
3386 * @param String type An event type
3387 * @param Function fn A function to unbind from the event on each of the set of matched elements
3392 * Removes all bound events of a particular type from each of the matched
3395 * @example $("p").unbind( "click" )
3396 * @before <p onclick="alert('Hello');">Hello</p>
3397 * @result [ <p>Hello</p> ]
3401 * @param String type An event type
3406 * Removes all bound events from each of the matched elements.
3408 * @example $("p").unbind()
3409 * @before <p onclick="alert('Hello');">Hello</p>
3410 * @result [ <p>Hello</p> ]
3416 unbind: function( type, fn ) {
3417 jQuery.event.remove( this, type, fn );
3421 * Trigger a type of event on every matched element.
3423 * @example $("p").trigger("click")
3424 * @before <p click="alert('hello')">Hello</p>
3425 * @result alert('hello')
3429 * @param String type An event type to trigger.
3432 trigger: function( type, data ) {
3433 jQuery.event.trigger( type, data, this );