2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * ok( Function.prototype.apply, "Function.apply()" );
20 * ok( document.getElementById, "getElementById" );
21 * ok( document.getElementsByTagName, "getElementsByTagName" );
22 * ok( RegExp, "RegExp" );
23 * ok( jQuery, "jQuery" );
31 jQuery = function(a,c) {
33 // Shortcut for document ready (because $(document).each() is silly)
34 if ( a && typeof a == "function" && jQuery.fn.ready )
35 return jQuery(document).ready(a);
37 // Make sure that a selection was provided
38 a = a || jQuery.context || document;
40 // Watch for when a jQuery object is passed as the selector
42 return jQuery( jQuery.merge( a, [] ) );
44 // Watch for when a jQuery object is passed at the context
46 return jQuery( c ).find(a);
48 // If the context is global, return a new object
50 return new jQuery(a,c);
52 // Handle HTML strings
53 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
54 if ( m ) a = jQuery.clean( [ m[1] ] );
56 // Watch for when an array is passed in
57 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
58 // Assume that it is an array of DOM Elements
59 jQuery.merge( a, [] ) :
61 // Find the matching elements and save them for later
62 jQuery.find( a, c ) );
64 // See if an extra function was provided
65 var fn = arguments[ arguments.length - 1 ];
67 // If so, execute it in context
68 if ( fn && typeof fn == "function" )
72 // Map over the $ in case of overwrite
73 if ( typeof $ != "undefined" )
77 * This function accepts a string containing a CSS selector,
78 * basic XPath, or raw HTML, which is then used to match a set of elements.
79 * The HTML string is different from the traditional selectors in that
80 * it creates the DOM elements representing that HTML string, on the fly,
81 * to be (assumedly) inserted into the document later.
83 * The core functionality of jQuery centers around this function.
84 * Everything in jQuery is based upon this, or uses this in some way.
85 * The most basic use of this function is to pass in an expression
86 * (usually consisting of CSS or XPath), which then finds all matching
87 * elements and remembers them for later use.
89 * By default, $() looks for DOM elements within the context of the
90 * current HTML document.
92 * @example $("div > p")
93 * @desc This finds all p elements that are children of a div element.
94 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
95 * @result [ <p>two</p> ]
97 * @example $("<div><p>Hello</p></div>").appendTo("#body")
98 * @desc Creates a div element (and all of its contents) dynamically, and appends it to the element with the ID of body.
101 * @param String expr An expression to search with, or a string of HTML to create on the fly.
107 * This function accepts a string containing a CSS selector, or
108 * basic XPath, which is then used to match a set of elements with the
109 * context of the specified DOM element, or document
111 * @example $("div", xml.responseXML)
112 * @desc This finds all div elements within the specified XML document.
115 * @param String expr An expression to search with.
116 * @param Element context A DOM Element, or Document, representing the base context.
122 * Wrap jQuery functionality around a specific DOM Element.
123 * This function also accepts XML Documents and Window objects
124 * as valid arguments (even though they are not DOM Elements).
126 * @example $(document).find("div > p")
127 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
128 * @result [ <p>two</p> ]
130 * @example $(document.body).background( "black" );
131 * @desc Sets the background color of the page to black.
134 * @param Element elem A DOM element to be encapsulated by a jQuery object.
140 * Wrap jQuery functionality around a set of DOM Elements.
142 * @example $( myForm.elements ).hide()
143 * @desc Hides all the input elements within a form
146 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
152 * A shorthand for $(document).ready(), allowing you to bind a function
153 * to be executed when the DOM document has finished loading. This function
154 * behaves just like $(document).ready(), in that it should be used to wrap
155 * all of the other $() operations on your page. While this function is,
156 * technically, chainable - there really isn't much use for chaining against it.
158 * @example $(function(){
159 * // Document is ready
161 * @desc Executes the function when the DOM is ready to be used.
164 * @param Function fn The function to execute when the DOM is ready.
170 * A means of creating a cloned copy of a jQuery object. This function
171 * copies the set of matched elements from one jQuery object and creates
172 * another, new, jQuery object containing the same elements.
174 * @example var div = $("div");
175 * $( div ).find("p");
176 * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div' (as would normally be the case if a simple div.find("p") was done).
179 * @param jQuery obj The jQuery object to be cloned.
184 // Map the jQuery namespace to the '$' one
187 jQuery.fn = jQuery.prototype = {
189 * The current SVN version of jQuery.
200 * The number of elements currently matched.
202 * @example $("img").length;
203 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
206 * @test ok( $("div").length == 2, "Get Number of Elements Found" );
215 * The number of elements currently matched.
217 * @example $("img").size();
218 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
221 * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
232 * Access all matched elements. This serves as a backwards-compatible
233 * way of accessing all matched elements (other than the jQuery object
234 * itself, which is, in fact, an array of elements).
236 * @example $("img").get();
237 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
238 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
240 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
243 * @type Array<Element>
248 * Access a single matched element. num is used to access the
249 * Nth element matched.
251 * @example $("img").get(1);
252 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
253 * @result [ <img src="test1.jpg"/> ]
255 * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
259 * @param Number num Access the element in the Nth position.
264 * Set the jQuery object to an array of elements.
266 * @example $("img").get([ document.body ]);
267 * @result $("img").get() == [ document.body ]
272 * @param Elements elems An array of elements
275 get: function( num ) {
276 // Watch for when an array (of elements) is passed in
277 if ( num && num.constructor == Array ) {
279 // Use a tricky hack to make the jQuery object
280 // look and feel like an array
282 [].push.apply( this, num );
286 return num == undefined ?
288 // Return a 'clean' array
289 jQuery.merge( this, [] ) :
291 // Return just the object
296 * Execute a function within the context of every matched element.
297 * This means that every time the passed-in function is executed
298 * (which is once for every element matched) the 'this' keyword
299 * points to the specific element.
301 * Additionally, the function, when executed, is passed a single
302 * argument representing the position of the element in the matched
305 * @example $("img").each(function(){
306 * this.src = "test.jpg";
308 * @before <img/> <img/>
309 * @result <img src="test.jpg"/> <img src="test.jpg"/>
311 * @example $("img").each(function(i){
312 * alert( "Image #" + i + " is " + this );
314 * @before <img/> <img/>
315 * @result <img src="test.jpg"/> <img src="test.jpg"/>
317 * @test var div = $("div");
318 * div.each(function(){this.foo = 'zoo';});
320 * for ( var i = 0; i < div.size(); i++ ) {
321 * if ( div.get(i).foo != "zoo" ) pass = false;
323 * ok( pass, "Execute a function, Relative" );
327 * @param Function fn A function to execute
330 each: function( fn, args ) {
331 return jQuery.each( this, fn, args );
335 * Searches every matched element for the object and returns
336 * the index of the element, if found, starting with zero.
337 * Returns -1 if the object wasn't found.
339 * @example $("*").index(document.getElementById('foobar'))
340 * @before <div id="foobar"></div><b></b><span id="foo"></span>
343 * @example $("*").index(document.getElementById('foo'))
344 * @before <div id="foobar"></div><b></b><span id="foo"></span>
347 * @example $("*").index(document.getElementById('bar'))
348 * @before <div id="foobar"></div><b></b><span id="foo"></span>
351 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
352 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
353 * var inputElements = $('#radio1,#radio2,#check1,#check2');
354 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
355 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
356 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
357 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
358 * ok( inputElements.index(window) == -1, "Check for not found index" );
359 * ok( inputElements.index(document) == -1, "Check for not found index" );
363 * @param Object obj Object to search for
366 index: function( obj ) {
368 this.each(function(i){
369 if ( this == obj ) pos = i;
375 * Access a property on the first matched element.
376 * This method makes it easy to retrieve a property value
377 * from the first matched element.
379 * @example $("img").attr("src");
380 * @before <img src="test.jpg"/>
383 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
384 * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
385 * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
386 * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
387 * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
388 * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
389 * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
390 * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
391 * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
392 * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
393 * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
394 * ok( $('#form').attr('action') == "formaction", 'Check for action attribute' );
398 * @param String name The name of the property to access.
403 * Set a hash of key/value object properties to all matched elements.
404 * This serves as the best way to set a large number of properties
405 * on all matched elements.
407 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
409 * @result <img src="test.jpg" alt="Test Image"/>
411 * @test var pass = true;
412 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
413 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
415 * ok( pass, "Set Multiple Attributes" );
419 * @param Hash prop A set of key/value pairs to set as object properties.
424 * Set a single property to a value, on all matched elements.
426 * @example $("img").attr("src","test.jpg");
428 * @result <img src="test.jpg"/>
430 * @test var div = $("div");
431 * div.attr("foo", "bar");
433 * for ( var i = 0; i < div.size(); i++ ) {
434 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
436 * ok( pass, "Set Attribute" );
438 * $("#name").attr('name', 'something');
439 * ok( $("#name").name() == 'something', 'Set name attribute' );
440 * $("#check2").attr('checked', true);
441 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
442 * $("#check2").attr('checked', false);
443 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
447 * @param String key The name of the property to set.
448 * @param Object value The value to set the property to.
451 attr: function( key, value, type ) {
452 // Check to see if we're setting style values
453 return key.constructor != String || value != undefined ?
454 this.each(function(){
455 // See if we're setting a hash of styles
456 if ( value == undefined )
457 // Set all the styles
458 for ( var prop in key )
460 type ? this.style : this,
464 // See if we're setting a single key/value style
467 type ? this.style : this,
472 // Look for the case where we're accessing a style value
473 jQuery[ type || "attr" ]( this[0], key );
477 * Access a style property on the first matched element.
478 * This method makes it easy to retrieve a style property value
479 * from the first matched element.
481 * @example $("p").css("color");
482 * @before <p style="color:red;">Test Paragraph.</p>
484 * @desc Retrieves the color style of the first paragraph
486 * @example $("p").css("fontWeight");
487 * @before <p style="font-weight: bold;">Test Paragraph.</p>
489 * @desc Retrieves the font-weight style of the first paragraph.
490 * Note that for all style properties with a dash (like 'font-weight'), you have to
491 * write it in camelCase. In other words: Every time you have a '-' in a
492 * property, remove it and replace the next character with an uppercase
493 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
494 * borderStyle, borderBottomWidth etc.
496 * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
500 * @param String name The name of the property to access.
505 * Set a hash of key/value style properties to all matched elements.
506 * This serves as the best way to set a large number of style properties
507 * on all matched elements.
509 * @example $("p").css({ color: "red", background: "blue" });
510 * @before <p>Test Paragraph.</p>
511 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
513 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
514 * $('#foo').css({display: 'none'});
515 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
516 * $('#foo').css({display: 'block'});
517 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
521 * @param Hash prop A set of key/value pairs to set as style properties.
526 * Set a single style property to a value, on all matched elements.
528 * @example $("p").css("color","red");
529 * @before <p>Test Paragraph.</p>
530 * @result <p style="color:red;">Test Paragraph.</p>
531 * @desc Changes the color of all paragraphs to red
534 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
535 * $('#foo').css('display', 'none');
536 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
537 * $('#foo').css('display', 'block');
538 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
542 * @param String key The name of the property to set.
543 * @param Object value The value to set the property to.
546 css: function( key, value ) {
547 return this.attr( key, value, "curCSS" );
551 * Retrieve the text contents of all matched elements. The result is
552 * a string that contains the combined text contents of all matched
553 * elements. This method works on both HTML and XML documents.
555 * @example $("p").text();
556 * @before <p>Test Paragraph.</p>
557 * @result Test Paragraph.
559 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
560 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
569 for ( var j = 0; j < e.length; j++ ) {
570 var r = e[j].childNodes;
571 for ( var i = 0; i < r.length; i++ )
572 if ( r[i].nodeType != 8 )
573 t += r[i].nodeType != 1 ?
574 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
580 * Wrap all matched elements with a structure of other elements.
581 * This wrapping process is most useful for injecting additional
582 * stucture into a document, without ruining the original semantic
583 * qualities of a document.
585 * This works by going through the first element
586 * provided (which is generated, on the fly, from the provided HTML)
587 * and finds the deepest ancestor element within its
588 * structure - it is that element that will en-wrap everything else.
590 * This does not work with elements that contain text. Any necessary text
591 * must be added after the wrapping is done.
593 * @example $("p").wrap("<div class='wrap'></div>");
594 * @before <p>Test Paragraph.</p>
595 * @result <div class='wrap'><p>Test Paragraph.</p></div>
597 * @test var defaultText = 'Try them out:'
598 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
599 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
600 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
604 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
605 * @cat DOM/Manipulation
609 * Wrap all matched elements with a structure of other elements.
610 * This wrapping process is most useful for injecting additional
611 * stucture into a document, without ruining the original semantic
612 * qualities of a document.
614 * This works by going through the first element
615 * provided and finding the deepest ancestor element within its
616 * structure - it is that element that will en-wrap everything else.
618 * This does not work with elements that contain text. Any necessary text
619 * must be added after the wrapping is done.
621 * @example $("p").wrap( document.getElementById('content') );
622 * @before <p>Test Paragraph.</p><div id="content"></div>
623 * @result <div id="content"><p>Test Paragraph.</p></div>
625 * @test var defaultText = 'Try them out:'
626 * var result = $('#first').wrap(document.getElementById('empty')).parent();
627 * ok( result.is('ol'), 'Check for element wrapping' );
628 * ok( result.text() == defaultText, 'Check for element wrapping' );
632 * @param Element elem A DOM element that will be wrapped.
633 * @cat DOM/Manipulation
636 // The elements to wrap the target around
637 var a = jQuery.clean(arguments);
639 // Wrap each of the matched elements individually
640 return this.each(function(){
641 // Clone the structure that we're using to wrap
642 var b = a[0].cloneNode(true);
644 // Insert it before the element to be wrapped
645 this.parentNode.insertBefore( b, this );
647 // Find he deepest point in the wrap structure
648 while ( b.firstChild )
651 // Move the matched element to within the wrap structure
652 b.appendChild( this );
657 * Append any number of elements to the inside of every matched elements,
658 * generated from the provided HTML.
659 * This operation is similar to doing an appendChild to all the
660 * specified elements, adding them into the document.
662 * @example $("p").append("<b>Hello</b>");
663 * @before <p>I would like to say: </p>
664 * @result <p>I would like to say: <b>Hello</b></p>
666 * @test var defaultText = 'Try them out:'
667 * var result = $('#first').append('<b>buga</b>');
668 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
671 * var expected = "Try them out: bla ";
672 * $('#first').append(" ");
673 * $('#first').append("bla ");
674 * ok( expected == $('#first').text(), "Check for appending of spaces" );
678 * @param String html A string of HTML, that will be created on the fly and appended to the target.
679 * @cat DOM/Manipulation
683 * Append an element to the inside of all matched elements.
684 * This operation is similar to doing an appendChild to all the
685 * specified elements, adding them into the document.
687 * @example $("p").append( $("#foo")[0] );
688 * @before <p>I would like to say: </p><b id="foo">Hello</b>
689 * @result <p>I would like to say: <b id="foo">Hello</b></p>
691 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
692 * $('#sap').append(document.getElementById('first'));
693 * ok( expected == $('#sap').text(), "Check for appending of element" );
697 * @param Element elem A DOM element that will be appended.
698 * @cat DOM/Manipulation
702 * Append any number of elements to the inside of all matched elements.
703 * This operation is similar to doing an appendChild to all the
704 * specified elements, adding them into the document.
706 * @example $("p").append( $("b") );
707 * @before <p>I would like to say: </p><b>Hello</b>
708 * @result <p>I would like to say: <b>Hello</b></p>
710 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
711 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
712 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
716 * @param Array<Element> elems An array of elements, all of which will be appended.
717 * @cat DOM/Manipulation
720 return this.domManip(arguments, true, 1, function(a){
721 this.appendChild( a );
726 * Prepend any number of elements to the inside of every matched elements,
727 * generated from the provided HTML.
728 * This operation is the best way to insert dynamically created elements
729 * inside, at the beginning, of all the matched element.
731 * @example $("p").prepend("<b>Hello</b>");
732 * @before <p>I would like to say: </p>
733 * @result <p><b>Hello</b>I would like to say: </p>
735 * @test var defaultText = 'Try them out:'
736 * var result = $('#first').prepend('<b>buga</b>');
737 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
741 * @param String html A string of HTML, that will be created on the fly and appended to the target.
742 * @cat DOM/Manipulation
746 * Prepend an element to the inside of all matched elements.
747 * This operation is the best way to insert an element inside, at the
748 * beginning, of all the matched element.
750 * @example $("p").prepend( $("#foo")[0] );
751 * @before <p>I would like to say: </p><b id="foo">Hello</b>
752 * @result <p><b id="foo">Hello</b>I would like to say: </p>
754 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
755 * $('#sap').prepend(document.getElementById('first'));
756 * ok( expected == $('#sap').text(), "Check for prepending of element" );
760 * @param Element elem A DOM element that will be appended.
761 * @cat DOM/Manipulation
765 * Prepend any number of elements to the inside of all matched elements.
766 * This operation is the best way to insert a set of elements inside, at the
767 * beginning, of all the matched element.
769 * @example $("p").prepend( $("b") );
770 * @before <p>I would like to say: </p><b>Hello</b>
771 * @result <p><b>Hello</b>I would like to say: </p>
773 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
774 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
775 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
779 * @param Array<Element> elems An array of elements, all of which will be appended.
780 * @cat DOM/Manipulation
782 prepend: function() {
783 return this.domManip(arguments, true, -1, function(a){
784 this.insertBefore( a, this.firstChild );
789 * Insert any number of dynamically generated elements before each of the
792 * @example $("p").before("<b>Hello</b>");
793 * @before <p>I would like to say: </p>
794 * @result <b>Hello</b><p>I would like to say: </p>
796 * @test var expected = 'This is a normal link: bugaYahoo';
797 * $('#yahoo').before('<b>buga</b>');
798 * ok( expected == $('#en').text(), 'Insert String before' );
802 * @param String html A string of HTML, that will be created on the fly and appended to the target.
803 * @cat DOM/Manipulation
807 * Insert an element before each of the matched elements.
809 * @example $("p").before( $("#foo")[0] );
810 * @before <p>I would like to say: </p><b id="foo">Hello</b>
811 * @result <b id="foo">Hello</b><p>I would like to say: </p>
813 * @test var expected = "This is a normal link: Try them out:Yahoo";
814 * $('#yahoo').before(document.getElementById('first'));
815 * ok( expected == $('#en').text(), "Insert element before" );
819 * @param Element elem A DOM element that will be appended.
820 * @cat DOM/Manipulation
824 * Insert any number of elements before each of the matched elements.
826 * @example $("p").before( $("b") );
827 * @before <p>I would like to say: </p><b>Hello</b>
828 * @result <b>Hello</b><p>I would like to say: </p>
830 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
831 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
832 * ok( expected == $('#en').text(), "Insert array of elements before" );
836 * @param Array<Element> elems An array of elements, all of which will be appended.
837 * @cat DOM/Manipulation
840 return this.domManip(arguments, false, 1, function(a){
841 this.parentNode.insertBefore( a, this );
846 * Insert any number of dynamically generated elements after each of the
849 * @example $("p").after("<b>Hello</b>");
850 * @before <p>I would like to say: </p>
851 * @result <p>I would like to say: </p><b>Hello</b>
853 * @test var expected = 'This is a normal link: Yahoobuga';
854 * $('#yahoo').after('<b>buga</b>');
855 * ok( expected == $('#en').text(), 'Insert String after' );
859 * @param String html A string of HTML, that will be created on the fly and appended to the target.
860 * @cat DOM/Manipulation
864 * Insert an element after each of the matched elements.
866 * @example $("p").after( $("#foo")[0] );
867 * @before <b id="foo">Hello</b><p>I would like to say: </p>
868 * @result <p>I would like to say: </p><b id="foo">Hello</b>
870 * @test var expected = "This is a normal link: YahooTry them out:";
871 * $('#yahoo').after(document.getElementById('first'));
872 * ok( expected == $('#en').text(), "Insert element after" );
876 * @param Element elem A DOM element that will be appended.
877 * @cat DOM/Manipulation
881 * Insert any number of elements after each of the matched elements.
883 * @example $("p").after( $("b") );
884 * @before <b>Hello</b><p>I would like to say: </p>
885 * @result <p>I would like to say: </p><b>Hello</b>
887 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
888 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
889 * ok( expected == $('#en').text(), "Insert array of elements after" );
893 * @param Array<Element> elems An array of elements, all of which will be appended.
894 * @cat DOM/Manipulation
897 return this.domManip(arguments, false, -1, function(a){
898 this.parentNode.insertBefore( a, this.nextSibling );
903 * End the most recent 'destructive' operation, reverting the list of matched elements
904 * back to its previous state. After an end operation, the list of matched elements will
905 * revert to the last state of matched elements.
907 * @example $("p").find("span").end();
908 * @before <p><span>Hello</span>, how are you?</p>
909 * @result $("p").find("span").end() == [ <p>...</p> ]
911 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
915 * @cat DOM/Traversing
918 return this.get( this.stack.pop() );
922 * Searches for all elements that match the specified expression.
923 * This method is the optimal way of finding additional descendant
924 * elements with which to process.
926 * All searching is done using a jQuery expression. The expression can be
927 * written using CSS 1-3 Selector syntax, or basic XPath.
929 * @example $("p").find("span");
930 * @before <p><span>Hello</span>, how are you?</p>
931 * @result $("p").find("span") == [ <span>Hello</span> ]
933 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
937 * @param String expr An expression to search with.
938 * @cat DOM/Traversing
941 return this.pushStack( jQuery.map( this, function(a){
942 return jQuery.find(t,a);
947 * Create cloned copies of all matched DOM Elements. This does
948 * not create a cloned copy of this particular jQuery object,
949 * instead it creates duplicate copies of all DOM Elements.
950 * This is useful for moving copies of the elements to another
951 * location in the DOM.
953 * @example $("b").clone().prependTo("p");
954 * @before <b>Hello</b><p>, how are you?</p>
955 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
957 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
958 * var clone = $('#yahoo').clone();
959 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
960 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
964 * @cat DOM/Manipulation
966 clone: function(deep) {
967 return this.pushStack( jQuery.map( this, function(a){
968 return a.cloneNode( deep != undefined ? deep : true );
973 * Removes all elements from the set of matched elements that do not
974 * match the specified expression. This method is used to narrow down
975 * the results of a search.
977 * All searching is done using a jQuery expression. The expression
978 * can be written using CSS 1-3 Selector syntax, or basic XPath.
980 * @example $("p").filter(".selected")
981 * @before <p class="selected">Hello</p><p>How are you?</p>
982 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
984 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
988 * @param String expr An expression to search with.
989 * @cat DOM/Traversing
993 * Removes all elements from the set of matched elements that do not
994 * match at least one of the expressions passed to the function. This
995 * method is used when you want to filter the set of matched elements
996 * through more than one expression.
998 * Elements will be retained in the jQuery object if they match at
999 * least one of the expressions passed.
1001 * @example $("p").filter([".selected", ":first"])
1002 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
1003 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
1007 * @param Array<String> exprs A set of expressions to evaluate against
1008 * @cat DOM/Traversing
1010 filter: function(t) {
1011 return this.pushStack(
1012 t.constructor == Array &&
1013 jQuery.map(this,function(a){
1014 for ( var i = 0; i < t.length; i++ )
1015 if ( jQuery.filter(t[i],[a]).r.length )
1019 t.constructor == Boolean &&
1020 ( t ? this.get() : [] ) ||
1022 typeof t == "function" &&
1023 jQuery.grep( this, t ) ||
1025 jQuery.filter(t,this).r, arguments );
1029 * Removes the specified Element from the set of matched elements. This
1030 * method is used to remove a single Element from a jQuery object.
1032 * @example $("p").not( document.getElementById("selected") )
1033 * @before <p>Hello</p><p id="selected">Hello Again</p>
1034 * @result [ <p>Hello</p> ]
1038 * @param Element el An element to remove from the set
1039 * @cat DOM/Traversing
1043 * Removes elements matching the specified expression from the set
1044 * of matched elements. This method is used to remove one or more
1045 * elements from a jQuery object.
1047 * @example $("p").not("#selected")
1048 * @before <p>Hello</p><p id="selected">Hello Again</p>
1049 * @result [ <p>Hello</p> ]
1051 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
1055 * @param String expr An expression with which to remove matching elements
1056 * @cat DOM/Traversing
1059 return this.pushStack( t.constructor == String ?
1060 jQuery.filter(t,this,false).r :
1061 jQuery.grep(this,function(a){ return a != t; }), arguments );
1065 * Adds the elements matched by the expression to the jQuery object. This
1066 * can be used to concatenate the result sets of two expressions.
1068 * @example $("p").add("span")
1069 * @before <p>Hello</p><p><span>Hello Again</span></p>
1070 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1074 * @param String expr An expression whose matched elements are added
1075 * @cat DOM/Traversing
1079 * Adds each of the Elements in the array to the set of matched elements.
1080 * This is used to add a set of Elements to a jQuery object.
1082 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1083 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1084 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1088 * @param Array<Element> els An array of Elements to add
1089 * @cat DOM/Traversing
1093 * Adds a single Element to the set of matched elements. This is used to
1094 * add a single Element to a jQuery object.
1096 * @example $("p").add( document.getElementById("a") )
1097 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1098 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1102 * @param Element el An Element to add
1103 * @cat DOM/Traversing
1106 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1107 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1111 * Checks the current selection against an expression and returns true,
1112 * if the selection fits the given expression. Does return false, if the
1113 * selection does not fit or the expression is not valid.
1115 * @example $("input[@type='checkbox']").parent().is("form")
1116 * @before <form><input type="checkbox" /></form>
1118 * @desc Returns true, because the parent of the input is a form element
1120 * @example $("input[@type='checkbox']").parent().is("form")
1121 * @before <form><p><input type="checkbox" /></p></form>
1123 * @desc Returns false, because the parent of the input is a p element
1125 * @example $("form").is(null)
1126 * @before <form></form>
1128 * @desc An invalid expression always returns false.
1130 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1131 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1132 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1133 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1134 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1135 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1136 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1137 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1138 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1139 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1140 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1141 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1142 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1143 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1144 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1145 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1146 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1147 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1148 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1149 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1150 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1151 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1155 * @param String expr The expression with which to filter
1156 * @cat DOM/Traversing
1158 is: function(expr) {
1159 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1163 * Executes the first callback for every element that fits the expression
1164 * and executes the second callback for every element that does not fit
1167 * @example $('div').ifelse(':visible',
1168 * function() { $(this).slideUp(); },
1169 function() { $(this).slideDown(); }
1171 * @desc Slides down all visible div elements and slides down all others
1173 * @test var checked = 0, notChecked = 0;
1174 * var inputChecked = $(':input').ifelse(':checked',
1175 * function() { checked++; },
1176 * function() { notChecked++ }
1178 * ok( checked == 2, 'Check is if/else: Count checked elements' );
1179 * ok( notChecked == 12, 'Check is if/else: Count unchecked elements' );
1181 * $('#first, #foo, #ap').ifelse('p',
1182 * function() { $(this).html('me == p') },
1183 * function() { $(this).html('me != p') }
1185 * ok( $('#first').text() == 'me == p', 'Check filter-if-clause' );
1186 * ok( $('#foo').text() == 'me != p', 'Check else-clause' );
1187 * ok( $('#ap').text() == 'me == p', 'Check filter-if-clause' );
1191 * @param String expression The expression with which to filter
1192 * @param Function ifCallback Called for elements that fit the expression
1193 * @param Function elseCallback Called for elements that don't fit the expression
1194 * @cat DOM/Traversing
1196 ifelse: function(expr, ifCallback, elseCallback) {
1197 var ifCallback = ifCallback || function() {};
1198 var elseCalllback = elseCallback || function() {};
1199 return this.each(function() {
1200 if($(this).is(expr)) {
1201 ifCallback.apply(this);
1203 elseCallback.apply(this);
1214 * @param Boolean table
1216 * @param Function fn The function doing the DOM manipulation.
1220 domManip: function(args, table, dir, fn){
1221 var clone = this.size() > 1;
1222 var a = jQuery.clean(args);
1224 return this.each(function(){
1227 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
1228 var tbody = this.getElementsByTagName("tbody");
1230 if ( !tbody.length ) {
1231 obj = document.createElement("tbody");
1232 this.appendChild( obj );
1237 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1238 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1239 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1254 pushStack: function(a,args) {
1255 var fn = args && args[args.length-1];
1257 if ( !fn || fn.constructor != Function ) {
1258 if ( !this.stack ) this.stack = [];
1259 this.stack.push( this.get() );
1262 var old = this.get();
1264 if ( typeof fn == "function" )
1274 * Extends the jQuery object itself. Can be used to add both static
1275 * functions and plugin methods.
1277 * @example $.fn.extend({
1278 * check: function() {
1279 * this.each(function() { this.checked = true; });
1281 * uncheck: function() {
1282 * this.each(function() { this.checked = false; });
1285 * $("input[@type=checkbox]").check();
1286 * $("input[@type=radio]").uncheck();
1287 * @desc Adds two plugin methods.
1297 * Extend one object with another, returning the original,
1298 * modified, object. This is a great utility for simple inheritance.
1300 * @example var settings = { validate: false, limit: 5, name: "foo" };
1301 * var options = { validate: true, name: "bar" };
1302 * jQuery.extend(settings, options);
1303 * @result settings == { validate: true, limit: 5, name: "bar" }
1305 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1306 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1307 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1308 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1309 * jQuery.extend(settings, options);
1310 * isSet( settings, merged, "Check if extended: settings must be extended" );
1311 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1314 * @param Object obj The object to extend
1315 * @param Object prop The object that will be merged into the first.
1319 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1320 if ( !prop ) { prop = obj; obj = this; }
1321 for ( var i in prop ) obj[i] = prop[i];
1333 jQuery.initDone = true;
1335 jQuery.each( jQuery.macros.axis, function(i,n){
1336 jQuery.fn[ i ] = function(a) {
1337 var ret = jQuery.map(this,n);
1338 if ( a && a.constructor == String )
1339 ret = jQuery.filter(a,ret).r;
1340 return this.pushStack( ret, arguments );
1344 jQuery.each( jQuery.macros.to, function(i,n){
1345 jQuery.fn[ i ] = function(){
1347 return this.each(function(){
1348 for ( var j = 0; j < a.length; j++ )
1349 jQuery(a[j])[n]( this );
1354 jQuery.each( jQuery.macros.each, function(i,n){
1355 jQuery.fn[ i ] = function() {
1356 return this.each( n, arguments );
1360 jQuery.each( jQuery.macros.filter, function(i,n){
1361 jQuery.fn[ n ] = function(num,fn) {
1362 return this.filter( ":" + n + "(" + num + ")", fn );
1366 jQuery.each( jQuery.macros.attr, function(i,n){
1368 jQuery.fn[ i ] = function(h) {
1369 return h == undefined ?
1370 this.length ? this[0][n] : null :
1375 jQuery.each( jQuery.macros.css, function(i,n){
1376 jQuery.fn[ n ] = function(h) {
1377 return h == undefined ?
1378 ( this.length ? jQuery.css( this[0], n ) : null ) :
1386 * A generic iterator function, which can be used to seemlessly
1387 * iterate over both objects and arrays. This function is not the same
1388 * as $().each() - which is used to iterate, exclusively, over a jQuery
1389 * object. This function can be used to iterate over anything.
1391 * @example $.each( [0,1,2], function(i){
1392 * alert( "Item #" + i + ": " + this );
1394 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1396 * @example $.each( { name: "John", lang: "JS" }, function(i){
1397 * alert( "Name: " + i + ", Value: " + this );
1399 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1402 * @param Object obj The object, or array, to iterate over.
1403 * @param Function fn The function that will be executed on every object.
1407 each: function( obj, fn, args ) {
1408 if ( obj.length == undefined )
1409 for ( var i in obj )
1410 fn.apply( obj[i], args || [i, obj[i]] );
1412 for ( var i = 0; i < obj.length; i++ )
1413 fn.apply( obj[i], args || [i, obj[i]] );
1419 if (jQuery.className.has(o,c)) return;
1420 o.className += ( o.className ? " " : "" ) + c;
1422 remove: function(o,c){
1424 o.className = !c ? "" :
1425 o.className.replace(
1426 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/
1430 var classes = o.className.split(" ");
1431 for(var i=0; i<classes.length; i++) {
1432 if(classes[i] == c) {
1433 classes.splice(i, 1);
1437 o.className = classes.join(' ');
1440 has: function(e,a) {
1441 if ( e.className != undefined )
1443 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1448 * Swap in/out style options.
1451 swap: function(e,o,f) {
1452 for ( var i in o ) {
1453 e.style["old"+i] = e.style[i];
1458 e.style[i] = e.style["old"+i];
1461 css: function(e,p) {
1462 if ( p == "height" || p == "width" ) {
1463 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1465 for ( var i in d ) {
1466 old["padding" + d[i]] = 0;
1467 old["border" + d[i] + "Width"] = 0;
1470 jQuery.swap( e, old, function() {
1471 if (jQuery.css(e,"display") != "none") {
1472 oHeight = e.offsetHeight;
1473 oWidth = e.offsetWidth;
1475 e = jQuery(e.cloneNode(true)).css({
1476 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1477 }).appendTo(e.parentNode)[0];
1479 var parPos = jQuery.css(e.parentNode,"position");
1480 if ( parPos == "" || parPos == "static" )
1481 e.parentNode.style.position = "relative";
1483 oHeight = e.clientHeight;
1484 oWidth = e.clientWidth;
1486 if ( parPos == "" || parPos == "static" )
1487 e.parentNode.style.position = "static";
1489 e.parentNode.removeChild(e);
1493 return p == "height" ? oHeight : oWidth;
1494 } else if ( p == "opacity" && jQuery.browser.msie )
1495 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1497 return jQuery.curCSS( e, p );
1500 curCSS: function(elem, prop, force) {
1503 if (!force && elem.style[prop]) {
1505 ret = elem.style[prop];
1507 } else if (elem.currentStyle) {
1509 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1510 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1512 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1514 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1515 var cur = document.defaultView.getComputedStyle(elem, null);
1518 ret = cur.getPropertyValue(prop);
1519 else if ( prop == 'display' )
1522 jQuery.swap(elem, { display: 'block' }, function() {
1523 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1531 clean: function(a) {
1533 for ( var i = 0; i < a.length; i++ ) {
1534 if ( a[i].constructor == String ) {
1538 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1540 a[i] = "<table>" + a[i] + "</table>";
1541 } else if ( !a[i].indexOf("<tr") ) {
1543 a[i] = "<table>" + a[i] + "</table>";
1544 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1546 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1549 var div = document.createElement("div");
1550 div.innerHTML = a[i];
1553 div = div.firstChild;
1554 if ( table != "thead" ) div = div.firstChild;
1555 if ( table == "td" ) div = div.firstChild;
1558 for ( var j = 0; j < div.childNodes.length; j++ )
1559 r.push( div.childNodes[j] );
1560 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1561 for ( var k = 0; k < a[i].length; k++ )
1563 else if ( a[i] !== null )
1564 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1570 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1571 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1579 last: "i==r.length-1",
1584 "nth-child": "jQuery.sibling(a,m[3]).cur",
1585 "first-child": "jQuery.sibling(a,0).cur",
1586 "last-child": "jQuery.sibling(a,0).last",
1587 "only-child": "jQuery.sibling(a).length==1",
1590 parent: "a.childNodes.length",
1591 empty: "!a.childNodes.length",
1594 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1597 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1598 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1601 enabled: "!a.disabled",
1602 disabled: "a.disabled",
1603 checked: "a.checked",
1604 selected: "a.selected",
1607 text: "a.type=='text'",
1608 radio: "a.type=='radio'",
1609 checkbox: "a.type=='checkbox'",
1610 file: "a.type=='file'",
1611 password: "a.type=='password'",
1612 submit: "a.type=='submit'",
1613 image: "a.type=='image'",
1614 reset: "a.type=='reset'",
1615 button: "a.type=='button'",
1616 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
1618 ".": "jQuery.className.has(a,m[2])",
1622 "^=": "z && !z.indexOf(m[4])",
1623 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1624 "*=": "z && z.indexOf(m[4])>=0",
1627 "[": "jQuery.find(m[2],a).length"
1631 "\\.\\.|/\\.\\.", "a.parentNode",
1632 ">|/", "jQuery.sibling(a.firstChild)",
1633 "\\+", "jQuery.sibling(a).next",
1636 var s = jQuery.sibling(a);
1638 for ( var i = s.n; i < s.length; i++ )
1646 * @test t( "Element Selector", "div", ["main","foo"] );
1647 * t( "Element Selector", "body", ["body"] );
1648 * t( "Element Selector", "html", ["html"] );
1649 * ok( $("*").size() >= 30, "Element Selector" );
1650 * t( "Parent Element", "div div", ["foo"] );
1652 * t( "ID Selector", "#body", ["body"] );
1653 * t( "ID Selector w/ Element", "body#body", ["body"] );
1654 * t( "ID Selector w/ Element", "ul#first", [] );
1656 * t( "Class Selector", ".blog", ["mark","simon"] );
1657 * t( "Class Selector", ".blog.link", ["simon"] );
1658 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1659 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1661 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1662 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1663 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1664 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1666 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1667 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1668 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1669 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1670 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1671 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1672 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1673 * t( "Adjacent", "a + a", ["groups"] );
1674 * t( "Adjacent", "a +a", ["groups"] );
1675 * t( "Adjacent", "a+ a", ["groups"] );
1676 * t( "Adjacent", "a+a", ["groups"] );
1677 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1678 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1679 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1680 * t( "Attribute Exists", "a[@title]", ["google"] );
1681 * t( "Attribute Exists", "*[@title]", ["google"] );
1682 * t( "Attribute Exists", "[@title]", ["google"] );
1684 * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] );
1685 * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
1686 * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] );
1688 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1689 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1690 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1691 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1692 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1693 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1695 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1696 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1697 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1698 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1699 * t( "Last Child", "p:last-child", ["sap"] );
1700 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1701 * t( "Empty", "ul:empty", ["firstUL"] );
1702 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1703 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1704 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1705 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1706 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1707 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1708 * t( "Element Preceded By", "p ~ div", ["foo"] );
1709 * t( "Not", "a.blog:not(.link)", ["mark"] );
1711 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1712 * t( "All Div Elements", "//div", ["main","foo"] );
1713 * t( "Absolute Path", "/html/body", ["body"] );
1714 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1715 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1716 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1717 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1718 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1719 * t( "Attribute Exists", "//a[@title]", ["google"] );
1720 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1721 * t( "Parent Axis", "//p/..", ["main","foo"] );
1722 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1723 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1724 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1726 * t( "nth Element", "p:nth(1)", ["ap"] );
1727 * t( "First Element", "p:first", ["firstp"] );
1728 * t( "Last Element", "p:last", ["first"] );
1729 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1730 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1731 * t( "Position Equals", "p:eq(1)", ["ap"] );
1732 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1733 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1734 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1735 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1736 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1738 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1740 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1741 * t( "All Children of ID with no children", "#firstUL/*", [] );
1743 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1744 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1745 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1746 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1747 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1748 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1749 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1751 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1752 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1753 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1756 * @type Array<Element>
1760 find: function( t, context ) {
1761 // Make sure that the context is a DOM Element
1762 if ( context && context.nodeType == undefined )
1765 // Set the correct context (if none is provided)
1766 context = context || jQuery.context || document;
1768 if ( t.constructor != String ) return [t];
1770 if ( !t.indexOf("//") ) {
1771 context = context.documentElement;
1772 t = t.substr(2,t.length);
1773 } else if ( !t.indexOf("/") ) {
1774 context = context.documentElement;
1775 t = t.substr(1,t.length);
1776 // FIX Assume the root element is right :(
1777 if ( t.indexOf("/") >= 1 )
1778 t = t.substr(t.indexOf("/"),t.length);
1781 var ret = [context];
1785 while ( t.length > 0 && last != t ) {
1789 t = jQuery.trim(t).replace( /^\/\//i, "" );
1791 var foundToken = false;
1793 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1794 if ( foundToken ) continue;
1796 var re = new RegExp("^(" + jQuery.token[i] + ")");
1800 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1801 t = jQuery.trim( t.replace( re, "" ) );
1806 if ( !foundToken ) {
1807 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1808 if ( ret[0] == context ) ret.shift();
1809 done = jQuery.merge( done, ret );
1810 r = ret = [context];
1811 t = " " + t.substr(1,t.length);
1813 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1814 var m = re2.exec(t);
1816 if ( m[1] == "#" ) {
1817 // Ummm, should make this work in all XML docs
1818 var oid = document.getElementById(m[2]);
1819 r = ret = oid ? [oid] : [];
1820 t = t.replace( re2, "" );
1822 if ( !m[2] || m[1] == "." ) m[2] = "*";
1824 for ( var i = 0; i < ret.length; i++ )
1825 r = jQuery.merge( r,
1827 jQuery.getAll(ret[i]) :
1828 ret[i].getElementsByTagName(m[2])
1836 var val = jQuery.filter(t,r);
1838 t = jQuery.trim(val.t);
1842 if ( ret && ret[0] == context ) ret.shift();
1843 done = jQuery.merge( done, ret );
1848 getAll: function(o,r) {
1850 var s = o.childNodes;
1851 for ( var i = 0; i < s.length; i++ )
1852 if ( s[i].nodeType == 1 ) {
1854 jQuery.getAll( s[i], r );
1859 attr: function(elem, name, value){
1862 "class": "className",
1863 "float": "cssFloat",
1864 innerHTML: "innerHTML",
1865 className: "className",
1867 disabled: "disabled",
1872 if ( value != undefined ) elem[fix[name]] = value;
1873 return elem[fix[name]];
1874 } else if( value == undefined && $.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1875 return elem.getAttributeNode(name).nodeValue;
1876 } else if ( elem.getAttribute != undefined ) {
1877 if ( value != undefined ) elem.setAttribute( name, value );
1878 return elem.getAttribute( name, 2 );
1880 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1881 if ( value != undefined ) elem[name] = value;
1886 // The regular expressions that power the parsing engine
1888 // Match: [@value='test'], [@foo]
1889 "\\[ *(@)S *([!*$^=]*)Q\\]",
1891 // Match: [div], [div p]
1894 // Match: :contains('foo')
1897 // Match: :even, :last-chlid
1901 filter: function(t,r,not) {
1902 // Figure out if we're doing regular, or inverse, filtering
1903 var g = not !== false ? jQuery.grep :
1904 function(a,f) {return jQuery.grep(a,f,true);};
1906 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1908 var p = jQuery.parse;
1910 for ( var i = 0; i < p.length; i++ ) {
1911 // get number for backreference
1913 if(p[i].indexOf('Q') != -1){
1914 br = p[i].replace(/\\\(/g,'').match(/\(|S/g).length+1;
1916 var re = new RegExp( "^" + p[i]
1918 // Look for a string-like sequence
1919 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1921 // Look for something (optionally) enclosed with quotes
1922 .replace( 'Q', " *('|\"|)([^'\"]*?)\\"+br+" *" ), "i" );
1924 var m = re.exec( t );
1927 // Re-organize the match
1929 m = ["",m[1], m[3], m[2], m[5]];
1930 } else if(br != 0) {
1933 // Remove what we just matched
1934 t = t.replace( re, "" );
1940 // :not() is a special case that can be optimized by
1941 // keeping it out of the expression list
1942 if ( m[1] == ":" && m[2] == "not" )
1943 r = jQuery.filter(m[3],r,false).r;
1945 // Otherwise, find the expression to execute
1947 var f = jQuery.expr[m[1]];
1948 if ( f.constructor != String )
1949 f = jQuery.expr[m[1]][m[2]];
1951 // Build a custom macro to enclose it
1952 eval("f = function(a,i){" +
1953 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1954 "return " + f + "}");
1956 // Execute it against the current filter
1961 // Return an array of filtered elements (r)
1962 // and the modified expression string (t)
1963 return { r: r, t: t };
1967 * Remove the whitespace from the beginning and end of a string.
1969 * @example $.trim(" hello, how are you? ");
1970 * @result "hello, how are you?"
1974 * @param String str The string to trim.
1978 return t.replace(/^\s+|\s+$/g, "");
1982 * All ancestors of a given element.
1986 * @type Array<Element>
1987 * @param Element elem The element to find the ancestors of.
1988 * @cat DOM/Traversing
1990 parents: function( elem ){
1992 var cur = elem.parentNode;
1993 while ( cur && cur != document ) {
1994 matched.push( cur );
1995 cur = cur.parentNode;
2001 * All elements on a specified axis.
2006 * @param Element elem The element to find all the siblings of (including itself).
2007 * @cat DOM/Traversing
2009 sibling: function(elem, pos, not) {
2013 var siblings = elem.parentNode.childNodes;
2014 for ( var i = 0; i < siblings.length; i++ ) {
2015 if ( not === true && siblings[i] == elem ) continue;
2017 if ( siblings[i].nodeType == 1 )
2018 elems.push( siblings[i] );
2019 if ( siblings[i] == elem )
2020 elems.n = elems.length - 1;
2024 return jQuery.extend( elems, {
2025 last: elems.n == elems.length - 1,
2026 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
2027 prev: elems[elems.n - 1],
2028 next: elems[elems.n + 1]
2033 * Merge two arrays together, removing all duplicates. The final order
2034 * or the new array is: All the results from the first array, followed
2035 * by the unique results from the second array.
2037 * @example $.merge( [0,1,2], [2,3,4] )
2038 * @result [0,1,2,3,4]
2040 * @example $.merge( [3,2,1], [4,3,2] )
2045 * @param Array first The first array to merge.
2046 * @param Array second The second array to merge.
2049 merge: function(first, second) {
2052 // Move b over to the new array (this helps to avoid
2053 // StaticNodeList instances)
2054 for ( var k = 0; k < first.length; k++ )
2055 result[k] = first[k];
2057 // Now check for duplicates between a and b and only
2058 // add the unique items
2059 for ( var i = 0; i < second.length; i++ ) {
2060 var noCollision = true;
2062 // The collision-checking process
2063 for ( var j = 0; j < first.length; j++ )
2064 if ( second[i] == first[j] )
2065 noCollision = false;
2067 // If the item is unique, add it
2069 result.push( second[i] );
2076 * Filter items out of an array, by using a filter function.
2077 * The specified function will be passed two arguments: The
2078 * current array item and the index of the item in the array. The
2079 * function should return 'true' if you wish to keep the item in
2080 * the array, false if it should be removed.
2082 * @example $.grep( [0,1,2], function(i){
2089 * @param Array array The Array to find items in.
2090 * @param Function fn The function to process each item against.
2091 * @param Boolean inv Invert the selection - select the opposite of the function.
2094 grep: function(elems, fn, inv) {
2095 // If a string is passed in for the function, make a function
2096 // for it (a handy shortcut)
2097 if ( fn.constructor == String )
2098 fn = new Function("a","i","return " + fn);
2102 // Go through the array, only saving the items
2103 // that pass the validator function
2104 for ( var i = 0; i < elems.length; i++ )
2105 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2106 result.push( elems[i] );
2112 * Translate all items in an array to another array of items.
2113 * The translation function that is provided to this method is
2114 * called for each item in the array and is passed one argument:
2115 * The item to be translated. The function can then return:
2116 * The translated value, 'null' (to remove the item), or
2117 * an array of values - which will be flattened into the full array.
2119 * @example $.map( [0,1,2], function(i){
2124 * @example $.map( [0,1,2], function(i){
2125 * return i > 0 ? i + 1 : null;
2129 * @example $.map( [0,1,2], function(i){
2130 * return [ i, i + 1 ];
2132 * @result [0, 1, 1, 2, 2, 3]
2136 * @param Array array The Array to translate.
2137 * @param Function fn The function to process each item against.
2140 map: function(elems, fn) {
2141 // If a string is passed in for the function, make a function
2142 // for it (a handy shortcut)
2143 if ( fn.constructor == String )
2144 fn = new Function("a","return " + fn);
2148 // Go through the array, translating each of the items to their
2149 // new value (or values).
2150 for ( var i = 0; i < elems.length; i++ ) {
2151 var val = fn(elems[i],i);
2153 if ( val !== null && val != undefined ) {
2154 if ( val.constructor != Array ) val = [val];
2155 result = jQuery.merge( result, val );
2163 * A number of helper functions used for managing events.
2164 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2168 // Bind an event to an element
2169 // Original by Dean Edwards
2170 add: function(element, type, handler) {
2171 // For whatever reason, IE has trouble passing the window object
2172 // around, causing it to be cloned in the process
2173 if ( jQuery.browser.msie && element.setInterval != undefined )
2176 // Make sure that the function being executed has a unique ID
2177 if ( !handler.guid )
2178 handler.guid = this.guid++;
2180 // Init the element's event structure
2181 if (!element.events)
2182 element.events = {};
2184 // Get the current list of functions bound to this event
2185 var handlers = element.events[type];
2187 // If it hasn't been initialized yet
2189 // Init the event handler queue
2190 handlers = element.events[type] = {};
2192 // Remember an existing handler, if it's already there
2193 if (element["on" + type])
2194 handlers[0] = element["on" + type];
2197 // Add the function to the element's handler list
2198 handlers[handler.guid] = handler;
2200 // And bind the global event handler to the element
2201 element["on" + type] = this.handle;
2203 // Remember the function in a global list (for triggering)
2204 if (!this.global[type])
2205 this.global[type] = [];
2206 this.global[type].push( element );
2212 // Detach an event or set of events from an element
2213 remove: function(element, type, handler) {
2215 if (type && element.events[type])
2217 delete element.events[type][handler.guid];
2219 for ( var i in element.events[type] )
2220 delete element.events[type][i];
2222 for ( var j in element.events )
2223 this.remove( element, j );
2226 trigger: function(type,data,element) {
2227 // Touch up the incoming data
2230 // Handle a global trigger
2232 var g = this.global[type];
2234 for ( var i = 0; i < g.length; i++ )
2235 this.trigger( type, data, g[i] );
2237 // Handle triggering a single element
2238 } else if ( element["on" + type] ) {
2239 // Pass along a fake event
2240 data.unshift( this.fix({ type: type, target: element }) );
2242 // Trigger the event
2243 element["on" + type].apply( element, data );
2247 handle: function(event) {
2248 if ( typeof jQuery == "undefined" ) return;
2250 event = event || jQuery.event.fix( window.event );
2252 // If no correct event was found, fail
2253 if ( !event ) return;
2255 var returnValue = true;
2257 var c = this.events[event.type];
2259 var args = [].slice.call( arguments, 1 );
2260 args.unshift( event );
2262 for ( var j in c ) {
2263 if ( c[j].apply( this, args ) === false ) {
2264 event.preventDefault();
2265 event.stopPropagation();
2266 returnValue = false;
2273 fix: function(event) {
2275 event.preventDefault = function() {
2276 this.returnValue = false;
2279 event.stopPropagation = function() {
2280 this.cancelBubble = true;
2291 * Contains flags for the useragent, read from navigator.userAgent.
2292 * Available flags are: safari, opera, msie, mozilla
2293 * This property is available before the DOM is ready, therefore you can
2294 * use it to add ready events only for certain browsers.
2296 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2297 * jQBrowser plugin</a> for advanced browser detection:
2299 * @example $.browser.msie
2300 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2302 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2303 * @desc Alerts "this is safari!" only for safari browsers
2310 var b = navigator.userAgent.toLowerCase();
2312 // Figure out what browser is being used
2314 safari: /webkit/.test(b),
2315 opera: /opera/.test(b),
2316 msie: /msie/.test(b) && !/opera/.test(b),
2317 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2320 // Check to see if the W3C box model is being used
2321 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2327 * Append all of the matched elements to another, specified, set of elements.
2328 * This operation is, essentially, the reverse of doing a regular
2329 * $(A).append(B), in that instead of appending B to A, you're appending
2332 * @example $("p").appendTo("#foo");
2333 * @before <p>I would like to say: </p><div id="foo"></div>
2334 * @result <div id="foo"><p>I would like to say: </p></div>
2338 * @param String expr A jQuery expression of elements to match.
2339 * @cat DOM/Manipulation
2344 * Prepend all of the matched elements to another, specified, set of elements.
2345 * This operation is, essentially, the reverse of doing a regular
2346 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2349 * @example $("p").prependTo("#foo");
2350 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2351 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2355 * @param String expr A jQuery expression of elements to match.
2356 * @cat DOM/Manipulation
2358 prependTo: "prepend",
2361 * Insert all of the matched elements before another, specified, set of elements.
2362 * This operation is, essentially, the reverse of doing a regular
2363 * $(A).before(B), in that instead of inserting B before A, you're inserting
2366 * @example $("p").insertBefore("#foo");
2367 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2368 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2370 * @name insertBefore
2372 * @param String expr A jQuery expression of elements to match.
2373 * @cat DOM/Manipulation
2375 insertBefore: "before",
2378 * Insert all of the matched elements after another, specified, set of elements.
2379 * This operation is, essentially, the reverse of doing a regular
2380 * $(A).after(B), in that instead of inserting B after A, you're inserting
2383 * @example $("p").insertAfter("#foo");
2384 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2385 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2389 * @param String expr A jQuery expression of elements to match.
2390 * @cat DOM/Manipulation
2392 insertAfter: "after"
2396 * Get the current CSS width of the first matched element.
2398 * @example $("p").width();
2399 * @before <p>This is just a test.</p>
2408 * Set the CSS width of every matched element. Be sure to include
2409 * the "px" (or other unit of measurement) after the number that you
2410 * specify, otherwise you might get strange results.
2412 * @example $("p").width("20px");
2413 * @before <p>This is just a test.</p>
2414 * @result <p style="width:20px;">This is just a test.</p>
2418 * @param String val Set the CSS property to the specified value.
2423 * Get the current CSS height of the first matched element.
2425 * @example $("p").height();
2426 * @before <p>This is just a test.</p>
2435 * Set the CSS height of every matched element. Be sure to include
2436 * the "px" (or other unit of measurement) after the number that you
2437 * specify, otherwise you might get strange results.
2439 * @example $("p").height("20px");
2440 * @before <p>This is just a test.</p>
2441 * @result <p style="height:20px;">This is just a test.</p>
2445 * @param String val Set the CSS property to the specified value.
2450 * Get the current CSS top of the first matched element.
2452 * @example $("p").top();
2453 * @before <p>This is just a test.</p>
2462 * Set the CSS top of every matched element. Be sure to include
2463 * the "px" (or other unit of measurement) after the number that you
2464 * specify, otherwise you might get strange results.
2466 * @example $("p").top("20px");
2467 * @before <p>This is just a test.</p>
2468 * @result <p style="top:20px;">This is just a test.</p>
2472 * @param String val Set the CSS property to the specified value.
2477 * Get the current CSS left of the first matched element.
2479 * @example $("p").left();
2480 * @before <p>This is just a test.</p>
2489 * Set the CSS left of every matched element. Be sure to include
2490 * the "px" (or other unit of measurement) after the number that you
2491 * specify, otherwise you might get strange results.
2493 * @example $("p").left("20px");
2494 * @before <p>This is just a test.</p>
2495 * @result <p style="left:20px;">This is just a test.</p>
2499 * @param String val Set the CSS property to the specified value.
2504 * Get the current CSS position of the first matched element.
2506 * @example $("p").position();
2507 * @before <p>This is just a test.</p>
2516 * Set the CSS position of every matched element.
2518 * @example $("p").position("relative");
2519 * @before <p>This is just a test.</p>
2520 * @result <p style="position:relative;">This is just a test.</p>
2524 * @param String val Set the CSS property to the specified value.
2529 * Get the current CSS float of the first matched element.
2531 * @example $("p").float();
2532 * @before <p>This is just a test.</p>
2541 * Set the CSS float of every matched element.
2543 * @example $("p").float("left");
2544 * @before <p>This is just a test.</p>
2545 * @result <p style="float:left;">This is just a test.</p>
2549 * @param String val Set the CSS property to the specified value.
2554 * Get the current CSS overflow of the first matched element.
2556 * @example $("p").overflow();
2557 * @before <p>This is just a test.</p>
2566 * Set the CSS overflow of every matched element.
2568 * @example $("p").overflow("auto");
2569 * @before <p>This is just a test.</p>
2570 * @result <p style="overflow:auto;">This is just a test.</p>
2574 * @param String val Set the CSS property to the specified value.
2579 * Get the current CSS color of the first matched element.
2581 * @example $("p").color();
2582 * @before <p>This is just a test.</p>
2591 * Set the CSS color of every matched element.
2593 * @example $("p").color("blue");
2594 * @before <p>This is just a test.</p>
2595 * @result <p style="color:blue;">This is just a test.</p>
2599 * @param String val Set the CSS property to the specified value.
2604 * Get the current CSS background of the first matched element.
2606 * @example $("p").background();
2607 * @before <p style="background:blue;">This is just a test.</p>
2616 * Set the CSS background of every matched element.
2618 * @example $("p").background("blue");
2619 * @before <p>This is just a test.</p>
2620 * @result <p style="background:blue;">This is just a test.</p>
2624 * @param String val Set the CSS property to the specified value.
2628 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2631 * Reduce the set of matched elements to a single element.
2632 * The position of the element in the set of matched elements
2633 * starts at 0 and goes to length - 1.
2635 * @example $("p").eq(1)
2636 * @before <p>This is just a test.</p><p>So is this</p>
2637 * @result [ <p>So is this</p> ]
2641 * @param Number pos The index of the element that you wish to limit to.
2646 * Reduce the set of matched elements to all elements before a given position.
2647 * The position of the element in the set of matched elements
2648 * starts at 0 and goes to length - 1.
2650 * @example $("p").lt(1)
2651 * @before <p>This is just a test.</p><p>So is this</p>
2652 * @result [ <p>This is just a test.</p> ]
2656 * @param Number pos Reduce the set to all elements below this position.
2661 * Reduce the set of matched elements to all elements after a given position.
2662 * The position of the element in the set of matched elements
2663 * starts at 0 and goes to length - 1.
2665 * @example $("p").gt(0)
2666 * @before <p>This is just a test.</p><p>So is this</p>
2667 * @result [ <p>So is this</p> ]
2671 * @param Number pos Reduce the set to all elements after this position.
2676 * Filter the set of elements to those that contain the specified text.
2678 * @example $("p").contains("test")
2679 * @before <p>This is just a test.</p><p>So is this</p>
2680 * @result [ <p>This is just a test.</p> ]
2684 * @param String str The string that will be contained within the text of an element.
2685 * @cat DOM/Traversing
2688 filter: [ "eq", "lt", "gt", "contains" ],
2692 * Get the current value of the first matched element.
2694 * @example $("input").val();
2695 * @before <input type="text" value="some text"/>
2696 * @result "some text"
2698 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2699 * ok( !$("#text1").val() == "", "Check for value of input element" );
2703 * @cat DOM/Attributes
2707 * Set the value of every matched element.
2709 * @example $("input").value("test");
2710 * @before <input type="text" value="some text"/>
2711 * @result <input type="text" value="test"/>
2713 * @test document.getElementById('text1').value = "bla";
2714 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2715 * $("#text1").val('test');
2716 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2720 * @param String val Set the property to the specified value.
2721 * @cat DOM/Attributes
2726 * Get the html contents of the first matched element.
2728 * @example $("div").html();
2729 * @before <div><input/></div>
2734 * @cat DOM/Attributes
2738 * Set the html contents of every matched element.
2740 * @example $("div").html("<b>new stuff</b>");
2741 * @before <div><input/></div>
2742 * @result <div><b>new stuff</b></div>
2744 * @test var div = $("div");
2745 * div.html("<b>test</b>");
2747 * for ( var i = 0; i < div.size(); i++ ) {
2748 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2750 * ok( pass, "Set HTML" );
2754 * @param String val Set the html contents to the specified value.
2755 * @cat DOM/Attributes
2760 * Get the current id of the first matched element.
2762 * @example $("input").id();
2763 * @before <input type="text" id="test" value="some text"/>
2766 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2767 * ok( $("#foo").id() == "foo", "Check for id" );
2768 * ok( !$("head").id(), "Check for id" );
2772 * @cat DOM/Attributes
2776 * Set the id of every matched element.
2778 * @example $("input").id("newid");
2779 * @before <input type="text" id="test" value="some text"/>
2780 * @result <input type="text" id="newid" value="some text"/>
2784 * @param String val Set the property to the specified value.
2785 * @cat DOM/Attributes
2790 * Get the current title of the first matched element.
2792 * @example $("img").title();
2793 * @before <img src="test.jpg" title="my image"/>
2794 * @result "my image"
2796 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2797 * ok( !$("#yahoo").title(), "Check for title" );
2801 * @cat DOM/Attributes
2805 * Set the title of every matched element.
2807 * @example $("img").title("new title");
2808 * @before <img src="test.jpg" title="my image"/>
2809 * @result <img src="test.jpg" title="new image"/>
2813 * @param String val Set the property to the specified value.
2814 * @cat DOM/Attributes
2819 * Get the current name of the first matched element.
2821 * @example $("input").name();
2822 * @before <input type="text" name="username"/>
2823 * @result "username"
2825 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2826 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2827 * ok( !$("#area1").name(), "Check for name" );
2831 * @cat DOM/Attributes
2835 * Set the name of every matched element.
2837 * @example $("input").name("user");
2838 * @before <input type="text" name="username"/>
2839 * @result <input type="text" name="user"/>
2843 * @param String val Set the property to the specified value.
2844 * @cat DOM/Attributes
2849 * Get the current href of the first matched element.
2851 * @example $("a").href();
2852 * @before <a href="test.html">my link</a>
2853 * @result "test.html"
2857 * @cat DOM/Attributes
2861 * Set the href of every matched element.
2863 * @example $("a").href("test2.html");
2864 * @before <a href="test.html">my link</a>
2865 * @result <a href="test2.html">my link</a>
2869 * @param String val Set the property to the specified value.
2870 * @cat DOM/Attributes
2875 * Get the current src of the first matched element.
2877 * @example $("img").src();
2878 * @before <img src="test.jpg" title="my image"/>
2879 * @result "test.jpg"
2883 * @cat DOM/Attributes
2887 * Set the src of every matched element.
2889 * @example $("img").src("test2.jpg");
2890 * @before <img src="test.jpg" title="my image"/>
2891 * @result <img src="test2.jpg" title="my image"/>
2895 * @param String val Set the property to the specified value.
2896 * @cat DOM/Attributes
2901 * Get the current rel of the first matched element.
2903 * @example $("a").rel();
2904 * @before <a href="test.html" rel="nofollow">my link</a>
2905 * @result "nofollow"
2909 * @cat DOM/Attributes
2913 * Set the rel of every matched element.
2915 * @example $("a").rel("nofollow");
2916 * @before <a href="test.html">my link</a>
2917 * @result <a href="test.html" rel="nofollow">my link</a>
2921 * @param String val Set the property to the specified value.
2922 * @cat DOM/Attributes
2929 * Get a set of elements containing the unique parents of the matched
2932 * @example $("p").parent()
2933 * @before <div><p>Hello</p><p>Hello</p></div>
2934 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2938 * @cat DOM/Traversing
2942 * Get a set of elements containing the unique parents of the matched
2943 * set of elements, and filtered by an expression.
2945 * @example $("p").parent(".selected")
2946 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2947 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2951 * @param String expr An expression to filter the parents with
2952 * @cat DOM/Traversing
2954 parent: "a.parentNode",
2957 * Get a set of elements containing the unique ancestors of the matched
2958 * set of elements (except for the root element).
2960 * @example $("span").ancestors()
2961 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2962 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2966 * @cat DOM/Traversing
2970 * Get a set of elements containing the unique ancestors of the matched
2971 * set of elements, and filtered by an expression.
2973 * @example $("span").ancestors("p")
2974 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2975 * @result [ <p><span>Hello</span></p> ]
2979 * @param String expr An expression to filter the ancestors with
2980 * @cat DOM/Traversing
2982 ancestors: jQuery.parents,
2985 * Get a set of elements containing the unique ancestors of the matched
2986 * set of elements (except for the root element).
2988 * @example $("span").ancestors()
2989 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2990 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2994 * @cat DOM/Traversing
2998 * Get a set of elements containing the unique ancestors of the matched
2999 * set of elements, and filtered by an expression.
3001 * @example $("span").ancestors("p")
3002 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
3003 * @result [ <p><span>Hello</span></p> ]
3007 * @param String expr An expression to filter the ancestors with
3008 * @cat DOM/Traversing
3010 parents: jQuery.parents,
3013 * Get a set of elements containing the unique next siblings of each of the
3014 * matched set of elements.
3016 * It only returns the very next sibling, not all next siblings.
3018 * @example $("p").next()
3019 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
3020 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
3024 * @cat DOM/Traversing
3028 * Get a set of elements containing the unique next siblings of each of the
3029 * matched set of elements, and filtered by an expression.
3031 * It only returns the very next sibling, not all next siblings.
3033 * @example $("p").next(".selected")
3034 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
3035 * @result [ <p class="selected">Hello Again</p> ]
3039 * @param String expr An expression to filter the next Elements with
3040 * @cat DOM/Traversing
3042 next: "jQuery.sibling(a).next",
3045 * Get a set of elements containing the unique previous siblings of each of the
3046 * matched set of elements.
3048 * It only returns the immediately previous sibling, not all previous siblings.
3050 * @example $("p").prev()
3051 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3052 * @result [ <div><span>Hello Again</span></div> ]
3056 * @cat DOM/Traversing
3060 * Get a set of elements containing the unique previous siblings of each of the
3061 * matched set of elements, and filtered by an expression.
3063 * It only returns the immediately previous sibling, not all previous siblings.
3065 * @example $("p").previous(".selected")
3066 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3067 * @result [ <div><span>Hello</span></div> ]
3071 * @param String expr An expression to filter the previous Elements with
3072 * @cat DOM/Traversing
3074 prev: "jQuery.sibling(a).prev",
3077 * Get a set of elements containing all of the unique siblings of each of the
3078 * matched set of elements.
3080 * @example $("div").siblings()
3081 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3082 * @result [ <p>Hello</p>, <p>And Again</p> ]
3084 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3088 * @cat DOM/Traversing
3092 * Get a set of elements containing all of the unique siblings of each of the
3093 * matched set of elements, and filtered by an expression.
3095 * @example $("div").siblings(".selected")
3096 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3097 * @result [ <p class="selected">Hello Again</p> ]
3099 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3100 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3104 * @param String expr An expression to filter the sibling Elements with
3105 * @cat DOM/Traversing
3107 siblings: "jQuery.sibling(a, null, true)",
3111 * Get a set of elements containing all of the unique children of each of the
3112 * matched set of elements.
3114 * @example $("div").children()
3115 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3116 * @result [ <span>Hello Again</span> ]
3118 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3122 * @cat DOM/Traversing
3126 * Get a set of elements containing all of the unique children of each of the
3127 * matched set of elements, and filtered by an expression.
3129 * @example $("div").children(".selected")
3130 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3131 * @result [ <p class="selected">Hello Again</p> ]
3133 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3137 * @param String expr An expression to filter the child Elements with
3138 * @cat DOM/Traversing
3140 children: "jQuery.sibling(a.firstChild)"
3146 * Remove an attribute from each of the matched elements.
3148 * @example $("input").removeAttr("disabled")
3149 * @before <input disabled="disabled"/>
3154 * @param String name The name of the attribute to remove.
3157 removeAttr: function( key ) {
3158 this.removeAttribute( key );
3162 * Displays each of the set of matched elements if they are hidden.
3164 * @example $("p").show()
3165 * @before <p style="display: none">Hello</p>
3166 * @result [ <p style="display: block">Hello</p> ]
3168 * @test var pass = true, div = $("div");
3169 * div.show().each(function(){
3170 * if ( this.style.display == "none" ) pass = false;
3172 * ok( pass, "Show" );
3179 this.style.display = this.oldblock ? this.oldblock : "";
3180 if ( jQuery.css(this,"display") == "none" )
3181 this.style.display = "block";
3185 * Hides each of the set of matched elements if they are shown.
3187 * @example $("p").hide()
3188 * @before <p>Hello</p>
3189 * @result [ <p style="display: none">Hello</p> ]
3191 * var pass = true, div = $("div");
3192 * div.hide().each(function(){
3193 * if ( this.style.display != "none" ) pass = false;
3195 * ok( pass, "Hide" );
3202 this.oldblock = this.oldblock || jQuery.css(this,"display");
3203 if ( this.oldblock == "none" )
3204 this.oldblock = "block";
3205 this.style.display = "none";
3209 * Toggles each of the set of matched elements. If they are shown,
3210 * toggle makes them hidden. If they are hidden, toggle
3213 * @example $("p").toggle()
3214 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3215 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3222 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3226 * Adds the specified class to each of the set of matched elements.
3228 * @example $("p").addClass("selected")
3229 * @before <p>Hello</p>
3230 * @result [ <p class="selected">Hello</p> ]
3232 * @test var div = $("div");
3233 * div.addClass("test");
3235 * for ( var i = 0; i < div.size(); i++ ) {
3236 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3238 * ok( pass, "Add Class" );
3242 * @param String class A CSS class to add to the elements
3245 addClass: function(c){
3246 jQuery.className.add(this,c);
3250 * Removes the specified class from the set of matched elements.
3252 * @example $("p").removeClass("selected")
3253 * @before <p class="selected">Hello</p>
3254 * @result [ <p>Hello</p> ]
3256 * @test var div = $("div").addClass("test");
3257 * div.removeClass("test");
3259 * for ( var i = 0; i < div.size(); i++ ) {
3260 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3262 * ok( pass, "Remove Class" );
3266 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3267 * div.removeClass("test").removeClass("bar").removeClass("foo");
3269 * for ( var i = 0; i < div.size(); i++ ) {
3270 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3272 * ok( pass, "Remove multiple classes" );
3276 * @param String class A CSS class to remove from the elements
3279 removeClass: function(c){
3280 jQuery.className.remove(this,c);
3284 * Adds the specified class if it is present, removes it if it is
3287 * @example $("p").toggleClass("selected")
3288 * @before <p>Hello</p><p class="selected">Hello Again</p>
3289 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3293 * @param String class A CSS class with which to toggle the elements
3296 toggleClass: function( c ){
3297 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3301 * Removes all matched elements from the DOM. This does NOT remove them from the
3302 * jQuery object, allowing you to use the matched elements further.
3304 * @example $("p").remove();
3305 * @before <p>Hello</p> how are <p>you?</p>
3310 * @cat DOM/Manipulation
3314 * Removes only elements (out of the list of matched elements) that match
3315 * the specified jQuery expression. This does NOT remove them from the
3316 * jQuery object, allowing you to use the matched elements further.
3318 * @example $("p").remove(".hello");
3319 * @before <p class="hello">Hello</p> how are <p>you?</p>
3320 * @result how are <p>you?</p>
3324 * @param String expr A jQuery expression to filter elements by.
3325 * @cat DOM/Manipulation
3327 remove: function(a){
3328 if ( !a || jQuery.filter( a, [this] ).r )
3329 this.parentNode.removeChild( this );
3333 * Removes all child nodes from the set of matched elements.
3335 * @example $("p").empty()
3336 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3337 * @result [ <p></p> ]
3341 * @cat DOM/Manipulation
3344 while ( this.firstChild )
3345 this.removeChild( this.firstChild );
3349 * Binds a handler to a particular event (like click) for each matched element.
3350 * The event handler is passed an event object that you can use to prevent
3351 * default behaviour. To stop both default action and event bubbling, your handler
3352 * has to return false.
3354 * @example $("p").bind( "click", function() {
3355 * alert( $(this).text() );
3357 * @before <p>Hello</p>
3358 * @result alert("Hello")
3360 * @example $("form").bind( "submit", function() { return false; } )
3361 * @desc Cancel a default action and prevent it from bubbling by returning false
3362 * from your function.
3364 * @example $("form").bind( "submit", function(event) {
3365 * event.preventDefault();
3367 * @desc Cancel only the default action by using the preventDefault method.
3370 * @example $("form").bind( "submit", function(event) {
3371 * event.stopPropagation();
3373 * @desc Stop only an event from bubbling by using the stopPropagation method.
3377 * @param String type An event type
3378 * @param Function fn A function to bind to the event on each of the set of matched elements
3381 bind: function( type, fn ) {
3382 if ( fn.constructor == String )
3383 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3384 jQuery.event.add( this, type, fn );
3388 * The opposite of bind, removes a bound event from each of the matched
3389 * elements. You must pass the identical function that was used in the original
3392 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3393 * @before <p onclick="alert('Hello');">Hello</p>
3394 * @result [ <p>Hello</p> ]
3398 * @param String type An event type
3399 * @param Function fn A function to unbind from the event on each of the set of matched elements
3404 * Removes all bound events of a particular type from each of the matched
3407 * @example $("p").unbind( "click" )
3408 * @before <p onclick="alert('Hello');">Hello</p>
3409 * @result [ <p>Hello</p> ]
3413 * @param String type An event type
3418 * Removes all bound events from each of the matched elements.
3420 * @example $("p").unbind()
3421 * @before <p onclick="alert('Hello');">Hello</p>
3422 * @result [ <p>Hello</p> ]
3428 unbind: function( type, fn ) {
3429 jQuery.event.remove( this, type, fn );
3433 * Trigger a type of event on every matched element.
3435 * @example $("p").trigger("click")
3436 * @before <p click="alert('hello')">Hello</p>
3437 * @result alert('hello')
3441 * @param String type An event type to trigger.
3444 trigger: function( type, data ) {
3445 jQuery.event.trigger( type, data, this );