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' );
672 * @param String html A string of HTML, that will be created on the fly and appended to the target.
673 * @cat DOM/Manipulation
677 * Append an element to the inside of all matched elements.
678 * This operation is similar to doing an appendChild to all the
679 * specified elements, adding them into the document.
681 * @example $("p").append( $("#foo")[0] );
682 * @before <p>I would like to say: </p><b id="foo">Hello</b>
683 * @result <p>I would like to say: <b id="foo">Hello</b></p>
685 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
686 * $('#sap').append(document.getElementById('first'));
687 * ok( expected == $('#sap').text(), "Check for appending of element" );
691 * @param Element elem A DOM element that will be appended.
692 * @cat DOM/Manipulation
696 * Append any number of elements to the inside of all matched elements.
697 * This operation is similar to doing an appendChild to all the
698 * specified elements, adding them into the document.
700 * @example $("p").append( $("b") );
701 * @before <p>I would like to say: </p><b>Hello</b>
702 * @result <p>I would like to say: <b>Hello</b></p>
704 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
705 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
706 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
710 * @param Array<Element> elems An array of elements, all of which will be appended.
711 * @cat DOM/Manipulation
714 return this.domManip(arguments, true, 1, function(a){
715 this.appendChild( a );
720 * Prepend any number of elements to the inside of every matched elements,
721 * generated from the provided HTML.
722 * This operation is the best way to insert dynamically created elements
723 * inside, at the beginning, of all the matched element.
725 * @example $("p").prepend("<b>Hello</b>");
726 * @before <p>I would like to say: </p>
727 * @result <p><b>Hello</b>I would like to say: </p>
729 * @test var defaultText = 'Try them out:'
730 * var result = $('#first').prepend('<b>buga</b>');
731 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
735 * @param String html A string of HTML, that will be created on the fly and appended to the target.
736 * @cat DOM/Manipulation
740 * Prepend an element to the inside of all matched elements.
741 * This operation is the best way to insert an element inside, at the
742 * beginning, of all the matched element.
744 * @example $("p").prepend( $("#foo")[0] );
745 * @before <p>I would like to say: </p><b id="foo">Hello</b>
746 * @result <p><b id="foo">Hello</b>I would like to say: </p>
748 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
749 * $('#sap').prepend(document.getElementById('first'));
750 * ok( expected == $('#sap').text(), "Check for prepending of element" );
754 * @param Element elem A DOM element that will be appended.
755 * @cat DOM/Manipulation
759 * Prepend any number of elements to the inside of all matched elements.
760 * This operation is the best way to insert a set of elements inside, at the
761 * beginning, of all the matched element.
763 * @example $("p").prepend( $("b") );
764 * @before <p>I would like to say: </p><b>Hello</b>
765 * @result <p><b>Hello</b>I would like to say: </p>
767 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
768 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
769 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
773 * @param Array<Element> elems An array of elements, all of which will be appended.
774 * @cat DOM/Manipulation
776 prepend: function() {
777 return this.domManip(arguments, true, -1, function(a){
778 this.insertBefore( a, this.firstChild );
783 * Insert any number of dynamically generated elements before each of the
786 * @example $("p").before("<b>Hello</b>");
787 * @before <p>I would like to say: </p>
788 * @result <b>Hello</b><p>I would like to say: </p>
790 * @test var expected = 'This is a normal link: bugaYahoo';
791 * $('#yahoo').before('<b>buga</b>');
792 * ok( expected == $('#en').text(), 'Insert String before' );
796 * @param String html A string of HTML, that will be created on the fly and appended to the target.
797 * @cat DOM/Manipulation
801 * Insert an element before each of the matched elements.
803 * @example $("p").before( $("#foo")[0] );
804 * @before <p>I would like to say: </p><b id="foo">Hello</b>
805 * @result <b id="foo">Hello</b><p>I would like to say: </p>
807 * @test var expected = "This is a normal link: Try them out:Yahoo";
808 * $('#yahoo').before(document.getElementById('first'));
809 * ok( expected == $('#en').text(), "Insert element before" );
813 * @param Element elem A DOM element that will be appended.
814 * @cat DOM/Manipulation
818 * Insert any number of elements before each of the matched elements.
820 * @example $("p").before( $("b") );
821 * @before <p>I would like to say: </p><b>Hello</b>
822 * @result <b>Hello</b><p>I would like to say: </p>
824 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
825 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
826 * ok( expected == $('#en').text(), "Insert array of elements before" );
830 * @param Array<Element> elems An array of elements, all of which will be appended.
831 * @cat DOM/Manipulation
834 return this.domManip(arguments, false, 1, function(a){
835 this.parentNode.insertBefore( a, this );
840 * Insert any number of dynamically generated elements after each of the
843 * @example $("p").after("<b>Hello</b>");
844 * @before <p>I would like to say: </p>
845 * @result <p>I would like to say: </p><b>Hello</b>
847 * @test var expected = 'This is a normal link: Yahoobuga';
848 * $('#yahoo').after('<b>buga</b>');
849 * ok( expected == $('#en').text(), 'Insert String after' );
853 * @param String html A string of HTML, that will be created on the fly and appended to the target.
854 * @cat DOM/Manipulation
858 * Insert an element after each of the matched elements.
860 * @example $("p").after( $("#foo")[0] );
861 * @before <b id="foo">Hello</b><p>I would like to say: </p>
862 * @result <p>I would like to say: </p><b id="foo">Hello</b>
864 * @test var expected = "This is a normal link: YahooTry them out:";
865 * $('#yahoo').after(document.getElementById('first'));
866 * ok( expected == $('#en').text(), "Insert element after" );
870 * @param Element elem A DOM element that will be appended.
871 * @cat DOM/Manipulation
875 * Insert any number of elements after each of the matched elements.
877 * @example $("p").after( $("b") );
878 * @before <b>Hello</b><p>I would like to say: </p>
879 * @result <p>I would like to say: </p><b>Hello</b>
881 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
882 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
883 * ok( expected == $('#en').text(), "Insert array of elements after" );
887 * @param Array<Element> elems An array of elements, all of which will be appended.
888 * @cat DOM/Manipulation
891 return this.domManip(arguments, false, -1, function(a){
892 this.parentNode.insertBefore( a, this.nextSibling );
897 * End the most recent 'destructive' operation, reverting the list of matched elements
898 * back to its previous state. After an end operation, the list of matched elements will
899 * revert to the last state of matched elements.
901 * @example $("p").find("span").end();
902 * @before <p><span>Hello</span>, how are you?</p>
903 * @result $("p").find("span").end() == [ <p>...</p> ]
905 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
909 * @cat DOM/Traversing
912 return this.get( this.stack.pop() );
916 * Searches for all elements that match the specified expression.
917 * This method is the optimal way of finding additional descendant
918 * elements with which to process.
920 * All searching is done using a jQuery expression. The expression can be
921 * written using CSS 1-3 Selector syntax, or basic XPath.
923 * @example $("p").find("span");
924 * @before <p><span>Hello</span>, how are you?</p>
925 * @result $("p").find("span") == [ <span>Hello</span> ]
927 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
931 * @param String expr An expression to search with.
932 * @cat DOM/Traversing
935 return this.pushStack( jQuery.map( this, function(a){
936 return jQuery.find(t,a);
941 * Create cloned copies of all matched DOM Elements. This does
942 * not create a cloned copy of this particular jQuery object,
943 * instead it creates duplicate copies of all DOM Elements.
944 * This is useful for moving copies of the elements to another
945 * location in the DOM.
947 * @example $("b").clone().prependTo("p");
948 * @before <b>Hello</b><p>, how are you?</p>
949 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
951 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
952 * var clone = $('#yahoo').clone();
953 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
954 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
958 * @cat DOM/Manipulation
960 clone: function(deep) {
961 return this.pushStack( jQuery.map( this, function(a){
962 return a.cloneNode( deep != undefined ? deep : true );
967 * Removes all elements from the set of matched elements that do not
968 * match the specified expression. This method is used to narrow down
969 * the results of a search.
971 * All searching is done using a jQuery expression. The expression
972 * can be written using CSS 1-3 Selector syntax, or basic XPath.
974 * @example $("p").filter(".selected")
975 * @before <p class="selected">Hello</p><p>How are you?</p>
976 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
978 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
982 * @param String expr An expression to search with.
983 * @cat DOM/Traversing
987 * Removes all elements from the set of matched elements that do not
988 * match at least one of the expressions passed to the function. This
989 * method is used when you want to filter the set of matched elements
990 * through more than one expression.
992 * Elements will be retained in the jQuery object if they match at
993 * least one of the expressions passed.
995 * @example $("p").filter([".selected", ":first"])
996 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
997 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
1001 * @param Array<String> exprs A set of expressions to evaluate against
1002 * @cat DOM/Traversing
1004 filter: function(t) {
1005 return this.pushStack(
1006 t.constructor == Array &&
1007 jQuery.map(this,function(a){
1008 for ( var i = 0; i < t.length; i++ )
1009 if ( jQuery.filter(t[i],[a]).r.length )
1013 t.constructor == Boolean &&
1014 ( t ? this.get() : [] ) ||
1016 typeof t == "function" &&
1017 jQuery.grep( this, t ) ||
1019 jQuery.filter(t,this).r, arguments );
1023 * Removes the specified Element from the set of matched elements. This
1024 * method is used to remove a single Element from a jQuery object.
1026 * @example $("p").not( document.getElementById("selected") )
1027 * @before <p>Hello</p><p id="selected">Hello Again</p>
1028 * @result [ <p>Hello</p> ]
1032 * @param Element el An element to remove from the set
1033 * @cat DOM/Traversing
1037 * Removes elements matching the specified expression from the set
1038 * of matched elements. This method is used to remove one or more
1039 * elements from a jQuery object.
1041 * @example $("p").not("#selected")
1042 * @before <p>Hello</p><p id="selected">Hello Again</p>
1043 * @result [ <p>Hello</p> ]
1045 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
1049 * @param String expr An expression with which to remove matching elements
1050 * @cat DOM/Traversing
1053 return this.pushStack( t.constructor == String ?
1054 jQuery.filter(t,this,false).r :
1055 jQuery.grep(this,function(a){ return a != t; }), arguments );
1059 * Adds the elements matched by the expression to the jQuery object. This
1060 * can be used to concatenate the result sets of two expressions.
1062 * @example $("p").add("span")
1063 * @before <p>Hello</p><p><span>Hello Again</span></p>
1064 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1068 * @param String expr An expression whose matched elements are added
1069 * @cat DOM/Traversing
1073 * Adds each of the Elements in the array to the set of matched elements.
1074 * This is used to add a set of Elements to a jQuery object.
1076 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1077 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1078 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1082 * @param Array<Element> els An array of Elements to add
1083 * @cat DOM/Traversing
1087 * Adds a single Element to the set of matched elements. This is used to
1088 * add a single Element to a jQuery object.
1090 * @example $("p").add( document.getElementById("a") )
1091 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1092 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1096 * @param Element el An Element to add
1097 * @cat DOM/Traversing
1100 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1101 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1105 * Checks the current selection against an expression and returns true,
1106 * if the selection fits the given expression. Does return false, if the
1107 * selection does not fit or the expression is not valid.
1109 * @example $("input[@type='checkbox']").parent().is("form")
1110 * @before <form><input type="checkbox" /></form>
1112 * @desc Returns true, because the parent of the input is a form element
1114 * @example $("input[@type='checkbox']").parent().is("form")
1115 * @before <form><p><input type="checkbox" /></p></form>
1117 * @desc Returns false, because the parent of the input is a p element
1119 * @example $("form").is(null)
1120 * @before <form></form>
1122 * @desc An invalid expression always returns false.
1124 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1125 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1126 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1127 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1128 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1129 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1130 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1131 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1132 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1133 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1134 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1135 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1136 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1137 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1138 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1139 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1140 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1141 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1142 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1143 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1144 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1145 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1149 * @param String expr The expression with which to filter
1150 * @cat DOM/Traversing
1152 is: function(expr) {
1153 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1157 * Executes the first callback for every element that fits the expression
1158 * and executes the second callback for every element that does not fit
1161 * @example $('div').ifelse(':visible',
1162 * function() { $(this).slideUp(); },
1163 function() { $(this).slideDown(); }
1165 * @desc Slides down all visible div elements and slides down all others
1167 * @test var checked = 0, notChecked = 0;
1168 * var inputChecked = $(':input').ifelse(':checked',
1169 * function() { checked++; },
1170 * function() { notChecked++ }
1172 * ok( checked == 2, 'Check is if/else: Count checked elements' );
1173 * ok( notChecked == 12, 'Check is if/else: Count unchecked elements' );
1175 * $('#first, #foo, #ap').ifelse('p',
1176 * function() { $(this).html('me == p') },
1177 * function() { $(this).html('me != p') }
1179 * ok( $('#first').text() == 'me == p', 'Check filter-if-clause' );
1180 * ok( $('#foo').text() == 'me != p', 'Check else-clause' );
1181 * ok( $('#ap').text() == 'me == p', 'Check filter-if-clause' );
1185 * @param String expression The expression with which to filter
1186 * @param Function ifCallback Called for elements that fit the expression
1187 * @param Function elseCallback Called for elements that don't fit the expression
1188 * @cat DOM/Traversing
1190 ifelse: function(expr, ifCallback, elseCallback) {
1191 var ifCallback = ifCallback || function() {};
1192 var elseCalllback = elseCallback || function() {};
1193 return this.each(function() {
1194 if($(this).is(expr)) {
1195 ifCallback.apply(this);
1197 elseCallback.apply(this);
1208 * @param Boolean table
1210 * @param Function fn The function doing the DOM manipulation.
1214 domManip: function(args, table, dir, fn){
1215 var clone = this.size() > 1;
1216 var a = jQuery.clean(args);
1218 return this.each(function(){
1221 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
1222 var tbody = this.getElementsByTagName("tbody");
1224 if ( !tbody.length ) {
1225 obj = document.createElement("tbody");
1226 this.appendChild( obj );
1231 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1232 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1233 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1248 pushStack: function(a,args) {
1249 var fn = args && args[args.length-1];
1251 if ( !fn || fn.constructor != Function ) {
1252 if ( !this.stack ) this.stack = [];
1253 this.stack.push( this.get() );
1256 var old = this.get();
1258 if ( typeof fn == "function" )
1268 * Extends the jQuery object itself. Can be used to add both static
1269 * functions and plugin methods.
1271 * @example $.fn.extend({
1272 * check: function() {
1273 * this.each(function() { this.checked = true; });
1275 * uncheck: function() {
1276 * this.each(function() { this.checked = false; });
1279 * $("input[@type=checkbox]").check();
1280 * $("input[@type=radio]").uncheck();
1281 * @desc Adds two plugin methods.
1291 * Extend one object with another, returning the original,
1292 * modified, object. This is a great utility for simple inheritance.
1294 * @example var settings = { validate: false, limit: 5, name: "foo" };
1295 * var options = { validate: true, name: "bar" };
1296 * jQuery.extend(settings, options);
1297 * @result settings == { validate: true, limit: 5, name: "bar" }
1299 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1300 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1301 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1302 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1303 * jQuery.extend(settings, options);
1304 * isSet( settings, merged, "Check if extended: settings must be extended" );
1305 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1308 * @param Object obj The object to extend
1309 * @param Object prop The object that will be merged into the first.
1313 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1314 if ( !prop ) { prop = obj; obj = this; }
1315 for ( var i in prop ) obj[i] = prop[i];
1327 jQuery.initDone = true;
1329 jQuery.each( jQuery.macros.axis, function(i,n){
1330 jQuery.fn[ i ] = function(a) {
1331 var ret = jQuery.map(this,n);
1332 if ( a && a.constructor == String )
1333 ret = jQuery.filter(a,ret).r;
1334 return this.pushStack( ret, arguments );
1338 jQuery.each( jQuery.macros.to, function(i,n){
1339 jQuery.fn[ i ] = function(){
1341 return this.each(function(){
1342 for ( var j = 0; j < a.length; j++ )
1343 jQuery(a[j])[n]( this );
1348 jQuery.each( jQuery.macros.each, function(i,n){
1349 jQuery.fn[ i ] = function() {
1350 return this.each( n, arguments );
1354 jQuery.each( jQuery.macros.filter, function(i,n){
1355 jQuery.fn[ n ] = function(num,fn) {
1356 return this.filter( ":" + n + "(" + num + ")", fn );
1360 jQuery.each( jQuery.macros.attr, function(i,n){
1362 jQuery.fn[ i ] = function(h) {
1363 return h == undefined ?
1364 this.length ? this[0][n] : null :
1369 jQuery.each( jQuery.macros.css, function(i,n){
1370 jQuery.fn[ n ] = function(h) {
1371 return h == undefined ?
1372 ( this.length ? jQuery.css( this[0], n ) : null ) :
1380 * A generic iterator function, which can be used to seemlessly
1381 * iterate over both objects and arrays. This function is not the same
1382 * as $().each() - which is used to iterate, exclusively, over a jQuery
1383 * object. This function can be used to iterate over anything.
1385 * @example $.each( [0,1,2], function(i){
1386 * alert( "Item #" + i + ": " + this );
1388 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1390 * @example $.each( { name: "John", lang: "JS" }, function(i){
1391 * alert( "Name: " + i + ", Value: " + this );
1393 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1396 * @param Object obj The object, or array, to iterate over.
1397 * @param Function fn The function that will be executed on every object.
1401 each: function( obj, fn, args ) {
1402 if ( obj.length == undefined )
1403 for ( var i in obj )
1404 fn.apply( obj[i], args || [i, obj[i]] );
1406 for ( var i = 0; i < obj.length; i++ )
1407 fn.apply( obj[i], args || [i, obj[i]] );
1413 if (jQuery.className.has(o,c)) return;
1414 o.className += ( o.className ? " " : "" ) + c;
1416 remove: function(o,c){
1418 o.className = !c ? "" :
1419 o.className.replace(
1420 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/
1424 var classes = o.className.split(" ");
1425 for(var i=0; i<classes.length; i++) {
1426 if(classes[i] == c) {
1427 classes.splice(i, 1);
1431 o.className = classes.join(' ');
1434 has: function(e,a) {
1435 if ( e.className != undefined )
1437 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1442 * Swap in/out style options.
1445 swap: function(e,o,f) {
1446 for ( var i in o ) {
1447 e.style["old"+i] = e.style[i];
1452 e.style[i] = e.style["old"+i];
1455 css: function(e,p) {
1456 if ( p == "height" || p == "width" ) {
1457 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1459 for ( var i in d ) {
1460 old["padding" + d[i]] = 0;
1461 old["border" + d[i] + "Width"] = 0;
1464 jQuery.swap( e, old, function() {
1465 if (jQuery.css(e,"display") != "none") {
1466 oHeight = e.offsetHeight;
1467 oWidth = e.offsetWidth;
1469 e = jQuery(e.cloneNode(true)).css({
1470 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1471 }).appendTo(e.parentNode)[0];
1473 var parPos = jQuery.css(e.parentNode,"position");
1474 if ( parPos == "" || parPos == "static" )
1475 e.parentNode.style.position = "relative";
1477 oHeight = e.clientHeight;
1478 oWidth = e.clientWidth;
1480 if ( parPos == "" || parPos == "static" )
1481 e.parentNode.style.position = "static";
1483 e.parentNode.removeChild(e);
1487 return p == "height" ? oHeight : oWidth;
1488 } else if ( p == "opacity" && jQuery.browser.msie )
1489 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1491 return jQuery.curCSS( e, p );
1494 curCSS: function(elem, prop, force) {
1497 if (!force && elem.style[prop]) {
1499 ret = elem.style[prop];
1501 } else if (elem.currentStyle) {
1503 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1504 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1506 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1508 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1509 var cur = document.defaultView.getComputedStyle(elem, null);
1512 ret = cur.getPropertyValue(prop);
1513 else if ( prop == 'display' )
1516 jQuery.swap(elem, { display: 'block' }, function() {
1517 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1525 clean: function(a) {
1527 for ( var i = 0; i < a.length; i++ ) {
1528 if ( a[i].constructor == String ) {
1532 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1534 a[i] = "<table>" + a[i] + "</table>";
1535 } else if ( !a[i].indexOf("<tr") ) {
1537 a[i] = "<table>" + a[i] + "</table>";
1538 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1540 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1543 var div = document.createElement("div");
1544 div.innerHTML = a[i];
1547 div = div.firstChild;
1548 if ( table != "thead" ) div = div.firstChild;
1549 if ( table == "td" ) div = div.firstChild;
1552 for ( var j = 0; j < div.childNodes.length; j++ )
1553 r.push( div.childNodes[j] );
1554 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1555 for ( var k = 0; k < a[i].length; k++ )
1557 else if ( a[i] !== null )
1558 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1564 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1565 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1573 last: "i==r.length-1",
1578 "nth-child": "jQuery.sibling(a,m[3]).cur",
1579 "first-child": "jQuery.sibling(a,0).cur",
1580 "last-child": "jQuery.sibling(a,0).last",
1581 "only-child": "jQuery.sibling(a).length==1",
1584 parent: "a.childNodes.length",
1585 empty: "!a.childNodes.length",
1588 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1591 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1592 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1595 enabled: "!a.disabled",
1596 disabled: "a.disabled",
1597 checked: "a.checked",
1598 selected: "a.selected",
1601 text: "a.type=='text'",
1602 radio: "a.type=='radio'",
1603 checkbox: "a.type=='checkbox'",
1604 file: "a.type=='file'",
1605 password: "a.type=='password'",
1606 submit: "a.type=='submit'",
1607 image: "a.type=='image'",
1608 reset: "a.type=='reset'",
1609 button: "a.type=='button'",
1610 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
1612 ".": "jQuery.className.has(a,m[2])",
1616 "^=": "z && !z.indexOf(m[4])",
1617 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1618 "*=": "z && z.indexOf(m[4])>=0",
1621 "[": "jQuery.find(m[2],a).length"
1625 "\\.\\.|/\\.\\.", "a.parentNode",
1626 ">|/", "jQuery.sibling(a.firstChild)",
1627 "\\+", "jQuery.sibling(a).next",
1630 var s = jQuery.sibling(a);
1632 for ( var i = s.n; i < s.length; i++ )
1640 * @test t( "Element Selector", "div", ["main","foo"] );
1641 * t( "Element Selector", "body", ["body"] );
1642 * t( "Element Selector", "html", ["html"] );
1643 * ok( $("*").size() >= 30, "Element Selector" );
1644 * t( "Parent Element", "div div", ["foo"] );
1646 * t( "ID Selector", "#body", ["body"] );
1647 * t( "ID Selector w/ Element", "body#body", ["body"] );
1648 * t( "ID Selector w/ Element", "ul#first", [] );
1650 * t( "Class Selector", ".blog", ["mark","simon"] );
1651 * t( "Class Selector", ".blog.link", ["simon"] );
1652 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1653 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1655 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1656 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1657 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1658 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1660 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1661 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1662 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1663 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1664 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1665 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1666 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1667 * t( "Adjacent", "a + a", ["groups"] );
1668 * t( "Adjacent", "a +a", ["groups"] );
1669 * t( "Adjacent", "a+ a", ["groups"] );
1670 * t( "Adjacent", "a+a", ["groups"] );
1671 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1672 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1673 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1674 * t( "Attribute Exists", "a[@title]", ["google"] );
1675 * t( "Attribute Exists", "*[@title]", ["google"] );
1676 * t( "Attribute Exists", "[@title]", ["google"] );
1678 * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] );
1679 * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
1680 * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] );
1682 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1683 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1684 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1685 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1686 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1687 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1689 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1690 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1691 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1692 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1693 * t( "Last Child", "p:last-child", ["sap"] );
1694 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1695 * t( "Empty", "ul:empty", ["firstUL"] );
1696 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1697 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1698 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1699 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1700 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1701 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1702 * t( "Element Preceded By", "p ~ div", ["foo"] );
1703 * t( "Not", "a.blog:not(.link)", ["mark"] );
1705 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1706 * t( "All Div Elements", "//div", ["main","foo"] );
1707 * t( "Absolute Path", "/html/body", ["body"] );
1708 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1709 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1710 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1711 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1712 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1713 * t( "Attribute Exists", "//a[@title]", ["google"] );
1714 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1715 * t( "Parent Axis", "//p/..", ["main","foo"] );
1716 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1717 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1718 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1720 * t( "nth Element", "p:nth(1)", ["ap"] );
1721 * t( "First Element", "p:first", ["firstp"] );
1722 * t( "Last Element", "p:last", ["first"] );
1723 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1724 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1725 * t( "Position Equals", "p:eq(1)", ["ap"] );
1726 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1727 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1728 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1729 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1730 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1732 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1734 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1735 * t( "All Children of ID with no children", "#firstUL/*", [] );
1737 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1738 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1739 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1740 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1741 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1742 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1743 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1745 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1746 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1747 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1750 * @type Array<Element>
1754 find: function( t, context ) {
1755 // Make sure that the context is a DOM Element
1756 if ( context && context.nodeType == undefined )
1759 // Set the correct context (if none is provided)
1760 context = context || jQuery.context || document;
1762 if ( t.constructor != String ) return [t];
1764 if ( !t.indexOf("//") ) {
1765 context = context.documentElement;
1766 t = t.substr(2,t.length);
1767 } else if ( !t.indexOf("/") ) {
1768 context = context.documentElement;
1769 t = t.substr(1,t.length);
1770 // FIX Assume the root element is right :(
1771 if ( t.indexOf("/") >= 1 )
1772 t = t.substr(t.indexOf("/"),t.length);
1775 var ret = [context];
1779 while ( t.length > 0 && last != t ) {
1783 t = jQuery.trim(t).replace( /^\/\//i, "" );
1785 var foundToken = false;
1787 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1788 if ( foundToken ) continue;
1790 var re = new RegExp("^(" + jQuery.token[i] + ")");
1794 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1795 t = jQuery.trim( t.replace( re, "" ) );
1800 if ( !foundToken ) {
1801 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1802 if ( ret[0] == context ) ret.shift();
1803 done = jQuery.merge( done, ret );
1804 r = ret = [context];
1805 t = " " + t.substr(1,t.length);
1807 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1808 var m = re2.exec(t);
1810 if ( m[1] == "#" ) {
1811 // Ummm, should make this work in all XML docs
1812 var oid = document.getElementById(m[2]);
1813 r = ret = oid ? [oid] : [];
1814 t = t.replace( re2, "" );
1816 if ( !m[2] || m[1] == "." ) m[2] = "*";
1818 for ( var i = 0; i < ret.length; i++ )
1819 r = jQuery.merge( r,
1821 jQuery.getAll(ret[i]) :
1822 ret[i].getElementsByTagName(m[2])
1830 var val = jQuery.filter(t,r);
1832 t = jQuery.trim(val.t);
1836 if ( ret && ret[0] == context ) ret.shift();
1837 done = jQuery.merge( done, ret );
1842 getAll: function(o,r) {
1844 var s = o.childNodes;
1845 for ( var i = 0; i < s.length; i++ )
1846 if ( s[i].nodeType == 1 ) {
1848 jQuery.getAll( s[i], r );
1853 attr: function(elem, name, value){
1856 "class": "className",
1857 "float": "cssFloat",
1858 innerHTML: "innerHTML",
1859 className: "className",
1861 disabled: "disabled",
1866 if ( value != undefined ) elem[fix[name]] = value;
1867 return elem[fix[name]];
1868 } else if( value == undefined && $.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1869 return elem.getAttributeNode(name).nodeValue;
1870 } else if ( elem.getAttribute != undefined ) {
1871 if ( value != undefined ) elem.setAttribute( name, value );
1872 return elem.getAttribute( name, 2 );
1874 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1875 if ( value != undefined ) elem[name] = value;
1880 // The regular expressions that power the parsing engine
1882 // Match: [@value='test'], [@foo]
1883 "\\[ *(@)S *([!*$^=]*)Q\\]",
1885 // Match: [div], [div p]
1888 // Match: :contains('foo')
1891 // Match: :even, :last-chlid
1895 filter: function(t,r,not) {
1896 // Figure out if we're doing regular, or inverse, filtering
1897 var g = not !== false ? jQuery.grep :
1898 function(a,f) {return jQuery.grep(a,f,true);};
1900 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1902 var p = jQuery.parse;
1904 for ( var i = 0; i < p.length; i++ ) {
1905 // get number for backreference
1907 if(p[i].indexOf('Q') != -1){
1908 br = p[i].replace(/\\\(/g,'').match(/\(|S/g).length+1;
1910 var re = new RegExp( "^" + p[i]
1912 // Look for a string-like sequence
1913 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1915 // Look for something (optionally) enclosed with quotes
1916 .replace( 'Q', " *('|\"|)([^'\"]*?)\\"+br+" *" ), "i" );
1918 var m = re.exec( t );
1921 // Re-organize the match
1923 m = ["",m[1], m[3], m[2], m[5]];
1924 } else if(br != 0) {
1927 // Remove what we just matched
1928 t = t.replace( re, "" );
1934 // :not() is a special case that can be optimized by
1935 // keeping it out of the expression list
1936 if ( m[1] == ":" && m[2] == "not" )
1937 r = jQuery.filter(m[3],r,false).r;
1939 // Otherwise, find the expression to execute
1941 var f = jQuery.expr[m[1]];
1942 if ( f.constructor != String )
1943 f = jQuery.expr[m[1]][m[2]];
1945 // Build a custom macro to enclose it
1946 eval("f = function(a,i){" +
1947 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1948 "return " + f + "}");
1950 // Execute it against the current filter
1955 // Return an array of filtered elements (r)
1956 // and the modified expression string (t)
1957 return { r: r, t: t };
1961 * Remove the whitespace from the beginning and end of a string.
1963 * @example $.trim(" hello, how are you? ");
1964 * @result "hello, how are you?"
1968 * @param String str The string to trim.
1972 return t.replace(/^\s+|\s+$/g, "");
1976 * All ancestors of a given element.
1980 * @type Array<Element>
1981 * @param Element elem The element to find the ancestors of.
1982 * @cat DOM/Traversing
1984 parents: function( elem ){
1986 var cur = elem.parentNode;
1987 while ( cur && cur != document ) {
1988 matched.push( cur );
1989 cur = cur.parentNode;
1995 * All elements on a specified axis.
2000 * @param Element elem The element to find all the siblings of (including itself).
2001 * @cat DOM/Traversing
2003 sibling: function(elem, pos, not) {
2007 var siblings = elem.parentNode.childNodes;
2008 for ( var i = 0; i < siblings.length; i++ ) {
2009 if ( not === true && siblings[i] == elem ) continue;
2011 if ( siblings[i].nodeType == 1 )
2012 elems.push( siblings[i] );
2013 if ( siblings[i] == elem )
2014 elems.n = elems.length - 1;
2018 return jQuery.extend( elems, {
2019 last: elems.n == elems.length - 1,
2020 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
2021 prev: elems[elems.n - 1],
2022 next: elems[elems.n + 1]
2027 * Merge two arrays together, removing all duplicates. The final order
2028 * or the new array is: All the results from the first array, followed
2029 * by the unique results from the second array.
2031 * @example $.merge( [0,1,2], [2,3,4] )
2032 * @result [0,1,2,3,4]
2034 * @example $.merge( [3,2,1], [4,3,2] )
2039 * @param Array first The first array to merge.
2040 * @param Array second The second array to merge.
2043 merge: function(first, second) {
2046 // Move b over to the new array (this helps to avoid
2047 // StaticNodeList instances)
2048 for ( var k = 0; k < first.length; k++ )
2049 result[k] = first[k];
2051 // Now check for duplicates between a and b and only
2052 // add the unique items
2053 for ( var i = 0; i < second.length; i++ ) {
2054 var noCollision = true;
2056 // The collision-checking process
2057 for ( var j = 0; j < first.length; j++ )
2058 if ( second[i] == first[j] )
2059 noCollision = false;
2061 // If the item is unique, add it
2063 result.push( second[i] );
2070 * Filter items out of an array, by using a filter function.
2071 * The specified function will be passed two arguments: The
2072 * current array item and the index of the item in the array. The
2073 * function should return 'true' if you wish to keep the item in
2074 * the array, false if it should be removed.
2076 * @example $.grep( [0,1,2], function(i){
2083 * @param Array array The Array to find items in.
2084 * @param Function fn The function to process each item against.
2085 * @param Boolean inv Invert the selection - select the opposite of the function.
2088 grep: function(elems, fn, inv) {
2089 // If a string is passed in for the function, make a function
2090 // for it (a handy shortcut)
2091 if ( fn.constructor == String )
2092 fn = new Function("a","i","return " + fn);
2096 // Go through the array, only saving the items
2097 // that pass the validator function
2098 for ( var i = 0; i < elems.length; i++ )
2099 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2100 result.push( elems[i] );
2106 * Translate all items in an array to another array of items.
2107 * The translation function that is provided to this method is
2108 * called for each item in the array and is passed one argument:
2109 * The item to be translated. The function can then return:
2110 * The translated value, 'null' (to remove the item), or
2111 * an array of values - which will be flattened into the full array.
2113 * @example $.map( [0,1,2], function(i){
2118 * @example $.map( [0,1,2], function(i){
2119 * return i > 0 ? i + 1 : null;
2123 * @example $.map( [0,1,2], function(i){
2124 * return [ i, i + 1 ];
2126 * @result [0, 1, 1, 2, 2, 3]
2130 * @param Array array The Array to translate.
2131 * @param Function fn The function to process each item against.
2134 map: function(elems, fn) {
2135 // If a string is passed in for the function, make a function
2136 // for it (a handy shortcut)
2137 if ( fn.constructor == String )
2138 fn = new Function("a","return " + fn);
2142 // Go through the array, translating each of the items to their
2143 // new value (or values).
2144 for ( var i = 0; i < elems.length; i++ ) {
2145 var val = fn(elems[i],i);
2147 if ( val !== null && val != undefined ) {
2148 if ( val.constructor != Array ) val = [val];
2149 result = jQuery.merge( result, val );
2157 * A number of helper functions used for managing events.
2158 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2162 // Bind an event to an element
2163 // Original by Dean Edwards
2164 add: function(element, type, handler) {
2165 // For whatever reason, IE has trouble passing the window object
2166 // around, causing it to be cloned in the process
2167 if ( jQuery.browser.msie && element.setInterval != undefined )
2170 // Make sure that the function being executed has a unique ID
2171 if ( !handler.guid )
2172 handler.guid = this.guid++;
2174 // Init the element's event structure
2175 if (!element.events)
2176 element.events = {};
2178 // Get the current list of functions bound to this event
2179 var handlers = element.events[type];
2181 // If it hasn't been initialized yet
2183 // Init the event handler queue
2184 handlers = element.events[type] = {};
2186 // Remember an existing handler, if it's already there
2187 if (element["on" + type])
2188 handlers[0] = element["on" + type];
2191 // Add the function to the element's handler list
2192 handlers[handler.guid] = handler;
2194 // And bind the global event handler to the element
2195 element["on" + type] = this.handle;
2197 // Remember the function in a global list (for triggering)
2198 if (!this.global[type])
2199 this.global[type] = [];
2200 this.global[type].push( element );
2206 // Detach an event or set of events from an element
2207 remove: function(element, type, handler) {
2209 if (type && element.events[type])
2211 delete element.events[type][handler.guid];
2213 for ( var i in element.events[type] )
2214 delete element.events[type][i];
2216 for ( var j in element.events )
2217 this.remove( element, j );
2220 trigger: function(type,data,element) {
2221 // Touch up the incoming data
2224 // Handle a global trigger
2226 var g = this.global[type];
2228 for ( var i = 0; i < g.length; i++ )
2229 this.trigger( type, data, g[i] );
2231 // Handle triggering a single element
2232 } else if ( element["on" + type] ) {
2233 // Pass along a fake event
2234 data.unshift( this.fix({ type: type, target: element }) );
2236 // Trigger the event
2237 element["on" + type].apply( element, data );
2241 handle: function(event) {
2242 if ( typeof jQuery == "undefined" ) return;
2244 event = event || jQuery.event.fix( window.event );
2246 // If no correct event was found, fail
2247 if ( !event ) return;
2249 var returnValue = true;
2251 var c = this.events[event.type];
2253 var args = [].slice.call( arguments, 1 );
2254 args.unshift( event );
2256 for ( var j in c ) {
2257 if ( c[j].apply( this, args ) === false ) {
2258 event.preventDefault();
2259 event.stopPropagation();
2260 returnValue = false;
2267 fix: function(event) {
2269 event.preventDefault = function() {
2270 this.returnValue = false;
2273 event.stopPropagation = function() {
2274 this.cancelBubble = true;
2285 * Contains flags for the useragent, read from navigator.userAgent.
2286 * Available flags are: safari, opera, msie, mozilla
2287 * This property is available before the DOM is ready, therefore you can
2288 * use it to add ready events only for certain browsers.
2290 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2291 * jQBrowser plugin</a> for advanced browser detection:
2293 * @example $.browser.msie
2294 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2296 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2297 * @desc Alerts "this is safari!" only for safari browsers
2304 var b = navigator.userAgent.toLowerCase();
2306 // Figure out what browser is being used
2308 safari: /webkit/.test(b),
2309 opera: /opera/.test(b),
2310 msie: /msie/.test(b) && !/opera/.test(b),
2311 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2314 // Check to see if the W3C box model is being used
2315 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2321 * Append all of the matched elements to another, specified, set of elements.
2322 * This operation is, essentially, the reverse of doing a regular
2323 * $(A).append(B), in that instead of appending B to A, you're appending
2326 * @example $("p").appendTo("#foo");
2327 * @before <p>I would like to say: </p><div id="foo"></div>
2328 * @result <div id="foo"><p>I would like to say: </p></div>
2332 * @param String expr A jQuery expression of elements to match.
2333 * @cat DOM/Manipulation
2338 * Prepend all of the matched elements to another, specified, set of elements.
2339 * This operation is, essentially, the reverse of doing a regular
2340 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2343 * @example $("p").prependTo("#foo");
2344 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2345 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2349 * @param String expr A jQuery expression of elements to match.
2350 * @cat DOM/Manipulation
2352 prependTo: "prepend",
2355 * Insert all of the matched elements before another, specified, set of elements.
2356 * This operation is, essentially, the reverse of doing a regular
2357 * $(A).before(B), in that instead of inserting B before A, you're inserting
2360 * @example $("p").insertBefore("#foo");
2361 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2362 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2364 * @name insertBefore
2366 * @param String expr A jQuery expression of elements to match.
2367 * @cat DOM/Manipulation
2369 insertBefore: "before",
2372 * Insert all of the matched elements after another, specified, set of elements.
2373 * This operation is, essentially, the reverse of doing a regular
2374 * $(A).after(B), in that instead of inserting B after A, you're inserting
2377 * @example $("p").insertAfter("#foo");
2378 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2379 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2383 * @param String expr A jQuery expression of elements to match.
2384 * @cat DOM/Manipulation
2386 insertAfter: "after"
2390 * Get the current CSS width of the first matched element.
2392 * @example $("p").width();
2393 * @before <p>This is just a test.</p>
2402 * Set the CSS width of every matched element. Be sure to include
2403 * the "px" (or other unit of measurement) after the number that you
2404 * specify, otherwise you might get strange results.
2406 * @example $("p").width("20px");
2407 * @before <p>This is just a test.</p>
2408 * @result <p style="width:20px;">This is just a test.</p>
2412 * @param String val Set the CSS property to the specified value.
2417 * Get the current CSS height of the first matched element.
2419 * @example $("p").height();
2420 * @before <p>This is just a test.</p>
2429 * Set the CSS height of every matched element. Be sure to include
2430 * the "px" (or other unit of measurement) after the number that you
2431 * specify, otherwise you might get strange results.
2433 * @example $("p").height("20px");
2434 * @before <p>This is just a test.</p>
2435 * @result <p style="height:20px;">This is just a test.</p>
2439 * @param String val Set the CSS property to the specified value.
2444 * Get the current CSS top of the first matched element.
2446 * @example $("p").top();
2447 * @before <p>This is just a test.</p>
2456 * Set the CSS top of every matched element. Be sure to include
2457 * the "px" (or other unit of measurement) after the number that you
2458 * specify, otherwise you might get strange results.
2460 * @example $("p").top("20px");
2461 * @before <p>This is just a test.</p>
2462 * @result <p style="top:20px;">This is just a test.</p>
2466 * @param String val Set the CSS property to the specified value.
2471 * Get the current CSS left of the first matched element.
2473 * @example $("p").left();
2474 * @before <p>This is just a test.</p>
2483 * Set the CSS left of every matched element. Be sure to include
2484 * the "px" (or other unit of measurement) after the number that you
2485 * specify, otherwise you might get strange results.
2487 * @example $("p").left("20px");
2488 * @before <p>This is just a test.</p>
2489 * @result <p style="left:20px;">This is just a test.</p>
2493 * @param String val Set the CSS property to the specified value.
2498 * Get the current CSS position of the first matched element.
2500 * @example $("p").position();
2501 * @before <p>This is just a test.</p>
2510 * Set the CSS position of every matched element.
2512 * @example $("p").position("relative");
2513 * @before <p>This is just a test.</p>
2514 * @result <p style="position:relative;">This is just a test.</p>
2518 * @param String val Set the CSS property to the specified value.
2523 * Get the current CSS float of the first matched element.
2525 * @example $("p").float();
2526 * @before <p>This is just a test.</p>
2535 * Set the CSS float of every matched element.
2537 * @example $("p").float("left");
2538 * @before <p>This is just a test.</p>
2539 * @result <p style="float:left;">This is just a test.</p>
2543 * @param String val Set the CSS property to the specified value.
2548 * Get the current CSS overflow of the first matched element.
2550 * @example $("p").overflow();
2551 * @before <p>This is just a test.</p>
2560 * Set the CSS overflow of every matched element.
2562 * @example $("p").overflow("auto");
2563 * @before <p>This is just a test.</p>
2564 * @result <p style="overflow:auto;">This is just a test.</p>
2568 * @param String val Set the CSS property to the specified value.
2573 * Get the current CSS color of the first matched element.
2575 * @example $("p").color();
2576 * @before <p>This is just a test.</p>
2585 * Set the CSS color of every matched element.
2587 * @example $("p").color("blue");
2588 * @before <p>This is just a test.</p>
2589 * @result <p style="color:blue;">This is just a test.</p>
2593 * @param String val Set the CSS property to the specified value.
2598 * Get the current CSS background of the first matched element.
2600 * @example $("p").background();
2601 * @before <p style="background:blue;">This is just a test.</p>
2610 * Set the CSS background of every matched element.
2612 * @example $("p").background("blue");
2613 * @before <p>This is just a test.</p>
2614 * @result <p style="background:blue;">This is just a test.</p>
2618 * @param String val Set the CSS property to the specified value.
2622 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2625 * Reduce the set of matched elements to a single element.
2626 * The position of the element in the set of matched elements
2627 * starts at 0 and goes to length - 1.
2629 * @example $("p").eq(1)
2630 * @before <p>This is just a test.</p><p>So is this</p>
2631 * @result [ <p>So is this</p> ]
2635 * @param Number pos The index of the element that you wish to limit to.
2640 * Reduce the set of matched elements to all elements before a given position.
2641 * The position of the element in the set of matched elements
2642 * starts at 0 and goes to length - 1.
2644 * @example $("p").lt(1)
2645 * @before <p>This is just a test.</p><p>So is this</p>
2646 * @result [ <p>This is just a test.</p> ]
2650 * @param Number pos Reduce the set to all elements below this position.
2655 * Reduce the set of matched elements to all elements after a given position.
2656 * The position of the element in the set of matched elements
2657 * starts at 0 and goes to length - 1.
2659 * @example $("p").gt(0)
2660 * @before <p>This is just a test.</p><p>So is this</p>
2661 * @result [ <p>So is this</p> ]
2665 * @param Number pos Reduce the set to all elements after this position.
2670 * Filter the set of elements to those that contain the specified text.
2672 * @example $("p").contains("test")
2673 * @before <p>This is just a test.</p><p>So is this</p>
2674 * @result [ <p>This is just a test.</p> ]
2678 * @param String str The string that will be contained within the text of an element.
2679 * @cat DOM/Traversing
2682 filter: [ "eq", "lt", "gt", "contains" ],
2686 * Get the current value of the first matched element.
2688 * @example $("input").val();
2689 * @before <input type="text" value="some text"/>
2690 * @result "some text"
2692 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2693 * ok( !$("#text1").val() == "", "Check for value of input element" );
2697 * @cat DOM/Attributes
2701 * Set the value of every matched element.
2703 * @example $("input").value("test");
2704 * @before <input type="text" value="some text"/>
2705 * @result <input type="text" value="test"/>
2707 * @test document.getElementById('text1').value = "bla";
2708 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2709 * $("#text1").val('test');
2710 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2714 * @param String val Set the property to the specified value.
2715 * @cat DOM/Attributes
2720 * Get the html contents of the first matched element.
2722 * @example $("div").html();
2723 * @before <div><input/></div>
2728 * @cat DOM/Attributes
2732 * Set the html contents of every matched element.
2734 * @example $("div").html("<b>new stuff</b>");
2735 * @before <div><input/></div>
2736 * @result <div><b>new stuff</b></div>
2738 * @test var div = $("div");
2739 * div.html("<b>test</b>");
2741 * for ( var i = 0; i < div.size(); i++ ) {
2742 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2744 * ok( pass, "Set HTML" );
2748 * @param String val Set the html contents to the specified value.
2749 * @cat DOM/Attributes
2754 * Get the current id of the first matched element.
2756 * @example $("input").id();
2757 * @before <input type="text" id="test" value="some text"/>
2760 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2761 * ok( $("#foo").id() == "foo", "Check for id" );
2762 * ok( !$("head").id(), "Check for id" );
2766 * @cat DOM/Attributes
2770 * Set the id of every matched element.
2772 * @example $("input").id("newid");
2773 * @before <input type="text" id="test" value="some text"/>
2774 * @result <input type="text" id="newid" value="some text"/>
2778 * @param String val Set the property to the specified value.
2779 * @cat DOM/Attributes
2784 * Get the current title of the first matched element.
2786 * @example $("img").title();
2787 * @before <img src="test.jpg" title="my image"/>
2788 * @result "my image"
2790 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2791 * ok( !$("#yahoo").title(), "Check for title" );
2795 * @cat DOM/Attributes
2799 * Set the title of every matched element.
2801 * @example $("img").title("new title");
2802 * @before <img src="test.jpg" title="my image"/>
2803 * @result <img src="test.jpg" title="new image"/>
2807 * @param String val Set the property to the specified value.
2808 * @cat DOM/Attributes
2813 * Get the current name of the first matched element.
2815 * @example $("input").name();
2816 * @before <input type="text" name="username"/>
2817 * @result "username"
2819 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2820 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2821 * ok( !$("#area1").name(), "Check for name" );
2825 * @cat DOM/Attributes
2829 * Set the name of every matched element.
2831 * @example $("input").name("user");
2832 * @before <input type="text" name="username"/>
2833 * @result <input type="text" name="user"/>
2837 * @param String val Set the property to the specified value.
2838 * @cat DOM/Attributes
2843 * Get the current href of the first matched element.
2845 * @example $("a").href();
2846 * @before <a href="test.html">my link</a>
2847 * @result "test.html"
2851 * @cat DOM/Attributes
2855 * Set the href of every matched element.
2857 * @example $("a").href("test2.html");
2858 * @before <a href="test.html">my link</a>
2859 * @result <a href="test2.html">my link</a>
2863 * @param String val Set the property to the specified value.
2864 * @cat DOM/Attributes
2869 * Get the current src of the first matched element.
2871 * @example $("img").src();
2872 * @before <img src="test.jpg" title="my image"/>
2873 * @result "test.jpg"
2877 * @cat DOM/Attributes
2881 * Set the src of every matched element.
2883 * @example $("img").src("test2.jpg");
2884 * @before <img src="test.jpg" title="my image"/>
2885 * @result <img src="test2.jpg" title="my image"/>
2889 * @param String val Set the property to the specified value.
2890 * @cat DOM/Attributes
2895 * Get the current rel of the first matched element.
2897 * @example $("a").rel();
2898 * @before <a href="test.html" rel="nofollow">my link</a>
2899 * @result "nofollow"
2903 * @cat DOM/Attributes
2907 * Set the rel of every matched element.
2909 * @example $("a").rel("nofollow");
2910 * @before <a href="test.html">my link</a>
2911 * @result <a href="test.html" rel="nofollow">my link</a>
2915 * @param String val Set the property to the specified value.
2916 * @cat DOM/Attributes
2923 * Get a set of elements containing the unique parents of the matched
2926 * @example $("p").parent()
2927 * @before <div><p>Hello</p><p>Hello</p></div>
2928 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2932 * @cat DOM/Traversing
2936 * Get a set of elements containing the unique parents of the matched
2937 * set of elements, and filtered by an expression.
2939 * @example $("p").parent(".selected")
2940 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2941 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2945 * @param String expr An expression to filter the parents with
2946 * @cat DOM/Traversing
2948 parent: "a.parentNode",
2951 * Get a set of elements containing the unique ancestors of the matched
2952 * set of elements (except for the root element).
2954 * @example $("span").ancestors()
2955 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2956 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2960 * @cat DOM/Traversing
2964 * Get a set of elements containing the unique ancestors of the matched
2965 * set of elements, and filtered by an expression.
2967 * @example $("span").ancestors("p")
2968 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2969 * @result [ <p><span>Hello</span></p> ]
2973 * @param String expr An expression to filter the ancestors with
2974 * @cat DOM/Traversing
2976 ancestors: jQuery.parents,
2979 * Get a set of elements containing the unique ancestors of the matched
2980 * set of elements (except for the root element).
2982 * @example $("span").ancestors()
2983 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2984 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2988 * @cat DOM/Traversing
2992 * Get a set of elements containing the unique ancestors of the matched
2993 * set of elements, and filtered by an expression.
2995 * @example $("span").ancestors("p")
2996 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2997 * @result [ <p><span>Hello</span></p> ]
3001 * @param String expr An expression to filter the ancestors with
3002 * @cat DOM/Traversing
3004 parents: jQuery.parents,
3007 * Get a set of elements containing the unique next siblings of each of the
3008 * matched set of elements.
3010 * It only returns the very next sibling, not all next siblings.
3012 * @example $("p").next()
3013 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
3014 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
3018 * @cat DOM/Traversing
3022 * Get a set of elements containing the unique next siblings of each of the
3023 * matched set of elements, and filtered by an expression.
3025 * It only returns the very next sibling, not all next siblings.
3027 * @example $("p").next(".selected")
3028 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
3029 * @result [ <p class="selected">Hello Again</p> ]
3033 * @param String expr An expression to filter the next Elements with
3034 * @cat DOM/Traversing
3036 next: "jQuery.sibling(a).next",
3039 * Get a set of elements containing the unique previous siblings of each of the
3040 * matched set of elements.
3042 * It only returns the immediately previous sibling, not all previous siblings.
3044 * @example $("p").prev()
3045 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3046 * @result [ <div><span>Hello Again</span></div> ]
3050 * @cat DOM/Traversing
3054 * Get a set of elements containing the unique previous siblings of each of the
3055 * matched set of elements, and filtered by an expression.
3057 * It only returns the immediately previous sibling, not all previous siblings.
3059 * @example $("p").previous(".selected")
3060 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3061 * @result [ <div><span>Hello</span></div> ]
3065 * @param String expr An expression to filter the previous Elements with
3066 * @cat DOM/Traversing
3068 prev: "jQuery.sibling(a).prev",
3071 * Get a set of elements containing all of the unique siblings of each of the
3072 * matched set of elements.
3074 * @example $("div").siblings()
3075 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3076 * @result [ <p>Hello</p>, <p>And Again</p> ]
3078 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3082 * @cat DOM/Traversing
3086 * Get a set of elements containing all of the unique siblings of each of the
3087 * matched set of elements, and filtered by an expression.
3089 * @example $("div").siblings(".selected")
3090 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3091 * @result [ <p class="selected">Hello Again</p> ]
3093 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3094 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3098 * @param String expr An expression to filter the sibling Elements with
3099 * @cat DOM/Traversing
3101 siblings: "jQuery.sibling(a, null, true)",
3105 * Get a set of elements containing all of the unique children of each of the
3106 * matched set of elements.
3108 * @example $("div").children()
3109 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3110 * @result [ <span>Hello Again</span> ]
3112 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3116 * @cat DOM/Traversing
3120 * Get a set of elements containing all of the unique children of each of the
3121 * matched set of elements, and filtered by an expression.
3123 * @example $("div").children(".selected")
3124 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3125 * @result [ <p class="selected">Hello Again</p> ]
3127 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3131 * @param String expr An expression to filter the child Elements with
3132 * @cat DOM/Traversing
3134 children: "jQuery.sibling(a.firstChild)"
3140 * Remove an attribute from each of the matched elements.
3142 * @example $("input").removeAttr("disabled")
3143 * @before <input disabled="disabled"/>
3148 * @param String name The name of the attribute to remove.
3151 removeAttr: function( key ) {
3152 this.removeAttribute( key );
3156 * Displays each of the set of matched elements if they are hidden.
3158 * @example $("p").show()
3159 * @before <p style="display: none">Hello</p>
3160 * @result [ <p style="display: block">Hello</p> ]
3162 * @test var pass = true, div = $("div");
3163 * div.show().each(function(){
3164 * if ( this.style.display == "none" ) pass = false;
3166 * ok( pass, "Show" );
3173 this.style.display = this.oldblock ? this.oldblock : "";
3174 if ( jQuery.css(this,"display") == "none" )
3175 this.style.display = "block";
3179 * Hides each of the set of matched elements if they are shown.
3181 * @example $("p").hide()
3182 * @before <p>Hello</p>
3183 * @result [ <p style="display: none">Hello</p> ]
3185 * var pass = true, div = $("div");
3186 * div.hide().each(function(){
3187 * if ( this.style.display != "none" ) pass = false;
3189 * ok( pass, "Hide" );
3196 this.oldblock = this.oldblock || jQuery.css(this,"display");
3197 if ( this.oldblock == "none" )
3198 this.oldblock = "block";
3199 this.style.display = "none";
3203 * Toggles each of the set of matched elements. If they are shown,
3204 * toggle makes them hidden. If they are hidden, toggle
3207 * @example $("p").toggle()
3208 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3209 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3216 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3220 * Adds the specified class to each of the set of matched elements.
3222 * @example $("p").addClass("selected")
3223 * @before <p>Hello</p>
3224 * @result [ <p class="selected">Hello</p> ]
3226 * @test var div = $("div");
3227 * div.addClass("test");
3229 * for ( var i = 0; i < div.size(); i++ ) {
3230 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3232 * ok( pass, "Add Class" );
3236 * @param String class A CSS class to add to the elements
3239 addClass: function(c){
3240 jQuery.className.add(this,c);
3244 * Removes the specified class from the set of matched elements.
3246 * @example $("p").removeClass("selected")
3247 * @before <p class="selected">Hello</p>
3248 * @result [ <p>Hello</p> ]
3250 * @test var div = $("div").addClass("test");
3251 * div.removeClass("test");
3253 * for ( var i = 0; i < div.size(); i++ ) {
3254 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3256 * ok( pass, "Remove Class" );
3260 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3261 * div.removeClass("test").removeClass("bar").removeClass("foo");
3263 * for ( var i = 0; i < div.size(); i++ ) {
3264 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3266 * ok( pass, "Remove multiple classes" );
3270 * @param String class A CSS class to remove from the elements
3273 removeClass: function(c){
3274 jQuery.className.remove(this,c);
3278 * Adds the specified class if it is present, removes it if it is
3281 * @example $("p").toggleClass("selected")
3282 * @before <p>Hello</p><p class="selected">Hello Again</p>
3283 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3287 * @param String class A CSS class with which to toggle the elements
3290 toggleClass: function( c ){
3291 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3295 * Removes all matched elements from the DOM. This does NOT remove them from the
3296 * jQuery object, allowing you to use the matched elements further.
3298 * @example $("p").remove();
3299 * @before <p>Hello</p> how are <p>you?</p>
3304 * @cat DOM/Manipulation
3308 * Removes only elements (out of the list of matched elements) that match
3309 * the specified jQuery expression. This does NOT remove them from the
3310 * jQuery object, allowing you to use the matched elements further.
3312 * @example $("p").remove(".hello");
3313 * @before <p class="hello">Hello</p> how are <p>you?</p>
3314 * @result how are <p>you?</p>
3318 * @param String expr A jQuery expression to filter elements by.
3319 * @cat DOM/Manipulation
3321 remove: function(a){
3322 if ( !a || jQuery.filter( a, [this] ).r )
3323 this.parentNode.removeChild( this );
3327 * Removes all child nodes from the set of matched elements.
3329 * @example $("p").empty()
3330 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3331 * @result [ <p></p> ]
3335 * @cat DOM/Manipulation
3338 while ( this.firstChild )
3339 this.removeChild( this.firstChild );
3343 * Binds a handler to a particular event (like click) for each matched element.
3344 * The event handler is passed an event object that you can use to prevent
3345 * default behaviour. To stop both default action and event bubbling, your handler
3346 * has to return false.
3348 * @example $("p").bind( "click", function() {
3349 * alert( $(this).text() );
3351 * @before <p>Hello</p>
3352 * @result alert("Hello")
3354 * @example $("form").bind( "submit", function() { return false; } )
3355 * @desc Cancel a default action and prevent it from bubbling by returning false
3356 * from your function.
3358 * @example $("form").bind( "submit", function(event) {
3359 * event.preventDefault();
3361 * @desc Cancel only the default action by using the preventDefault method.
3364 * @example $("form").bind( "submit", function(event) {
3365 * event.stopPropagation();
3367 * @desc Stop only an event from bubbling by using the stopPropagation method.
3371 * @param String type An event type
3372 * @param Function fn A function to bind to the event on each of the set of matched elements
3375 bind: function( type, fn ) {
3376 if ( fn.constructor == String )
3377 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3378 jQuery.event.add( this, type, fn );
3382 * The opposite of bind, removes a bound event from each of the matched
3383 * elements. You must pass the identical function that was used in the original
3386 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3387 * @before <p onclick="alert('Hello');">Hello</p>
3388 * @result [ <p>Hello</p> ]
3392 * @param String type An event type
3393 * @param Function fn A function to unbind from the event on each of the set of matched elements
3398 * Removes all bound events of a particular type from each of the matched
3401 * @example $("p").unbind( "click" )
3402 * @before <p onclick="alert('Hello');">Hello</p>
3403 * @result [ <p>Hello</p> ]
3407 * @param String type An event type
3412 * Removes all bound events from each of the matched elements.
3414 * @example $("p").unbind()
3415 * @before <p onclick="alert('Hello');">Hello</p>
3416 * @result [ <p>Hello</p> ]
3422 unbind: function( type, fn ) {
3423 jQuery.event.remove( this, type, fn );
3427 * Trigger a type of event on every matched element.
3429 * @example $("p").trigger("click")
3430 * @before <p click="alert('hello')">Hello</p>
3431 * @result alert('hello')
3435 * @param String type An event type to trigger.
3438 trigger: function( type, data ) {
3439 jQuery.event.trigger( type, data, this );