2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * ok( Function.prototype.apply, "Function.apply()" );
20 * ok( document.getElementById, "getElementById" );
21 * ok( document.getElementsByTagName, "getElementsByTagName" );
22 * ok( RegExp, "RegExp" );
23 * ok( jQuery, "jQuery" );
31 function jQuery(a,c) {
33 // Shortcut for document ready (because $(document).each() is silly)
34 if ( a && typeof a == "function" && jQuery.fn.ready )
35 return jQuery(document).ready(a);
37 // Make sure that a selection was provided
38 a = a || jQuery.context || document;
40 // Watch for when a jQuery object is passed as the selector
42 return jQuery( jQuery.merge( a, [] ) );
44 // Watch for when a jQuery object is passed at the context
46 return jQuery( c ).find(a);
48 // If the context is global, return a new object
50 return new jQuery(a,c);
52 // Handle HTML strings
53 if ( a.constructor == String ) {
54 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
55 if ( m ) a = jQuery.clean( [ m[1] ] );
58 // Watch for when an array is passed in
59 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
60 // Assume that it is an array of DOM Elements
61 jQuery.merge( a, [] ) :
63 // Find the matching elements and save them for later
64 jQuery.find( a, c ) );
66 // See if an extra function was provided
67 var fn = arguments[ arguments.length - 1 ];
69 // If so, execute it in context
70 if ( fn && typeof fn == "function" )
76 // Map over the $ in case of overwrite
77 if ( typeof $ != "undefined" )
81 * This function accepts a string containing a CSS selector,
82 * basic XPath, or raw HTML, which is then used to match a set of elements.
83 * The HTML string is different from the traditional selectors in that
84 * it creates the DOM elements representing that HTML string, on the fly,
85 * to be (assumedly) inserted into the document later.
87 * The core functionality of jQuery centers around this function.
88 * Everything in jQuery is based upon this, or uses this in some way.
89 * The most basic use of this function is to pass in an expression
90 * (usually consisting of CSS or XPath), which then finds all matching
91 * elements and remembers them for later use.
93 * By default, $() looks for DOM elements within the context of the
94 * current HTML document.
96 * @example $("div > p")
97 * @desc This finds all p elements that are children of a div element.
98 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
99 * @result [ <p>two</p> ]
101 * @example $("<div><p>Hello</p></div>").appendTo("#body")
102 * @desc Creates a div element (and all of its contents) dynamically,
103 * and appends it to the element with the ID of body. Internally, an
104 * element is created and it's innerHTML property set to the given markup.
105 * It is therefore both quite flexible and limited.
108 * @param String expr An expression to search with, or a string of HTML to create on the fly.
114 * This function accepts a string containing a CSS selector, or
115 * basic XPath, which is then used to match a set of elements with the
116 * context of the specified DOM element, or document
118 * @example $("div", xml.responseXML)
119 * @desc This finds all div elements within the specified XML document.
122 * @param String expr An expression to search with.
123 * @param Element context A DOM Element, or Document, representing the base context.
129 * Wrap jQuery functionality around a specific DOM Element.
130 * This function also accepts XML Documents and Window objects
131 * as valid arguments (even though they are not DOM Elements).
133 * @example $(document).find("div > p")
134 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
135 * @result [ <p>two</p> ]
137 * @example $(document.body).background( "black" );
138 * @desc Sets the background color of the page to black.
141 * @param Element elem A DOM element to be encapsulated by a jQuery object.
147 * Wrap jQuery functionality around a set of DOM Elements.
149 * @example $( myForm.elements ).hide()
150 * @desc Hides all the input elements within a form
153 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
159 * A shorthand for $(document).ready(), allowing you to bind a function
160 * to be executed when the DOM document has finished loading. This function
161 * behaves just like $(document).ready(), in that it should be used to wrap
162 * all of the other $() operations on your page. While this function is,
163 * technically, chainable - there really isn't much use for chaining against it.
164 * You can have as many $(document).ready events on your page as you like.
166 * @example $(function(){
167 * // Document is ready
169 * @desc Executes the function when the DOM is ready to be used.
172 * @param Function fn The function to execute when the DOM is ready.
178 * A means of creating a cloned copy of a jQuery object. This function
179 * copies the set of matched elements from one jQuery object and creates
180 * another, new, jQuery object containing the same elements.
182 * @example var div = $("div");
183 * $( div ).find("p");
184 * @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).
187 * @param jQuery obj The jQuery object to be cloned.
192 // Map the jQuery namespace to the '$' one
195 jQuery.fn = jQuery.prototype = {
197 * The current version of jQuery.
208 * The number of elements currently matched.
210 * @example $("img").length;
211 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
214 * @test ok( $("div").length == 2, "Get Number of Elements Found" );
223 * The number of elements currently matched.
225 * @example $("img").size();
226 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
229 * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
240 * Access all matched elements. This serves as a backwards-compatible
241 * way of accessing all matched elements (other than the jQuery object
242 * itself, which is, in fact, an array of elements).
244 * @example $("img").get();
245 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
246 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
248 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
251 * @type Array<Element>
256 * Access a single matched element. num is used to access the
257 * Nth element matched.
259 * @example $("img").get(1);
260 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
261 * @result [ <img src="test1.jpg"/> ]
263 * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
267 * @param Number num Access the element in the Nth position.
272 * Set the jQuery object to an array of elements.
274 * @example $("img").get([ document.body ]);
275 * @result $("img").get() == [ document.body ]
280 * @param Elements elems An array of elements
283 get: function( num ) {
284 // Watch for when an array (of elements) is passed in
285 if ( num && num.constructor == Array ) {
287 // Use a tricky hack to make the jQuery object
288 // look and feel like an array
290 [].push.apply( this, num );
294 return num == undefined ?
296 // Return a 'clean' array
297 jQuery.merge( this, [] ) :
299 // Return just the object
304 * Execute a function within the context of every matched element.
305 * This means that every time the passed-in function is executed
306 * (which is once for every element matched) the 'this' keyword
307 * points to the specific element.
309 * Additionally, the function, when executed, is passed a single
310 * argument representing the position of the element in the matched
313 * @example $("img").each(function(){
314 * this.src = "test.jpg";
316 * @before <img/> <img/>
317 * @result <img src="test.jpg"/> <img src="test.jpg"/>
319 * @example $("img").each(function(i){
320 * alert( "Image #" + i + " is " + this );
322 * @before <img/> <img/>
323 * @result <img src="test.jpg"/> <img src="test.jpg"/>
325 * @test var div = $("div");
326 * div.each(function(){this.foo = 'zoo';});
328 * for ( var i = 0; i < div.size(); i++ ) {
329 * if ( div.get(i).foo != "zoo" ) pass = false;
331 * ok( pass, "Execute a function, Relative" );
335 * @param Function fn A function to execute
338 each: function( fn, args ) {
339 return jQuery.each( this, fn, args );
343 * Searches every matched element for the object and returns
344 * the index of the element, if found, starting with zero.
345 * Returns -1 if the object wasn't found.
347 * @example $("*").index(document.getElementById('foobar'))
348 * @before <div id="foobar"></div><b></b><span id="foo"></span>
351 * @example $("*").index(document.getElementById('foo'))
352 * @before <div id="foobar"></div><b></b><span id="foo"></span>
355 * @example $("*").index(document.getElementById('bar'))
356 * @before <div id="foobar"></div><b></b><span id="foo"></span>
359 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
360 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
361 * var inputElements = $('#radio1,#radio2,#check1,#check2');
362 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
363 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
364 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
365 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
366 * ok( inputElements.index(window) == -1, "Check for not found index" );
367 * ok( inputElements.index(document) == -1, "Check for not found index" );
371 * @param Object obj Object to search for
374 index: function( obj ) {
376 this.each(function(i){
377 if ( this == obj ) pos = i;
383 * Access a property on the first matched element.
384 * This method makes it easy to retrieve a property value
385 * from the first matched element.
387 * @example $("img").attr("src");
388 * @before <img src="test.jpg"/>
391 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
392 * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
393 * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
394 * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
395 * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
396 * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
397 * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
398 * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
399 * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
400 * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
401 * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
402 * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
406 * @param String name The name of the property to access.
411 * Set a hash of key/value object properties to all matched elements.
412 * This serves as the best way to set a large number of properties
413 * on all matched elements.
415 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
417 * @result <img src="test.jpg" alt="Test Image"/>
419 * @test var pass = true;
420 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
421 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
423 * ok( pass, "Set Multiple Attributes" );
427 * @param Hash prop A set of key/value pairs to set as object properties.
432 * Set a single property to a value, on all matched elements.
434 * @example $("img").attr("src","test.jpg");
436 * @result <img src="test.jpg"/>
438 * @test var div = $("div");
439 * div.attr("foo", "bar");
441 * for ( var i = 0; i < div.size(); i++ ) {
442 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
444 * ok( pass, "Set Attribute" );
446 * $("#name").attr('name', 'something');
447 * ok( $("#name").name() == 'something', 'Set name attribute' );
448 * $("#check2").attr('checked', true);
449 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
450 * $("#check2").attr('checked', false);
451 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
454 * $.get('data/dashboard.xml', function(xml) {
456 * $('tab', xml).each(function() {
457 * titles.push($(this).attr('title'));
459 * ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
460 * ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
466 * @param String key The name of the property to set.
467 * @param Object value The value to set the property to.
470 attr: function( key, value, type ) {
471 // Check to see if we're setting style values
472 return key.constructor != String || value != undefined ?
473 this.each(function(){
474 // See if we're setting a hash of styles
475 if ( value == undefined )
476 // Set all the styles
477 for ( var prop in key )
479 type ? this.style : this,
483 // See if we're setting a single key/value style
486 type ? this.style : this,
491 // Look for the case where we're accessing a style value
492 jQuery[ type || "attr" ]( this[0], key );
496 * Access a style property on the first matched element.
497 * This method makes it easy to retrieve a style property value
498 * from the first matched element.
500 * @example $("p").css("color");
501 * @before <p style="color:red;">Test Paragraph.</p>
503 * @desc Retrieves the color style of the first paragraph
505 * @example $("p").css("fontWeight");
506 * @before <p style="font-weight: bold;">Test Paragraph.</p>
508 * @desc Retrieves the font-weight style of the first paragraph.
509 * Note that for all style properties with a dash (like 'font-weight'), you have to
510 * write it in camelCase. In other words: Every time you have a '-' in a
511 * property, remove it and replace the next character with an uppercase
512 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
513 * borderStyle, borderBottomWidth etc.
515 * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
519 * @param String name The name of the property to access.
524 * Set a hash of key/value style properties to all matched elements.
525 * This serves as the best way to set a large number of style properties
526 * on all matched elements.
528 * @example $("p").css({ color: "red", background: "blue" });
529 * @before <p>Test Paragraph.</p>
530 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
532 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
533 * $('#foo').css({display: 'none'});
534 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
535 * $('#foo').css({display: 'block'});
536 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
540 * @param Hash prop A set of key/value pairs to set as style properties.
545 * Set a single style property to a value, on all matched elements.
547 * @example $("p").css("color","red");
548 * @before <p>Test Paragraph.</p>
549 * @result <p style="color:red;">Test Paragraph.</p>
550 * @desc Changes the color of all paragraphs to red
553 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
554 * $('#foo').css('display', 'none');
555 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
556 * $('#foo').css('display', 'block');
557 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
561 * @param String key The name of the property to set.
562 * @param Object value The value to set the property to.
565 css: function( key, value ) {
566 return this.attr( key, value, "curCSS" );
570 * Retrieve the text contents of all matched elements. The result is
571 * a string that contains the combined text contents of all matched
572 * elements. This method works on both HTML and XML documents.
574 * @example $("p").text();
575 * @before <p>Test Paragraph.</p>
576 * @result Test Paragraph.
578 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
579 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
588 for ( var j = 0; j < e.length; j++ ) {
589 var r = e[j].childNodes;
590 for ( var i = 0; i < r.length; i++ )
591 if ( r[i].nodeType != 8 )
592 t += r[i].nodeType != 1 ?
593 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
599 * Wrap all matched elements with a structure of other elements.
600 * This wrapping process is most useful for injecting additional
601 * stucture into a document, without ruining the original semantic
602 * qualities of a document.
604 * This works by going through the first element
605 * provided (which is generated, on the fly, from the provided HTML)
606 * and finds the deepest ancestor element within its
607 * structure - it is that element that will en-wrap everything else.
609 * This does not work with elements that contain text. Any necessary text
610 * must be added after the wrapping is done.
612 * @example $("p").wrap("<div class='wrap'></div>");
613 * @before <p>Test Paragraph.</p>
614 * @result <div class='wrap'><p>Test Paragraph.</p></div>
616 * @test var defaultText = 'Try them out:'
617 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
618 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
619 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
623 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
624 * @cat DOM/Manipulation
628 * Wrap all matched elements with a structure of other elements.
629 * This wrapping process is most useful for injecting additional
630 * stucture into a document, without ruining the original semantic
631 * qualities of a document.
633 * This works by going through the first element
634 * provided and finding the deepest ancestor element within its
635 * structure - it is that element that will en-wrap everything else.
637 * This does not work with elements that contain text. Any necessary text
638 * must be added after the wrapping is done.
640 * @example $("p").wrap( document.getElementById('content') );
641 * @before <p>Test Paragraph.</p><div id="content"></div>
642 * @result <div id="content"><p>Test Paragraph.</p></div>
644 * @test var defaultText = 'Try them out:'
645 * var result = $('#first').wrap(document.getElementById('empty')).parent();
646 * ok( result.is('ol'), 'Check for element wrapping' );
647 * ok( result.text() == defaultText, 'Check for element wrapping' );
651 * @param Element elem A DOM element that will be wrapped.
652 * @cat DOM/Manipulation
655 // The elements to wrap the target around
656 var a = jQuery.clean(arguments);
658 // Wrap each of the matched elements individually
659 return this.each(function(){
660 // Clone the structure that we're using to wrap
661 var b = a[0].cloneNode(true);
663 // Insert it before the element to be wrapped
664 this.parentNode.insertBefore( b, this );
666 // Find the deepest point in the wrap structure
667 while ( b.firstChild )
670 // Move the matched element to within the wrap structure
671 b.appendChild( this );
676 * Append any number of elements to the inside of every matched elements,
677 * generated from the provided HTML.
678 * This operation is similar to doing an appendChild to all the
679 * specified elements, adding them into the document.
681 * @example $("p").append("<b>Hello</b>");
682 * @before <p>I would like to say: </p>
683 * @result <p>I would like to say: <b>Hello</b></p>
685 * @test var defaultText = 'Try them out:'
686 * var result = $('#first').append('<b>buga</b>');
687 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
691 * @param String html A string of HTML, that will be created on the fly and appended to the target.
692 * @cat DOM/Manipulation
696 * Append an element 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( $("#foo")[0] );
701 * @before <p>I would like to say: </p><b id="foo">Hello</b>
702 * @result <p>I would like to say: <b id="foo">Hello</b></p>
704 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
705 * $('#sap').append(document.getElementById('first'));
706 * ok( expected == $('#sap').text(), "Check for appending of element" );
710 * @param Element elem A DOM element that will be appended.
711 * @cat DOM/Manipulation
715 * Append any number of elements to the inside of all matched elements.
716 * This operation is similar to doing an appendChild to all the
717 * specified elements, adding them into the document.
719 * @example $("p").append( $("b") );
720 * @before <p>I would like to say: </p><b>Hello</b>
721 * @result <p>I would like to say: <b>Hello</b></p>
723 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
724 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
725 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
729 * @param Array<Element> elems An array of elements, all of which will be appended.
730 * @cat DOM/Manipulation
733 return this.domManip(arguments, true, 1, function(a){
734 this.appendChild( a );
739 * Prepend any number of elements to the inside of every matched elements,
740 * generated from the provided HTML.
741 * This operation is the best way to insert dynamically created elements
742 * inside, at the beginning, of all the matched element.
744 * @example $("p").prepend("<b>Hello</b>");
745 * @before <p>I would like to say: </p>
746 * @result <p><b>Hello</b>I would like to say: </p>
748 * @test var defaultText = 'Try them out:'
749 * var result = $('#first').prepend('<b>buga</b>');
750 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
754 * @param String html A string of HTML, that will be created on the fly and appended to the target.
755 * @cat DOM/Manipulation
759 * Prepend an element to the inside of all matched elements.
760 * This operation is the best way to insert an element inside, at the
761 * beginning, of all the matched element.
763 * @example $("p").prepend( $("#foo")[0] );
764 * @before <p>I would like to say: </p><b id="foo">Hello</b>
765 * @result <p><b id="foo">Hello</b>I would like to say: </p>
767 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
768 * $('#sap').prepend(document.getElementById('first'));
769 * ok( expected == $('#sap').text(), "Check for prepending of element" );
773 * @param Element elem A DOM element that will be appended.
774 * @cat DOM/Manipulation
778 * Prepend any number of elements to the inside of all matched elements.
779 * This operation is the best way to insert a set of elements inside, at the
780 * beginning, of all the matched element.
782 * @example $("p").prepend( $("b") );
783 * @before <p>I would like to say: </p><b>Hello</b>
784 * @result <p><b>Hello</b>I would like to say: </p>
786 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
787 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
788 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
792 * @param Array<Element> elems An array of elements, all of which will be appended.
793 * @cat DOM/Manipulation
795 prepend: function() {
796 return this.domManip(arguments, true, -1, function(a){
797 this.insertBefore( a, this.firstChild );
802 * Insert any number of dynamically generated elements before each of the
805 * @example $("p").before("<b>Hello</b>");
806 * @before <p>I would like to say: </p>
807 * @result <b>Hello</b><p>I would like to say: </p>
809 * @test var expected = 'This is a normal link: bugaYahoo';
810 * $('#yahoo').before('<b>buga</b>');
811 * ok( expected == $('#en').text(), 'Insert String before' );
815 * @param String html A string of HTML, that will be created on the fly and appended to the target.
816 * @cat DOM/Manipulation
820 * Insert an element before each of the matched elements.
822 * @example $("p").before( $("#foo")[0] );
823 * @before <p>I would like to say: </p><b id="foo">Hello</b>
824 * @result <b id="foo">Hello</b><p>I would like to say: </p>
826 * @test var expected = "This is a normal link: Try them out:Yahoo";
827 * $('#yahoo').before(document.getElementById('first'));
828 * ok( expected == $('#en').text(), "Insert element before" );
832 * @param Element elem A DOM element that will be appended.
833 * @cat DOM/Manipulation
837 * Insert any number of elements before each of the matched elements.
839 * @example $("p").before( $("b") );
840 * @before <p>I would like to say: </p><b>Hello</b>
841 * @result <b>Hello</b><p>I would like to say: </p>
843 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
844 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
845 * ok( expected == $('#en').text(), "Insert array of elements before" );
849 * @param Array<Element> elems An array of elements, all of which will be appended.
850 * @cat DOM/Manipulation
853 return this.domManip(arguments, false, 1, function(a){
854 this.parentNode.insertBefore( a, this );
859 * Insert any number of dynamically generated elements after each of the
862 * @example $("p").after("<b>Hello</b>");
863 * @before <p>I would like to say: </p>
864 * @result <p>I would like to say: </p><b>Hello</b>
866 * @test var expected = 'This is a normal link: Yahoobuga';
867 * $('#yahoo').after('<b>buga</b>');
868 * ok( expected == $('#en').text(), 'Insert String after' );
872 * @param String html A string of HTML, that will be created on the fly and appended to the target.
873 * @cat DOM/Manipulation
877 * Insert an element after each of the matched elements.
879 * @example $("p").after( $("#foo")[0] );
880 * @before <b id="foo">Hello</b><p>I would like to say: </p>
881 * @result <p>I would like to say: </p><b id="foo">Hello</b>
883 * @test var expected = "This is a normal link: YahooTry them out:";
884 * $('#yahoo').after(document.getElementById('first'));
885 * ok( expected == $('#en').text(), "Insert element after" );
889 * @param Element elem A DOM element that will be appended.
890 * @cat DOM/Manipulation
894 * Insert any number of elements after each of the matched elements.
896 * @example $("p").after( $("b") );
897 * @before <b>Hello</b><p>I would like to say: </p>
898 * @result <p>I would like to say: </p><b>Hello</b>
900 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
901 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
902 * ok( expected == $('#en').text(), "Insert array of elements after" );
906 * @param Array<Element> elems An array of elements, all of which will be appended.
907 * @cat DOM/Manipulation
910 return this.domManip(arguments, false, -1, function(a){
911 this.parentNode.insertBefore( a, this.nextSibling );
916 * End the most recent 'destructive' operation, reverting the list of matched elements
917 * back to its previous state. After an end operation, the list of matched elements will
918 * revert to the last state of matched elements.
920 * @example $("p").find("span").end();
921 * @before <p><span>Hello</span>, how are you?</p>
922 * @result $("p").find("span").end() == [ <p>...</p> ]
924 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
928 * @cat DOM/Traversing
931 return this.get( this.stack.pop() );
935 * Searches for all elements that match the specified expression.
936 * This method is the optimal way of finding additional descendant
937 * elements with which to process.
939 * All searching is done using a jQuery expression. The expression can be
940 * written using CSS 1-3 Selector syntax, or basic XPath.
942 * @example $("p").find("span");
943 * @before <p><span>Hello</span>, how are you?</p>
944 * @result $("p").find("span") == [ <span>Hello</span> ]
946 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
950 * @param String expr An expression to search with.
951 * @cat DOM/Traversing
954 return this.pushStack( jQuery.map( this, function(a){
955 return jQuery.find(t,a);
960 * Create cloned copies of all matched DOM Elements. This does
961 * not create a cloned copy of this particular jQuery object,
962 * instead it creates duplicate copies of all DOM Elements.
963 * This is useful for moving copies of the elements to another
964 * location in the DOM.
966 * @example $("b").clone().prependTo("p");
967 * @before <b>Hello</b><p>, how are you?</p>
968 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
970 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
971 * var clone = $('#yahoo').clone();
972 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
973 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
977 * @cat DOM/Manipulation
979 clone: function(deep) {
980 return this.pushStack( jQuery.map( this, function(a){
981 return a.cloneNode( deep != undefined ? deep : true );
986 * Removes all elements from the set of matched elements that do not
987 * match the specified expression. This method is used to narrow down
988 * the results of a search.
990 * All searching is done using a jQuery expression. The expression
991 * can be written using CSS 1-3 Selector syntax, or basic XPath.
993 * @example $("p").filter(".selected")
994 * @before <p class="selected">Hello</p><p>How are you?</p>
995 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
997 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
998 * @test $("input").filter(":checked",function(i){
999 * ok( this == q("radio2", "check1")[i], "Filter elements, context" );
1001 * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){
1002 * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
1007 * @param String expr An expression to search with.
1008 * @cat DOM/Traversing
1012 * Removes all elements from the set of matched elements that do not
1013 * match at least one of the expressions passed to the function. This
1014 * method is used when you want to filter the set of matched elements
1015 * through more than one expression.
1017 * Elements will be retained in the jQuery object if they match at
1018 * least one of the expressions passed.
1020 * @example $("p").filter([".selected", ":first"])
1021 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
1022 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
1026 * @param Array<String> exprs A set of expressions to evaluate against
1027 * @cat DOM/Traversing
1029 filter: function(t) {
1030 return this.pushStack(
1031 t.constructor == Array &&
1032 jQuery.map(this,function(a){
1033 for ( var i = 0; i < t.length; i++ )
1034 if ( jQuery.filter(t[i],[a]).r.length )
1039 t.constructor == Boolean &&
1040 ( t ? this.get() : [] ) ||
1042 typeof t == "function" &&
1043 jQuery.grep( this, t ) ||
1045 jQuery.filter(t,this).r, arguments );
1049 * Removes the specified Element from the set of matched elements. This
1050 * method is used to remove a single Element from a jQuery object.
1052 * @example $("p").not( document.getElementById("selected") )
1053 * @before <p>Hello</p><p id="selected">Hello Again</p>
1054 * @result [ <p>Hello</p> ]
1058 * @param Element el An element to remove from the set
1059 * @cat DOM/Traversing
1063 * Removes elements matching the specified expression from the set
1064 * of matched elements. This method is used to remove one or more
1065 * elements from a jQuery object.
1067 * @example $("p").not("#selected")
1068 * @before <p>Hello</p><p id="selected">Hello Again</p>
1069 * @result [ <p>Hello</p> ]
1071 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
1075 * @param String expr An expression with which to remove matching elements
1076 * @cat DOM/Traversing
1079 return this.pushStack( t.constructor == String ?
1080 jQuery.filter(t,this,false).r :
1081 jQuery.grep(this,function(a){ return a != t; }), arguments );
1085 * Adds the elements matched by the expression to the jQuery object. This
1086 * can be used to concatenate the result sets of two expressions.
1088 * @example $("p").add("span")
1089 * @before <p>Hello</p><p><span>Hello Again</span></p>
1090 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1094 * @param String expr An expression whose matched elements are added
1095 * @cat DOM/Traversing
1099 * Adds each of the Elements in the array to the set of matched elements.
1100 * This is used to add a set of Elements to a jQuery object.
1102 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1103 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1104 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1108 * @param Array<Element> els An array of Elements to add
1109 * @cat DOM/Traversing
1113 * Adds a single Element to the set of matched elements. This is used to
1114 * add a single Element to a jQuery object.
1116 * @example $("p").add( document.getElementById("a") )
1117 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1118 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1122 * @param Element el An Element to add
1123 * @cat DOM/Traversing
1126 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1127 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1131 * Checks the current selection against an expression and returns true,
1132 * if the selection fits the given expression. Does return false, if the
1133 * selection does not fit or the expression is not valid.
1135 * @example $("input[@type='checkbox']").parent().is("form")
1136 * @before <form><input type="checkbox" /></form>
1138 * @desc Returns true, because the parent of the input is a form element
1140 * @example $("input[@type='checkbox']").parent().is("form")
1141 * @before <form><p><input type="checkbox" /></p></form>
1143 * @desc Returns false, because the parent of the input is a p element
1145 * @example $("form").is(null)
1146 * @before <form></form>
1148 * @desc An invalid expression always returns false.
1150 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1151 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1152 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1153 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1154 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1155 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1156 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1157 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1158 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1159 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1160 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1161 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1162 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1163 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1164 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1165 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1166 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1167 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1168 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1169 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1170 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1171 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1175 * @param String expr The expression with which to filter
1176 * @cat DOM/Traversing
1178 is: function(expr) {
1179 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1188 * @param Boolean table
1190 * @param Function fn The function doing the DOM manipulation.
1194 domManip: function(args, table, dir, fn){
1195 var clone = this.size() > 1;
1196 var a = jQuery.clean(args);
1198 return this.each(function(){
1201 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
1202 var tbody = this.getElementsByTagName("tbody");
1204 if ( !tbody.length ) {
1205 obj = document.createElement("tbody");
1206 this.appendChild( obj );
1211 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1212 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1213 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1228 pushStack: function(a,args) {
1229 var fn = args && args[args.length-1];
1230 var fn2 = args && args[args.length-2];
1232 if ( fn && fn.constructor != Function ) fn = null;
1233 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1236 if ( !this.stack ) this.stack = [];
1237 this.stack.push( this.get() );
1240 var old = this.get();
1243 if ( fn2 && a.length || !fn2 )
1244 this.each( fn2 || fn ).get( old );
1246 this.get( old ).each( fn );
1254 * Extends the jQuery object itself. Can be used to add both static
1255 * functions and plugin methods.
1257 * @example $.fn.extend({
1258 * check: function() {
1259 * this.each(function() { this.checked = true; });
1261 * uncheck: function() {
1262 * this.each(function() { this.checked = false; });
1265 * $("input[@type=checkbox]").check();
1266 * $("input[@type=radio]").uncheck();
1267 * @desc Adds two plugin methods.
1277 * Extend one object with another, returning the original,
1278 * modified, object. This is a great utility for simple inheritance.
1280 * @example var settings = { validate: false, limit: 5, name: "foo" };
1281 * var options = { validate: true, name: "bar" };
1282 * jQuery.extend(settings, options);
1283 * @result settings == { validate: true, limit: 5, name: "bar" }
1285 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1286 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1287 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1288 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1289 * jQuery.extend(settings, options);
1290 * isSet( settings, merged, "Check if extended: settings must be extended" );
1291 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1294 * @param Object obj The object to extend
1295 * @param Object prop The object that will be merged into the first.
1299 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1300 if ( !prop ) { prop = obj; obj = this; }
1301 for ( var i in prop ) obj[i] = prop[i];
1313 jQuery.initDone = true;
1315 jQuery.each( jQuery.macros.axis, function(i,n){
1316 jQuery.fn[ i ] = function(a) {
1317 var ret = jQuery.map(this,n);
1318 if ( a && a.constructor == String )
1319 ret = jQuery.filter(a,ret).r;
1320 return this.pushStack( ret, arguments );
1324 jQuery.each( jQuery.macros.to, function(i,n){
1325 jQuery.fn[ i ] = function(){
1327 return this.each(function(){
1328 for ( var j = 0; j < a.length; j++ )
1329 jQuery(a[j])[n]( this );
1334 jQuery.each( jQuery.macros.each, function(i,n){
1335 jQuery.fn[ i ] = function() {
1336 return this.each( n, arguments );
1340 jQuery.each( jQuery.macros.filter, function(i,n){
1341 jQuery.fn[ n ] = function(num,fn) {
1342 return this.filter( ":" + n + "(" + num + ")", fn );
1346 jQuery.each( jQuery.macros.attr, function(i,n){
1348 jQuery.fn[ i ] = function(h) {
1349 return h == undefined ?
1350 this.length ? this[0][n] : null :
1355 jQuery.each( jQuery.macros.css, function(i,n){
1356 jQuery.fn[ n ] = function(h) {
1357 return h == undefined ?
1358 ( this.length ? jQuery.css( this[0], n ) : null ) :
1366 * A generic iterator function, which can be used to seemlessly
1367 * iterate over both objects and arrays. This function is not the same
1368 * as $().each() - which is used to iterate, exclusively, over a jQuery
1369 * object. This function can be used to iterate over anything.
1371 * @example $.each( [0,1,2], function(i){
1372 * alert( "Item #" + i + ": " + this );
1374 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1376 * @example $.each( { name: "John", lang: "JS" }, function(i){
1377 * alert( "Name: " + i + ", Value: " + this );
1379 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1382 * @param Object obj The object, or array, to iterate over.
1383 * @param Function fn The function that will be executed on every object.
1387 each: function( obj, fn, args ) {
1388 if ( obj.length == undefined )
1389 for ( var i in obj )
1390 fn.apply( obj[i], args || [i, obj[i]] );
1392 for ( var i = 0; i < obj.length; i++ )
1393 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1399 if (jQuery.className.has(o,c)) return;
1400 o.className += ( o.className ? " " : "" ) + c;
1402 remove: function(o,c){
1406 var classes = o.className.split(" ");
1407 for(var i=0; i<classes.length; i++) {
1408 if(classes[i] == c) {
1409 classes.splice(i, 1);
1413 o.className = classes.join(' ');
1416 has: function(e,a) {
1417 if ( e.className != undefined )
1419 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1424 * Swap in/out style options.
1427 swap: function(e,o,f) {
1428 for ( var i in o ) {
1429 e.style["old"+i] = e.style[i];
1434 e.style[i] = e.style["old"+i];
1437 css: function(e,p) {
1438 if ( p == "height" || p == "width" ) {
1439 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1441 for ( var i in d ) {
1442 old["padding" + d[i]] = 0;
1443 old["border" + d[i] + "Width"] = 0;
1446 jQuery.swap( e, old, function() {
1447 if (jQuery.css(e,"display") != "none") {
1448 oHeight = e.offsetHeight;
1449 oWidth = e.offsetWidth;
1451 e = jQuery(e.cloneNode(true)).css({
1452 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1453 }).appendTo(e.parentNode)[0];
1455 var parPos = jQuery.css(e.parentNode,"position");
1456 if ( parPos == "" || parPos == "static" )
1457 e.parentNode.style.position = "relative";
1459 oHeight = e.clientHeight;
1460 oWidth = e.clientWidth;
1462 if ( parPos == "" || parPos == "static" )
1463 e.parentNode.style.position = "static";
1465 e.parentNode.removeChild(e);
1469 return p == "height" ? oHeight : oWidth;
1472 return jQuery.curCSS( e, p );
1475 curCSS: function(elem, prop, force) {
1478 if (prop == 'opacity' && jQuery.browser.msie)
1479 return jQuery.attr(elem.style, 'opacity');
1481 if (prop == "float" || prop == "cssFloat")
1482 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1484 if (!force && elem.style[prop]) {
1486 ret = elem.style[prop];
1488 } else if (elem.currentStyle) {
1490 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1491 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1493 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1495 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1496 var cur = document.defaultView.getComputedStyle(elem, null);
1499 ret = cur.getPropertyValue(prop);
1500 else if ( prop == 'display' )
1503 jQuery.swap(elem, { display: 'block' }, function() {
1504 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1512 clean: function(a) {
1514 for ( var i = 0; i < a.length; i++ ) {
1515 if ( a[i].constructor == String ) {
1516 // trim whitespace, otherwise indexOf won't work as expected
1517 a[i] = jQuery.trim(a[i]);
1521 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1523 a[i] = "<table>" + a[i] + "</table>";
1524 } else if ( !a[i].indexOf("<tr") ) {
1526 a[i] = "<table>" + a[i] + "</table>";
1527 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1529 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1532 var div = document.createElement("div");
1533 div.innerHTML = a[i];
1536 div = div.firstChild;
1537 if ( table != "thead" ) div = div.firstChild;
1538 if ( table == "td" ) div = div.firstChild;
1541 for ( var j = 0; j < div.childNodes.length; j++ )
1542 r.push( div.childNodes[j] );
1543 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1544 for ( var k = 0; k < a[i].length; k++ )
1546 else if ( a[i] !== null )
1547 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1553 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1554 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1562 last: "i==r.length-1",
1567 "nth-child": "jQuery.sibling(a,m[3]).cur",
1568 "first-child": "jQuery.sibling(a,0).cur",
1569 "last-child": "jQuery.sibling(a,0).last",
1570 "only-child": "jQuery.sibling(a).length==1",
1573 parent: "a.childNodes.length",
1574 empty: "!a.childNodes.length",
1577 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
1580 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1581 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1584 enabled: "!a.disabled",
1585 disabled: "a.disabled",
1586 checked: "a.checked",
1587 selected: "a.selected || jQuery.attr(a, 'selected')",
1590 text: "a.type=='text'",
1591 radio: "a.type=='radio'",
1592 checkbox: "a.type=='checkbox'",
1593 file: "a.type=='file'",
1594 password: "a.type=='password'",
1595 submit: "a.type=='submit'",
1596 image: "a.type=='image'",
1597 reset: "a.type=='reset'",
1598 button: "a.type=='button'",
1599 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
1601 ".": "jQuery.className.has(a,m[2])",
1605 "^=": "z && !z.indexOf(m[4])",
1606 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1607 "*=": "z && z.indexOf(m[4])>=0",
1610 "[": "jQuery.find(m[2],a).length"
1614 "\\.\\.|/\\.\\.", "a.parentNode",
1615 ">|/", "jQuery.sibling(a.firstChild)",
1616 "\\+", "jQuery.sibling(a).next",
1619 var s = jQuery.sibling(a);
1621 for ( var i = s.n; i < s.length; i++ )
1629 * @test t( "Element Selector", "div", ["main","foo"] );
1630 * t( "Element Selector", "body", ["body"] );
1631 * t( "Element Selector", "html", ["html"] );
1632 * ok( $("*").size() >= 30, "Element Selector" );
1633 * t( "Parent Element", "div div", ["foo"] );
1635 * t( "ID Selector", "#body", ["body"] );
1636 * t( "ID Selector w/ Element", "body#body", ["body"] );
1637 * t( "ID Selector w/ Element", "ul#first", [] );
1639 * t( "Class Selector", ".blog", ["mark","simon"] );
1640 * t( "Class Selector", ".blog.link", ["simon"] );
1641 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1642 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1644 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1645 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1646 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1647 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1649 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1650 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1651 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1652 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1653 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1654 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1655 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1656 * t( "Adjacent", "a + a", ["groups"] );
1657 * t( "Adjacent", "a +a", ["groups"] );
1658 * t( "Adjacent", "a+ a", ["groups"] );
1659 * t( "Adjacent", "a+a", ["groups"] );
1660 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1661 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1662 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1663 * t( "Attribute Exists", "a[@title]", ["google"] );
1664 * t( "Attribute Exists", "*[@title]", ["google"] );
1665 * t( "Attribute Exists", "[@title]", ["google"] );
1667 * t( "Non-existing part of attribute", "[@name*=bla]", [] );
1668 * t( "Non-existing start of attribute", "[@name^=bla]", [] );
1669 * t( "Non-existing end of attribute", "[@name$=bla]", [] );
1671 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1672 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1673 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1674 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1675 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1676 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1678 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1679 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1680 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1681 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1682 * t( "Last Child", "p:last-child", ["sap"] );
1683 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1684 * t( "Empty", "ul:empty", ["firstUL"] );
1685 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1686 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1687 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1688 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1689 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1690 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1691 * t( "Element Preceded By", "p ~ div", ["foo"] );
1692 * t( "Not", "a.blog:not(.link)", ["mark"] );
1694 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1695 * t( "All Div Elements", "//div", ["main","foo"] );
1696 * t( "Absolute Path", "/html/body", ["body"] );
1697 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1698 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1699 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1700 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1701 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1702 * t( "Attribute Exists", "//a[@title]", ["google"] );
1703 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1704 * t( "Parent Axis", "//p/..", ["main","foo"] );
1705 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1706 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1707 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1709 * t( "nth Element", "p:nth(1)", ["ap"] );
1710 * t( "First Element", "p:first", ["firstp"] );
1711 * t( "Last Element", "p:last", ["first"] );
1712 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1713 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1714 * t( "Position Equals", "p:eq(1)", ["ap"] );
1715 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1716 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1717 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1718 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1719 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1721 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1723 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1724 * t( "All Children of ID with no children", "#firstUL/*", [] );
1726 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1727 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1728 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1729 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1730 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1731 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1732 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1734 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1735 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1736 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1739 * @type Array<Element>
1743 find: function( t, context ) {
1744 // Make sure that the context is a DOM Element
1745 if ( context && context.nodeType == undefined )
1748 // Set the correct context (if none is provided)
1749 context = context || jQuery.context || document;
1751 if ( t.constructor != String ) return [t];
1753 if ( !t.indexOf("//") ) {
1754 context = context.documentElement;
1755 t = t.substr(2,t.length);
1756 } else if ( !t.indexOf("/") ) {
1757 context = context.documentElement;
1758 t = t.substr(1,t.length);
1759 // FIX Assume the root element is right :(
1760 if ( t.indexOf("/") >= 1 )
1761 t = t.substr(t.indexOf("/"),t.length);
1764 var ret = [context];
1768 while ( t.length > 0 && last != t ) {
1772 t = jQuery.trim(t).replace( /^\/\//i, "" );
1774 var foundToken = false;
1776 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1777 if ( foundToken ) continue;
1779 var re = new RegExp("^(" + jQuery.token[i] + ")");
1783 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1784 t = jQuery.trim( t.replace( re, "" ) );
1789 if ( !foundToken ) {
1790 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1791 if ( ret[0] == context ) ret.shift();
1792 done = jQuery.merge( done, ret );
1793 r = ret = [context];
1794 t = " " + t.substr(1,t.length);
1796 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1797 var m = re2.exec(t);
1799 if ( m[1] == "#" ) {
1800 // Ummm, should make this work in all XML docs
1801 var oid = document.getElementById(m[2]);
1802 r = ret = oid ? [oid] : [];
1803 t = t.replace( re2, "" );
1805 if ( !m[2] || m[1] == "." ) m[2] = "*";
1807 for ( var i = 0; i < ret.length; i++ )
1808 r = jQuery.merge( r,
1810 jQuery.getAll(ret[i]) :
1811 ret[i].getElementsByTagName(m[2])
1819 var val = jQuery.filter(t,r);
1821 t = jQuery.trim(val.t);
1825 if ( ret && ret[0] == context ) ret.shift();
1826 done = jQuery.merge( done, ret );
1831 getAll: function(o,r) {
1833 var s = o.childNodes;
1834 for ( var i = 0; i < s.length; i++ )
1835 if ( s[i].nodeType == 1 ) {
1837 jQuery.getAll( s[i], r );
1842 attr: function(elem, name, value){
1845 "class": "className",
1846 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1847 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1848 innerHTML: "innerHTML",
1849 className: "className",
1851 disabled: "disabled",
1855 // IE actually uses filters for opacity ... elem is actually elem.style
1856 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
1857 // IE has trouble with opacity if it does not have layout
1858 // Would prefer to check element.hasLayout first but don't have access to the element here
1860 if (value == 1) // Remove filter to avoid more IE weirdness
1861 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
1863 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
1864 } else if (name == "opacity" && jQuery.browser.msie) {
1865 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
1868 // Mozilla doesn't play well with opacity 1
1869 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
1872 if ( value != undefined ) elem[fix[name]] = value;
1873 return elem[fix[name]];
1874 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1875 return elem.getAttributeNode(name).nodeValue;
1876 } else if ( elem.getAttribute != undefined && elem.tagName ) { // IE elem.getAttribute passes even for style
1877 if ( value != undefined ) elem.setAttribute( name, value );
1878 return elem.getAttribute( name );
1880 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1881 if ( value != undefined ) elem[name] = value;
1886 // The regular expressions that power the parsing engine
1888 // Match: [@value='test'], [@foo]
1889 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1891 // Match: [div], [div p]
1892 "(\\[)\s*(.*?)\s*\\]",
1894 // Match: :contains('foo')
1895 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1897 // Match: :even, :last-chlid
1901 filter: function(t,r,not) {
1902 // Figure out if we're doing regular, or inverse, filtering
1903 var g = not !== false ? jQuery.grep :
1904 function(a,f) {return jQuery.grep(a,f,true);};
1906 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1908 var p = jQuery.parse;
1910 for ( var i = 0; i < p.length; i++ ) {
1912 // Look for, and replace, string-like sequences
1913 // and finally build a regexp out of it
1914 var re = new RegExp(
1915 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1917 var m = re.exec( t );
1920 // Re-organize the first match
1922 m = ["",m[1], m[3], m[2], m[5]];
1924 // Remove what we just matched
1925 t = t.replace( re, "" );
1931 // :not() is a special case that can be optimized by
1932 // keeping it out of the expression list
1933 if ( m[1] == ":" && m[2] == "not" )
1934 r = jQuery.filter(m[3],r,false).r;
1936 // Otherwise, find the expression to execute
1938 var f = jQuery.expr[m[1]];
1939 if ( f.constructor != String )
1940 f = jQuery.expr[m[1]][m[2]];
1942 // Build a custom macro to enclose it
1943 eval("f = function(a,i){" +
1944 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1945 "return " + f + "}");
1947 // Execute it against the current filter
1952 // Return an array of filtered elements (r)
1953 // and the modified expression string (t)
1954 return { r: r, t: t };
1958 * Remove the whitespace from the beginning and end of a string.
1960 * @example $.trim(" hello, how are you? ");
1961 * @result "hello, how are you?"
1965 * @param String str The string to trim.
1969 return t.replace(/^\s+|\s+$/g, "");
1973 * All ancestors of a given element.
1977 * @type Array<Element>
1978 * @param Element elem The element to find the ancestors of.
1979 * @cat DOM/Traversing
1981 parents: function( elem ){
1983 var cur = elem.parentNode;
1984 while ( cur && cur != document ) {
1985 matched.push( cur );
1986 cur = cur.parentNode;
1992 * All elements on a specified axis.
1997 * @param Element elem The element to find all the siblings of (including itself).
1998 * @cat DOM/Traversing
2000 sibling: function(elem, pos, not) {
2004 var siblings = elem.parentNode.childNodes;
2005 for ( var i = 0; i < siblings.length; i++ ) {
2006 if ( not === true && siblings[i] == elem ) continue;
2008 if ( siblings[i].nodeType == 1 )
2009 elems.push( siblings[i] );
2010 if ( siblings[i] == elem )
2011 elems.n = elems.length - 1;
2015 return jQuery.extend( elems, {
2016 last: elems.n == elems.length - 1,
2017 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
2018 prev: elems[elems.n - 1],
2019 next: elems[elems.n + 1]
2024 * Merge two arrays together, removing all duplicates. The final order
2025 * or the new array is: All the results from the first array, followed
2026 * by the unique results from the second array.
2028 * @example $.merge( [0,1,2], [2,3,4] )
2029 * @result [0,1,2,3,4]
2031 * @example $.merge( [3,2,1], [4,3,2] )
2036 * @param Array first The first array to merge.
2037 * @param Array second The second array to merge.
2040 merge: function(first, second) {
2043 // Move b over to the new array (this helps to avoid
2044 // StaticNodeList instances)
2045 for ( var k = 0; k < first.length; k++ )
2046 result[k] = first[k];
2048 // Now check for duplicates between a and b and only
2049 // add the unique items
2050 for ( var i = 0; i < second.length; i++ ) {
2051 var noCollision = true;
2053 // The collision-checking process
2054 for ( var j = 0; j < first.length; j++ )
2055 if ( second[i] == first[j] )
2056 noCollision = false;
2058 // If the item is unique, add it
2060 result.push( second[i] );
2067 * Filter items out of an array, by using a filter function.
2068 * The specified function will be passed two arguments: The
2069 * current array item and the index of the item in the array. The
2070 * function should return 'true' if you wish to keep the item in
2071 * the array, false if it should be removed.
2073 * @example $.grep( [0,1,2], function(i){
2080 * @param Array array The Array to find items in.
2081 * @param Function fn The function to process each item against.
2082 * @param Boolean inv Invert the selection - select the opposite of the function.
2085 grep: function(elems, fn, inv) {
2086 // If a string is passed in for the function, make a function
2087 // for it (a handy shortcut)
2088 if ( fn.constructor == String )
2089 fn = new Function("a","i","return " + fn);
2093 // Go through the array, only saving the items
2094 // that pass the validator function
2095 for ( var i = 0; i < elems.length; i++ )
2096 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2097 result.push( elems[i] );
2103 * Translate all items in an array to another array of items.
2104 * The translation function that is provided to this method is
2105 * called for each item in the array and is passed one argument:
2106 * The item to be translated. The function can then return:
2107 * The translated value, 'null' (to remove the item), or
2108 * an array of values - which will be flattened into the full array.
2110 * @example $.map( [0,1,2], function(i){
2115 * @example $.map( [0,1,2], function(i){
2116 * return i > 0 ? i + 1 : null;
2120 * @example $.map( [0,1,2], function(i){
2121 * return [ i, i + 1 ];
2123 * @result [0, 1, 1, 2, 2, 3]
2127 * @param Array array The Array to translate.
2128 * @param Function fn The function to process each item against.
2131 map: function(elems, fn) {
2132 // If a string is passed in for the function, make a function
2133 // for it (a handy shortcut)
2134 if ( fn.constructor == String )
2135 fn = new Function("a","return " + fn);
2139 // Go through the array, translating each of the items to their
2140 // new value (or values).
2141 for ( var i = 0; i < elems.length; i++ ) {
2142 var val = fn(elems[i],i);
2144 if ( val !== null && val != undefined ) {
2145 if ( val.constructor != Array ) val = [val];
2146 result = jQuery.merge( result, val );
2154 * A number of helper functions used for managing events.
2155 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2159 // Bind an event to an element
2160 // Original by Dean Edwards
2161 add: function(element, type, handler) {
2162 // For whatever reason, IE has trouble passing the window object
2163 // around, causing it to be cloned in the process
2164 if ( jQuery.browser.msie && element.setInterval != undefined )
2167 // Make sure that the function being executed has a unique ID
2168 if ( !handler.guid )
2169 handler.guid = this.guid++;
2171 // Init the element's event structure
2172 if (!element.events)
2173 element.events = {};
2175 // Get the current list of functions bound to this event
2176 var handlers = element.events[type];
2178 // If it hasn't been initialized yet
2180 // Init the event handler queue
2181 handlers = element.events[type] = {};
2183 // Remember an existing handler, if it's already there
2184 if (element["on" + type])
2185 handlers[0] = element["on" + type];
2188 // Add the function to the element's handler list
2189 handlers[handler.guid] = handler;
2191 // And bind the global event handler to the element
2192 element["on" + type] = this.handle;
2194 // Remember the function in a global list (for triggering)
2195 if (!this.global[type])
2196 this.global[type] = [];
2197 this.global[type].push( element );
2203 // Detach an event or set of events from an element
2204 remove: function(element, type, handler) {
2206 if (type && element.events[type])
2208 delete element.events[type][handler.guid];
2210 for ( var i in element.events[type] )
2211 delete element.events[type][i];
2213 for ( var j in element.events )
2214 this.remove( element, j );
2217 trigger: function(type,data,element) {
2218 // Touch up the incoming data
2221 // Handle a global trigger
2223 var g = this.global[type];
2225 for ( var i = 0; i < g.length; i++ )
2226 this.trigger( type, data, g[i] );
2228 // Handle triggering a single element
2229 } else if ( element["on" + type] ) {
2230 // Pass along a fake event
2231 data.unshift( this.fix({ type: type, target: element }) );
2233 // Trigger the event
2234 element["on" + type].apply( element, data );
2238 handle: function(event) {
2239 if ( typeof jQuery == "undefined" ) return false;
2241 event = event || jQuery.event.fix( window.event );
2243 // If no correct event was found, fail
2244 if ( !event ) return false;
2246 var returnValue = true;
2248 var c = this.events[event.type];
2250 var args = [].slice.call( arguments, 1 );
2251 args.unshift( event );
2253 for ( var j in c ) {
2254 if ( c[j].apply( this, args ) === false ) {
2255 event.preventDefault();
2256 event.stopPropagation();
2257 returnValue = false;
2264 fix: function(event) {
2266 event.preventDefault = function() {
2267 this.returnValue = false;
2270 event.stopPropagation = function() {
2271 this.cancelBubble = true;
2282 * Contains flags for the useragent, read from navigator.userAgent.
2283 * Available flags are: safari, opera, msie, mozilla
2284 * This property is available before the DOM is ready, therefore you can
2285 * use it to add ready events only for certain browsers.
2287 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2288 * jQBrowser plugin</a> for advanced browser detection:
2290 * @example $.browser.msie
2291 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2293 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2294 * @desc Alerts "this is safari!" only for safari browsers
2301 var b = navigator.userAgent.toLowerCase();
2303 // Figure out what browser is being used
2305 safari: /webkit/.test(b),
2306 opera: /opera/.test(b),
2307 msie: /msie/.test(b) && !/opera/.test(b),
2308 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2311 // Check to see if the W3C box model is being used
2312 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2318 * Append all of the matched elements to another, specified, set of elements.
2319 * This operation is, essentially, the reverse of doing a regular
2320 * $(A).append(B), in that instead of appending B to A, you're appending
2323 * @example $("p").appendTo("#foo");
2324 * @before <p>I would like to say: </p><div id="foo"></div>
2325 * @result <div id="foo"><p>I would like to say: </p></div>
2329 * @param String expr A jQuery expression of elements to match.
2330 * @cat DOM/Manipulation
2335 * Prepend all of the matched elements to another, specified, set of elements.
2336 * This operation is, essentially, the reverse of doing a regular
2337 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2340 * @example $("p").prependTo("#foo");
2341 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2342 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2346 * @param String expr A jQuery expression of elements to match.
2347 * @cat DOM/Manipulation
2349 prependTo: "prepend",
2352 * Insert all of the matched elements before another, specified, set of elements.
2353 * This operation is, essentially, the reverse of doing a regular
2354 * $(A).before(B), in that instead of inserting B before A, you're inserting
2357 * @example $("p").insertBefore("#foo");
2358 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2359 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2361 * @name insertBefore
2363 * @param String expr A jQuery expression of elements to match.
2364 * @cat DOM/Manipulation
2366 insertBefore: "before",
2369 * Insert all of the matched elements after another, specified, set of elements.
2370 * This operation is, essentially, the reverse of doing a regular
2371 * $(A).after(B), in that instead of inserting B after A, you're inserting
2374 * @example $("p").insertAfter("#foo");
2375 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2376 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2380 * @param String expr A jQuery expression of elements to match.
2381 * @cat DOM/Manipulation
2383 insertAfter: "after"
2387 * Get the current CSS width of the first matched element.
2389 * @example $("p").width();
2390 * @before <p>This is just a test.</p>
2399 * Set the CSS width of every matched element. Be sure to include
2400 * the "px" (or other unit of measurement) after the number that you
2401 * specify, otherwise you might get strange results.
2403 * @example $("p").width("20px");
2404 * @before <p>This is just a test.</p>
2405 * @result <p style="width:20px;">This is just a test.</p>
2409 * @param String val Set the CSS property to the specified value.
2414 * Get the current CSS height of the first matched element.
2416 * @example $("p").height();
2417 * @before <p>This is just a test.</p>
2426 * Set the CSS height of every matched element. Be sure to include
2427 * the "px" (or other unit of measurement) after the number that you
2428 * specify, otherwise you might get strange results.
2430 * @example $("p").height("20px");
2431 * @before <p>This is just a test.</p>
2432 * @result <p style="height:20px;">This is just a test.</p>
2436 * @param String val Set the CSS property to the specified value.
2441 * Get the current CSS top of the first matched element.
2443 * @example $("p").top();
2444 * @before <p>This is just a test.</p>
2453 * Set the CSS top of every matched element. Be sure to include
2454 * the "px" (or other unit of measurement) after the number that you
2455 * specify, otherwise you might get strange results.
2457 * @example $("p").top("20px");
2458 * @before <p>This is just a test.</p>
2459 * @result <p style="top:20px;">This is just a test.</p>
2463 * @param String val Set the CSS property to the specified value.
2468 * Get the current CSS left of the first matched element.
2470 * @example $("p").left();
2471 * @before <p>This is just a test.</p>
2480 * Set the CSS left of every matched element. Be sure to include
2481 * the "px" (or other unit of measurement) after the number that you
2482 * specify, otherwise you might get strange results.
2484 * @example $("p").left("20px");
2485 * @before <p>This is just a test.</p>
2486 * @result <p style="left:20px;">This is just a test.</p>
2490 * @param String val Set the CSS property to the specified value.
2495 * Get the current CSS position of the first matched element.
2497 * @example $("p").position();
2498 * @before <p>This is just a test.</p>
2507 * Set the CSS position of every matched element.
2509 * @example $("p").position("relative");
2510 * @before <p>This is just a test.</p>
2511 * @result <p style="position:relative;">This is just a test.</p>
2515 * @param String val Set the CSS property to the specified value.
2520 * Get the current CSS float of the first matched element.
2522 * @example $("p").float();
2523 * @before <p>This is just a test.</p>
2532 * Set the CSS float of every matched element.
2534 * @example $("p").float("left");
2535 * @before <p>This is just a test.</p>
2536 * @result <p style="float:left;">This is just a test.</p>
2540 * @param String val Set the CSS property to the specified value.
2545 * Get the current CSS overflow of the first matched element.
2547 * @example $("p").overflow();
2548 * @before <p>This is just a test.</p>
2557 * Set the CSS overflow of every matched element.
2559 * @example $("p").overflow("auto");
2560 * @before <p>This is just a test.</p>
2561 * @result <p style="overflow:auto;">This is just a test.</p>
2565 * @param String val Set the CSS property to the specified value.
2570 * Get the current CSS color of the first matched element.
2572 * @example $("p").color();
2573 * @before <p>This is just a test.</p>
2582 * Set the CSS color of every matched element.
2584 * @example $("p").color("blue");
2585 * @before <p>This is just a test.</p>
2586 * @result <p style="color:blue;">This is just a test.</p>
2590 * @param String val Set the CSS property to the specified value.
2595 * Get the current CSS background of the first matched element.
2597 * @example $("p").background();
2598 * @before <p style="background:blue;">This is just a test.</p>
2607 * Set the CSS background of every matched element.
2609 * @example $("p").background("blue");
2610 * @before <p>This is just a test.</p>
2611 * @result <p style="background:blue;">This is just a test.</p>
2615 * @param String val Set the CSS property to the specified value.
2619 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2622 * Reduce the set of matched elements to a single element.
2623 * The position of the element in the set of matched elements
2624 * starts at 0 and goes to length - 1.
2626 * @example $("p").eq(1)
2627 * @before <p>This is just a test.</p><p>So is this</p>
2628 * @result [ <p>So is this</p> ]
2632 * @param Number pos The index of the element that you wish to limit to.
2637 * Reduce the set of matched elements to all elements before a given position.
2638 * The position of the element in the set of matched elements
2639 * starts at 0 and goes to length - 1.
2641 * @example $("p").lt(1)
2642 * @before <p>This is just a test.</p><p>So is this</p>
2643 * @result [ <p>This is just a test.</p> ]
2647 * @param Number pos Reduce the set to all elements below this position.
2652 * Reduce the set of matched elements to all elements after a given position.
2653 * The position of the element in the set of matched elements
2654 * starts at 0 and goes to length - 1.
2656 * @example $("p").gt(0)
2657 * @before <p>This is just a test.</p><p>So is this</p>
2658 * @result [ <p>So is this</p> ]
2662 * @param Number pos Reduce the set to all elements after this position.
2667 * Filter the set of elements to those that contain the specified text.
2669 * @example $("p").contains("test")
2670 * @before <p>This is just a test.</p><p>So is this</p>
2671 * @result [ <p>This is just a test.</p> ]
2675 * @param String str The string that will be contained within the text of an element.
2676 * @cat DOM/Traversing
2679 filter: [ "eq", "lt", "gt", "contains" ],
2683 * Get the current value of the first matched element.
2685 * @example $("input").val();
2686 * @before <input type="text" value="some text"/>
2687 * @result "some text"
2689 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2690 * ok( !$("#text1").val() == "", "Check for value of input element" );
2694 * @cat DOM/Attributes
2698 * Set the value of every matched element.
2700 * @example $("input").val("test");
2701 * @before <input type="text" value="some text"/>
2702 * @result <input type="text" value="test"/>
2704 * @test document.getElementById('text1').value = "bla";
2705 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2706 * $("#text1").val('test');
2707 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2711 * @param String val Set the property to the specified value.
2712 * @cat DOM/Attributes
2717 * Get the html contents of the first matched element.
2719 * @example $("div").html();
2720 * @before <div><input/></div>
2725 * @cat DOM/Attributes
2729 * Set the html contents of every matched element.
2731 * @example $("div").html("<b>new stuff</b>");
2732 * @before <div><input/></div>
2733 * @result <div><b>new stuff</b></div>
2735 * @test var div = $("div");
2736 * div.html("<b>test</b>");
2738 * for ( var i = 0; i < div.size(); i++ ) {
2739 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2741 * ok( pass, "Set HTML" );
2745 * @param String val Set the html contents to the specified value.
2746 * @cat DOM/Attributes
2751 * Get the current id of the first matched element.
2753 * @example $("input").id();
2754 * @before <input type="text" id="test" value="some text"/>
2757 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2758 * ok( $("#foo").id() == "foo", "Check for id" );
2759 * ok( !$("head").id(), "Check for id" );
2763 * @cat DOM/Attributes
2767 * Set the id of every matched element.
2769 * @example $("input").id("newid");
2770 * @before <input type="text" id="test" value="some text"/>
2771 * @result <input type="text" id="newid" value="some text"/>
2775 * @param String val Set the property to the specified value.
2776 * @cat DOM/Attributes
2781 * Get the current title of the first matched element.
2783 * @example $("img").title();
2784 * @before <img src="test.jpg" title="my image"/>
2785 * @result "my image"
2787 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2788 * ok( !$("#yahoo").title(), "Check for title" );
2792 * @cat DOM/Attributes
2796 * Set the title of every matched element.
2798 * @example $("img").title("new title");
2799 * @before <img src="test.jpg" title="my image"/>
2800 * @result <img src="test.jpg" title="new image"/>
2804 * @param String val Set the property to the specified value.
2805 * @cat DOM/Attributes
2810 * Get the current name of the first matched element.
2812 * @example $("input").name();
2813 * @before <input type="text" name="username"/>
2814 * @result "username"
2816 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2817 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2818 * ok( !$("#area1").name(), "Check for name" );
2822 * @cat DOM/Attributes
2826 * Set the name of every matched element.
2828 * @example $("input").name("user");
2829 * @before <input type="text" name="username"/>
2830 * @result <input type="text" name="user"/>
2834 * @param String val Set the property to the specified value.
2835 * @cat DOM/Attributes
2840 * Get the current href of the first matched element.
2842 * @example $("a").href();
2843 * @before <a href="test.html">my link</a>
2844 * @result "test.html"
2848 * @cat DOM/Attributes
2852 * Set the href of every matched element.
2854 * @example $("a").href("test2.html");
2855 * @before <a href="test.html">my link</a>
2856 * @result <a href="test2.html">my link</a>
2860 * @param String val Set the property to the specified value.
2861 * @cat DOM/Attributes
2866 * Get the current src of the first matched element.
2868 * @example $("img").src();
2869 * @before <img src="test.jpg" title="my image"/>
2870 * @result "test.jpg"
2874 * @cat DOM/Attributes
2878 * Set the src of every matched element.
2880 * @example $("img").src("test2.jpg");
2881 * @before <img src="test.jpg" title="my image"/>
2882 * @result <img src="test2.jpg" title="my image"/>
2886 * @param String val Set the property to the specified value.
2887 * @cat DOM/Attributes
2892 * Get the current rel of the first matched element.
2894 * @example $("a").rel();
2895 * @before <a href="test.html" rel="nofollow">my link</a>
2896 * @result "nofollow"
2900 * @cat DOM/Attributes
2904 * Set the rel of every matched element.
2906 * @example $("a").rel("nofollow");
2907 * @before <a href="test.html">my link</a>
2908 * @result <a href="test.html" rel="nofollow">my link</a>
2912 * @param String val Set the property to the specified value.
2913 * @cat DOM/Attributes
2920 * Get a set of elements containing the unique parents of the matched
2923 * @example $("p").parent()
2924 * @before <div><p>Hello</p><p>Hello</p></div>
2925 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2929 * @cat DOM/Traversing
2933 * Get a set of elements containing the unique parents of the matched
2934 * set of elements, and filtered by an expression.
2936 * @example $("p").parent(".selected")
2937 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2938 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2942 * @param String expr An expression to filter the parents with
2943 * @cat DOM/Traversing
2945 parent: "a.parentNode",
2948 * Get a set of elements containing the unique ancestors of the matched
2949 * set of elements (except for the root element).
2951 * @example $("span").ancestors()
2952 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2953 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2957 * @cat DOM/Traversing
2961 * Get a set of elements containing the unique ancestors of the matched
2962 * set of elements, and filtered by an expression.
2964 * @example $("span").ancestors("p")
2965 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2966 * @result [ <p><span>Hello</span></p> ]
2970 * @param String expr An expression to filter the ancestors with
2971 * @cat DOM/Traversing
2973 ancestors: jQuery.parents,
2976 * Get a set of elements containing the unique ancestors of the matched
2977 * set of elements (except for the root element).
2979 * @example $("span").ancestors()
2980 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2981 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2985 * @cat DOM/Traversing
2989 * Get a set of elements containing the unique ancestors of the matched
2990 * set of elements, and filtered by an expression.
2992 * @example $("span").ancestors("p")
2993 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2994 * @result [ <p><span>Hello</span></p> ]
2998 * @param String expr An expression to filter the ancestors with
2999 * @cat DOM/Traversing
3001 parents: jQuery.parents,
3004 * Get a set of elements containing the unique next siblings of each of the
3005 * matched set of elements.
3007 * It only returns the very next sibling, not all next siblings.
3009 * @example $("p").next()
3010 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
3011 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
3015 * @cat DOM/Traversing
3019 * Get a set of elements containing the unique next siblings of each of the
3020 * matched set of elements, and filtered by an expression.
3022 * It only returns the very next sibling, not all next siblings.
3024 * @example $("p").next(".selected")
3025 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
3026 * @result [ <p class="selected">Hello Again</p> ]
3030 * @param String expr An expression to filter the next Elements with
3031 * @cat DOM/Traversing
3033 next: "jQuery.sibling(a).next",
3036 * Get a set of elements containing the unique previous siblings of each of the
3037 * matched set of elements.
3039 * It only returns the immediately previous sibling, not all previous siblings.
3041 * @example $("p").prev()
3042 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3043 * @result [ <div><span>Hello Again</span></div> ]
3047 * @cat DOM/Traversing
3051 * Get a set of elements containing the unique previous siblings of each of the
3052 * matched set of elements, and filtered by an expression.
3054 * It only returns the immediately previous sibling, not all previous siblings.
3056 * @example $("p").previous(".selected")
3057 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3058 * @result [ <div><span>Hello</span></div> ]
3062 * @param String expr An expression to filter the previous Elements with
3063 * @cat DOM/Traversing
3065 prev: "jQuery.sibling(a).prev",
3068 * Get a set of elements containing all of the unique siblings of each of the
3069 * matched set of elements.
3071 * @example $("div").siblings()
3072 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3073 * @result [ <p>Hello</p>, <p>And Again</p> ]
3075 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3079 * @cat DOM/Traversing
3083 * Get a set of elements containing all of the unique siblings of each of the
3084 * matched set of elements, and filtered by an expression.
3086 * @example $("div").siblings(".selected")
3087 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3088 * @result [ <p class="selected">Hello Again</p> ]
3090 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3091 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3095 * @param String expr An expression to filter the sibling Elements with
3096 * @cat DOM/Traversing
3098 siblings: "jQuery.sibling(a, null, true)",
3102 * Get a set of elements containing all of the unique children of each of the
3103 * matched set of elements.
3105 * @example $("div").children()
3106 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3107 * @result [ <span>Hello Again</span> ]
3109 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3113 * @cat DOM/Traversing
3117 * Get a set of elements containing all of the unique children of each of the
3118 * matched set of elements, and filtered by an expression.
3120 * @example $("div").children(".selected")
3121 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3122 * @result [ <p class="selected">Hello Again</p> ]
3124 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3128 * @param String expr An expression to filter the child Elements with
3129 * @cat DOM/Traversing
3131 children: "jQuery.sibling(a.firstChild)"
3137 * Remove an attribute from each of the matched elements.
3139 * @example $("input").removeAttr("disabled")
3140 * @before <input disabled="disabled"/>
3145 * @param String name The name of the attribute to remove.
3148 removeAttr: function( key ) {
3149 this.removeAttribute( key );
3153 * Displays each of the set of matched elements if they are hidden.
3155 * @example $("p").show()
3156 * @before <p style="display: none">Hello</p>
3157 * @result [ <p style="display: block">Hello</p> ]
3159 * @test var pass = true, div = $("div");
3160 * div.show().each(function(){
3161 * if ( this.style.display == "none" ) pass = false;
3163 * ok( pass, "Show" );
3170 this.style.display = this.oldblock ? this.oldblock : "";
3171 if ( jQuery.css(this,"display") == "none" )
3172 this.style.display = "block";
3176 * Hides each of the set of matched elements if they are shown.
3178 * @example $("p").hide()
3179 * @before <p>Hello</p>
3180 * @result [ <p style="display: none">Hello</p> ]
3182 * var pass = true, div = $("div");
3183 * div.hide().each(function(){
3184 * if ( this.style.display != "none" ) pass = false;
3186 * ok( pass, "Hide" );
3193 this.oldblock = this.oldblock || jQuery.css(this,"display");
3194 if ( this.oldblock == "none" )
3195 this.oldblock = "block";
3196 this.style.display = "none";
3200 * Toggles each of the set of matched elements. If they are shown,
3201 * toggle makes them hidden. If they are hidden, toggle
3204 * @example $("p").toggle()
3205 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3206 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3213 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3217 * Adds the specified class to each of the set of matched elements.
3219 * @example $("p").addClass("selected")
3220 * @before <p>Hello</p>
3221 * @result [ <p class="selected">Hello</p> ]
3223 * @test var div = $("div");
3224 * div.addClass("test");
3226 * for ( var i = 0; i < div.size(); i++ ) {
3227 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3229 * ok( pass, "Add Class" );
3233 * @param String class A CSS class to add to the elements
3236 addClass: function(c){
3237 jQuery.className.add(this,c);
3241 * Removes the specified class from the set of matched elements.
3243 * @example $("p").removeClass("selected")
3244 * @before <p class="selected">Hello</p>
3245 * @result [ <p>Hello</p> ]
3247 * @test var div = $("div").addClass("test");
3248 * div.removeClass("test");
3250 * for ( var i = 0; i < div.size(); i++ ) {
3251 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3253 * ok( pass, "Remove Class" );
3257 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3258 * div.removeClass("test").removeClass("bar").removeClass("foo");
3260 * for ( var i = 0; i < div.size(); i++ ) {
3261 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3263 * ok( pass, "Remove multiple classes" );
3267 * @param String class A CSS class to remove from the elements
3270 removeClass: function(c){
3271 jQuery.className.remove(this,c);
3275 * Adds the specified class if it is present, removes it if it is
3278 * @example $("p").toggleClass("selected")
3279 * @before <p>Hello</p><p class="selected">Hello Again</p>
3280 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3284 * @param String class A CSS class with which to toggle the elements
3287 toggleClass: function( c ){
3288 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3292 * Removes all matched elements from the DOM. This does NOT remove them from the
3293 * jQuery object, allowing you to use the matched elements further.
3295 * @example $("p").remove();
3296 * @before <p>Hello</p> how are <p>you?</p>
3301 * @cat DOM/Manipulation
3305 * Removes only elements (out of the list of matched elements) that match
3306 * the specified jQuery expression. This does NOT remove them from the
3307 * jQuery object, allowing you to use the matched elements further.
3309 * @example $("p").remove(".hello");
3310 * @before <p class="hello">Hello</p> how are <p>you?</p>
3311 * @result how are <p>you?</p>
3315 * @param String expr A jQuery expression to filter elements by.
3316 * @cat DOM/Manipulation
3318 remove: function(a){
3319 if ( !a || jQuery.filter( a, [this] ).r )
3320 this.parentNode.removeChild( this );
3324 * Removes all child nodes from the set of matched elements.
3326 * @example $("p").empty()
3327 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3328 * @result [ <p></p> ]
3332 * @cat DOM/Manipulation
3335 while ( this.firstChild )
3336 this.removeChild( this.firstChild );
3340 * Binds a handler to a particular event (like click) for each matched element.
3341 * The event handler is passed an event object that you can use to prevent
3342 * default behaviour. To stop both default action and event bubbling, your handler
3343 * has to return false.
3345 * @example $("p").bind( "click", function() {
3346 * alert( $(this).text() );
3348 * @before <p>Hello</p>
3349 * @result alert("Hello")
3351 * @example $("form").bind( "submit", function() { return false; } )
3352 * @desc Cancel a default action and prevent it from bubbling by returning false
3353 * from your function.
3355 * @example $("form").bind( "submit", function(event) {
3356 * event.preventDefault();
3358 * @desc Cancel only the default action by using the preventDefault method.
3361 * @example $("form").bind( "submit", function(event) {
3362 * event.stopPropagation();
3364 * @desc Stop only an event from bubbling by using the stopPropagation method.
3368 * @param String type An event type
3369 * @param Function fn A function to bind to the event on each of the set of matched elements
3372 bind: function( type, fn ) {
3373 if ( fn.constructor == String )
3374 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3375 jQuery.event.add( this, type, fn );
3379 * The opposite of bind, removes a bound event from each of the matched
3380 * elements. You must pass the identical function that was used in the original
3383 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3384 * @before <p onclick="alert('Hello');">Hello</p>
3385 * @result [ <p>Hello</p> ]
3389 * @param String type An event type
3390 * @param Function fn A function to unbind from the event on each of the set of matched elements
3395 * Removes all bound events of a particular type from each of the matched
3398 * @example $("p").unbind( "click" )
3399 * @before <p onclick="alert('Hello');">Hello</p>
3400 * @result [ <p>Hello</p> ]
3404 * @param String type An event type
3409 * Removes all bound events from each of the matched elements.
3411 * @example $("p").unbind()
3412 * @before <p onclick="alert('Hello');">Hello</p>
3413 * @result [ <p>Hello</p> ]
3419 unbind: function( type, fn ) {
3420 jQuery.event.remove( this, type, fn );
3424 * Trigger a type of event on every matched element.
3426 * @example $("p").trigger("click")
3427 * @before <p click="alert('hello')">Hello</p>
3428 * @result alert('hello')
3432 * @param String type An event type to trigger.
3435 trigger: function( type, data ) {
3436 jQuery.event.trigger( type, data, this );