2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * @test ok( Function.prototype.apply, "Function.apply()" );
20 * @test ok( document.getElementById, "getElementById" );
21 * @test ok( document.getElementsByTagName, "getElementsByTagName" );
22 * @test ok( RegExp, "RegExp" );
23 * @test ok( jQuery, "jQuery" );
24 * @test ok( $, "$()" );
31 function jQuery(a,c) {
33 // Shortcut for document ready (because $(document).each() is silly)
34 if ( a && a.constructor == Function && jQuery.fn.ready )
35 return jQuery(document).ready(a);
37 // Make sure that a selection was provided
38 a = a || jQuery.context || document;
40 // Watch for when a jQuery object is passed as the selector
42 return jQuery( jQuery.merge( a, [] ) );
44 // Watch for when a jQuery object is passed at the context
46 return jQuery( c ).find(a);
48 // If the context is global, return a new object
50 return new jQuery(a,c);
52 // Handle HTML strings
53 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
54 if ( m ) a = jQuery.clean( [ m[1] ] );
56 // Watch for when an array is passed in
57 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
58 // Assume that it is an array of DOM Elements
59 jQuery.merge( a, [] ) :
61 // Find the matching elements and save them for later
62 jQuery.find( a, c ) );
64 // See if an extra function was provided
65 var fn = arguments[ arguments.length - 1 ];
67 // If so, execute it in context
68 if ( fn && fn.constructor == Function )
72 // Map over the $ in case of overwrite
73 if ( typeof $ != "undefined" )
77 * This function accepts a string containing a CSS selector,
78 * basic XPath, or raw HTML, which is then used to match a set of elements.
79 * The HTML string is different from the traditional selectors in that
80 * it creates the DOM elements representing that HTML string, on the fly,
81 * to be (assumedly) inserted into the document later.
83 * The core functionality of jQuery centers around this function.
84 * Everything in jQuery is based upon this, or uses this in some way.
85 * The most basic use of this function is to pass in an expression
86 * (usually consisting of CSS or XPath), which then finds all matching
87 * elements and remembers them for later use.
89 * By default, $() looks for DOM elements within the context of the
90 * current HTML document.
92 * @example $("div > p")
93 * @desc This finds all p elements that are children of a div element.
94 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
95 * @result [ <p>two</p> ]
97 * @example $("<div><p>Hello</p></div>").appendTo("#body")
98 * @desc Creates a div element (and all of its contents) dynamically, and appends it to the element with the ID of body.
101 * @param String expr An expression to search with, or a string of HTML to create on the fly.
107 * This function accepts a string containing a CSS selector, or
108 * basic XPath, which is then used to match a set of elements with the
109 * context of the specified DOM element, or document
111 * @example $("div", xml.responseXML)
112 * @desc This finds all div elements within the specified XML document.
115 * @param String expr An expression to search with.
116 * @param Element context A DOM Element, or Document, representing the base context.
122 * Wrap jQuery functionality around a specific DOM Element.
123 * This function also accepts XML Documents and Window objects
124 * as valid arguments (even though they are not DOM Elements).
126 * @example $(document).find("div > p")
127 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
128 * @result [ <p>two</p> ]
130 * @example $(document).ready( loaded );
131 * @desc Executes the "loaded" function when the DOM is ready to
135 * @param Element elem A DOM element to be encapsulated by a jQuery object.
141 * Wrap jQuery functionality around a set of DOM Elements.
143 * @example $( myForm.elements ).hide()
144 * @desc Hides all the input elements within a form
147 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
153 * A shorthand for $(document).ready(), allowing you to bind a function
154 * to be executed when the DOM document has finished loading.
156 * @example $( loaded )
157 * @desc Executes the function "loaded" when the DOM is ready to be used.
160 * @param Function fn The function to execute when the DOM is ready.
166 * A means of creating a duplicate copy of a jQuery object.
168 * @example var div = $("div");
170 * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div'.
173 * @param jQuery obj The jQuery object to be cloned.
178 // Map the jQuery namespace to the '$' one
181 jQuery.fn = jQuery.prototype = {
183 * The current SVN version of jQuery.
194 * The number of elements currently matched.
196 * @example $("img").length;
197 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
200 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
209 * The number of elements currently matched.
211 * @example $("img").size();
212 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
215 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
226 * Access all matched elements. This serves as a backwards-compatible
227 * way of accessing all matched elements (other than the jQuery object
228 * itself, which is, in fact, an array of elements).
230 * @example $("img").get();
231 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
232 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
234 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
237 * @type Array<Element>
242 * Access a single matched element. num is used to access the
243 * Nth element matched.
245 * @example $("img").get(1);
246 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
247 * @result [ <img src="test1.jpg"/> ]
249 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
253 * @param Number num Access the element in the Nth position.
258 * Set the jQuery object to an array of elements.
260 * @example $("img").get([ document.body ]);
261 * @result $("img").get() == [ document.body ]
266 * @param Elements elems An array of elements
269 get: function( num ) {
270 // Watch for when an array (of elements) is passed in
271 if ( num && num.constructor == Array ) {
273 // Use a tricky hack to make the jQuery object
274 // look and feel like an array
276 [].push.apply( this, num );
280 return num == undefined ?
282 // Return a 'clean' array
283 jQuery.map( this, function(a){ return a } ) :
285 // Return just the object
290 * Execute a function within the context of every matched element.
291 * This means that every time the passed-in function is executed
292 * (which is once for every element matched) the 'this' keyword
293 * points to the specific element.
295 * Additionally, the function, when executed, is passed a single
296 * argument representing the position of the element in the matched
299 * @example $("img").each(function(){
300 * this.src = "test.jpg";
302 * @before <img/> <img/>
303 * @result <img src="test.jpg"/> <img src="test.jpg"/>
305 * @example $("img").each(function(i){
306 * alert( "Image #" + i + " is " + this );
308 * @before <img/> <img/>
309 * @result <img src="test.jpg"/> <img src="test.jpg"/>
311 * @test var div = $("div");
312 * div.each(function(){this.foo = 'zoo';});
314 * for ( var i = 0; i < div.size(); i++ ) {
315 * if ( div.get(i).foo != "zoo" ) pass = false;
317 * ok( pass, "Execute a function, Relative" );
321 * @param Function fn A function to execute
324 each: function( fn, args ) {
325 return jQuery.each( this, fn, args );
328 index: function( obj ) {
330 this.each(function(i){
331 if ( this == obj ) pos = i;
337 * Access a property on the first matched element.
338 * This method makes it easy to retreive a property value
339 * from the first matched element.
341 * @example $("img").attr("src");
342 * @before <img src="test.jpg"/>
347 * @param String name The name of the property to access.
352 * Set a hash of key/value object properties to all matched elements.
353 * This serves as the best way to set a large number of properties
354 * on all matched elements.
356 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
358 * @result <img src="test.jpg" alt="Test Image"/>
360 * @test var pass = true;
361 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
362 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
364 * ok( pass, "Set Multiple Attributes" );
368 * @param Hash prop A set of key/value pairs to set as object properties.
373 * Set a single property to a value, on all matched elements.
375 * @example $("img").attr("src","test.jpg");
377 * @result <img src="test.jpg"/>
379 * @test var div = $("div");
380 * div.attr("foo", "bar");
382 * for ( var i = 0; i < div.size(); i++ ) {
383 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
385 * ok( pass, "Set Attribute" );
389 * @param String key The name of the property to set.
390 * @param Object value The value to set the property to.
393 attr: function( key, value, type ) {
394 // Check to see if we're setting style values
395 return key.constructor != String || value != undefined ?
396 this.each(function(){
397 // See if we're setting a hash of styles
398 if ( value == undefined )
399 // Set all the styles
400 for ( var prop in key )
402 type ? this.style : this,
406 // See if we're setting a single key/value style
409 type ? this.style : this,
414 // Look for the case where we're accessing a style value
415 jQuery[ type || "attr" ]( this[0], key );
419 * Access a style property on the first matched element.
420 * This method makes it easy to retreive a style property value
421 * from the first matched element.
423 * @example $("p").css("red");
424 * @before <p style="color:red;">Test Paragraph.</p>
429 * @param String name The name of the property to access.
434 * Set a hash of key/value style properties to all matched elements.
435 * This serves as the best way to set a large number of style properties
436 * on all matched elements.
438 * @example $("p").css({ color: "red", background: "blue" });
439 * @before <p>Test Paragraph.</p>
440 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
444 * @param Hash prop A set of key/value pairs to set as style properties.
449 * Set a single style property to a value, on all matched elements.
451 * @example $("p").css("color","red");
452 * @before <p>Test Paragraph.</p>
453 * @result <p style="color:red;">Test Paragraph.</p>
457 * @param String key The name of the property to set.
458 * @param Object value The value to set the property to.
461 css: function( key, value ) {
462 return this.attr( key, value, "curCSS" );
466 * Retreive the text contents of all matched elements. The result is
467 * a string that contains the combined text contents of all matched
468 * elements. This method works on both HTML and XML documents.
470 * @example $("p").text();
471 * @before <p>Test Paragraph.</p>
472 * @result Test Paragraph.
481 for ( var j = 0; j < e.length; j++ ) {
482 var r = e[j].childNodes;
483 for ( var i = 0; i < r.length; i++ )
484 if ( r[i].nodeType != 8 )
485 t += r[i].nodeType != 1 ?
486 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
492 * Wrap all matched elements with a structure of other elements.
493 * This wrapping process is most useful for injecting additional
494 * stucture into a document, without ruining the original semantic
495 * qualities of a document.
497 * This works by going through the first element
498 * provided (which is generated, on the fly, from the provided HTML)
499 * and finds the deepest ancestor element within its
500 * structure - it is that element that will en-wrap everything else.
502 * @example $("p").wrap("<div class='wrap'></div>");
503 * @before <p>Test Paragraph.</p>
504 * @result <div class='wrap'><p>Test Paragraph.</p></div>
508 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
509 * @cat DOM/Manipulation
513 * Wrap all matched elements with a structure of other elements.
514 * This wrapping process is most useful for injecting additional
515 * stucture into a document, without ruining the original semantic
516 * qualities of a document.
518 * This works by going through the first element
519 * provided and finding the deepest ancestor element within its
520 * structure - it is that element that will en-wrap everything else.
522 * @example $("p").wrap("<div class='wrap'></div>");
523 * @before <p>Test Paragraph.</p>
524 * @result <div class='wrap'><p>Test Paragraph.</p></div>
528 * @param Element elem A DOM element that will be wrapped.
529 * @cat DOM/Manipulation
532 // The elements to wrap the target around
533 var a = jQuery.clean(arguments);
535 // Wrap each of the matched elements individually
536 return this.each(function(){
537 // Clone the structure that we're using to wrap
538 var b = a[0].cloneNode(true);
540 // Insert it before the element to be wrapped
541 this.parentNode.insertBefore( b, this );
543 // Find he deepest point in the wrap structure
544 while ( b.firstChild )
547 // Move the matched element to within the wrap structure
548 b.appendChild( this );
553 * Append any number of elements to the inside of every matched elements,
554 * generated from the provided HTML.
555 * This operation is similar to doing an appendChild to all the
556 * specified elements, adding them into the document.
558 * @example $("p").append("<b>Hello</b>");
559 * @before <p>I would like to say: </p>
560 * @result <p>I would like to say: <b>Hello</b></p>
564 * @param String html A string of HTML, that will be created on the fly and appended to the target.
565 * @cat DOM/Manipulation
569 * Append an element to the inside of all matched elements.
570 * This operation is similar to doing an appendChild to all the
571 * specified elements, adding them into the document.
573 * @example $("p").append( $("#foo")[0] );
574 * @before <p>I would like to say: </p><b id="foo">Hello</b>
575 * @result <p>I would like to say: <b id="foo">Hello</b></p>
579 * @param Element elem A DOM element that will be appended.
580 * @cat DOM/Manipulation
584 * Append any number of elements to the inside of all matched elements.
585 * This operation is similar to doing an appendChild to all the
586 * specified elements, adding them into the document.
588 * @example $("p").append( $("b") );
589 * @before <p>I would like to say: </p><b>Hello</b>
590 * @result <p>I would like to say: <b>Hello</b></p>
594 * @param Array<Element> elems An array of elements, all of which will be appended.
595 * @cat DOM/Manipulation
598 return this.domManip(arguments, true, 1, function(a){
599 this.appendChild( a );
604 * Prepend any number of elements to the inside of every matched elements,
605 * generated from the provided HTML.
606 * This operation is the best way to insert dynamically created elements
607 * inside, at the beginning, of all the matched element.
609 * @example $("p").prepend("<b>Hello</b>");
610 * @before <p>I would like to say: </p>
611 * @result <p><b>Hello</b>I would like to say: </p>
615 * @param String html A string of HTML, that will be created on the fly and appended to the target.
616 * @cat DOM/Manipulation
620 * Append an element to the inside of all matched elements.
621 * This operation is the best way to insert an element inside, at the
622 * beginning, of all the matched element.
624 * @example $("p").prepend( $("#foo")[0] );
625 * @before <p>I would like to say: </p><b id="foo">Hello</b>
626 * @result <p><b id="foo">Hello</b>I would like to say: </p>
630 * @param Element elem A DOM element that will be appended.
631 * @cat DOM/Manipulation
635 * Append any number of elements to the inside of all matched elements.
636 * This operation is the best way to insert a set of elements inside, at the
637 * beginning, of all the matched element.
639 * @example $("p").prepend( $("b") );
640 * @before <p>I would like to say: </p><b>Hello</b>
641 * @result <p><b>Hello</b>I would like to say: </p>
645 * @param Array<Element> elems An array of elements, all of which will be appended.
646 * @cat DOM/Manipulation
648 prepend: function() {
649 return this.domManip(arguments, true, -1, function(a){
650 this.insertBefore( a, this.firstChild );
655 * Insert any number of dynamically generated elements before each of the
658 * @example $("p").before("<b>Hello</b>");
659 * @before <p>I would like to say: </p>
660 * @result <b>Hello</b><p>I would like to say: </p>
664 * @param String html A string of HTML, that will be created on the fly and appended to the target.
665 * @cat DOM/Manipulation
669 * Insert an element before each of the matched elements.
671 * @example $("p").before( $("#foo")[0] );
672 * @before <p>I would like to say: </p><b id="foo">Hello</b>
673 * @result <b id="foo">Hello</b><p>I would like to say: </p>
677 * @param Element elem A DOM element that will be appended.
678 * @cat DOM/Manipulation
682 * Insert any number of elements before each of the matched elements.
684 * @example $("p").before( $("b") );
685 * @before <p>I would like to say: </p><b>Hello</b>
686 * @result <b>Hello</b><p>I would like to say: </p>
690 * @param Array<Element> elems An array of elements, all of which will be appended.
691 * @cat DOM/Manipulation
694 return this.domManip(arguments, false, 1, function(a){
695 this.parentNode.insertBefore( a, this );
700 * Insert any number of dynamically generated elements after each of the
703 * @example $("p").after("<b>Hello</b>");
704 * @before <p>I would like to say: </p>
705 * @result <p>I would like to say: </p><b>Hello</b>
709 * @param String html A string of HTML, that will be created on the fly and appended to the target.
710 * @cat DOM/Manipulation
714 * Insert an element after each of the matched elements.
716 * @example $("p").after( $("#foo")[0] );
717 * @before <b id="foo">Hello</b><p>I would like to say: </p>
718 * @result <p>I would like to say: </p><b id="foo">Hello</b>
722 * @param Element elem A DOM element that will be appended.
723 * @cat DOM/Manipulation
727 * Insert any number of elements after each of the matched elements.
729 * @example $("p").after( $("b") );
730 * @before <b>Hello</b><p>I would like to say: </p>
731 * @result <p>I would like to say: </p><b>Hello</b>
735 * @param Array<Element> elems An array of elements, all of which will be appended.
736 * @cat DOM/Manipulation
739 return this.domManip(arguments, false, -1, function(a){
740 this.parentNode.insertBefore( a, this.nextSibling );
745 * End the most recent 'destructive' operation, reverting the list of matched elements
746 * back to its previous state. After an end operation, the list of matched elements will
747 * revert to the last state of matched elements.
749 * @example $("p").find("span").end();
750 * @before <p><span>Hello</span>, how are you?</p>
751 * @result $("p").find("span").end() == [ <p>...</p> ]
755 * @cat DOM/Traversing
758 return this.get( this.stack.pop() );
762 * Searches for all elements that match the specified expression.
763 * This method is the optimal way of finding additional descendant
764 * elements with which to process.
766 * All searching is done using a jQuery expression. The expression can be
767 * written using CSS 1-3 Selector syntax, or basic XPath.
769 * @example $("p").find("span");
770 * @before <p><span>Hello</span>, how are you?</p>
771 * @result $("p").find("span") == [ <span>Hello</span> ]
775 * @param String expr An expression to search with.
776 * @cat DOM/Traversing
779 return this.pushStack( jQuery.map( this, function(a){
780 return jQuery.find(t,a);
784 clone: function(deep) {
785 return this.pushStack( jQuery.map( this, function(a){
786 return a.cloneNode( deep != undefined ? deep : true );
791 * Removes all elements from the set of matched elements that do not
792 * match the specified expression. This method is used to narrow down
793 * the results of a search.
795 * All searching is done using a jQuery expression. The expression
796 * can be written using CSS 1-3 Selector syntax, or basic XPath.
798 * @example $("p").filter(".selected")
799 * @before <p class="selected">Hello</p><p>How are you?</p>
800 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
804 * @param String expr An expression to search with.
805 * @cat DOM/Traversing
809 * Removes all elements from the set of matched elements that do not
810 * match at least one of the expressions passed to the function. This
811 * method is used when you want to filter the set of matched elements
812 * through more than one expression.
814 * Elements will be retained in the jQuery object if they match at
815 * least one of the expressions passed.
817 * @example $("p").filter([".selected", ":first"])
818 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
819 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
823 * @param Array<String> exprs A set of expressions to evaluate against
824 * @cat DOM/Traversing
826 filter: function(t) {
827 return this.pushStack(
828 t.constructor == Array &&
829 jQuery.map(this,function(a){
830 for ( var i = 0; i < t.length; i++ )
831 if ( jQuery.filter(t[i],[a]).r.length )
835 t.constructor == Boolean &&
836 ( t ? this.get() : [] ) ||
838 t.constructor == Function &&
839 jQuery.grep( this, t ) ||
841 jQuery.filter(t,this).r, arguments );
845 * Removes the specified Element from the set of matched elements. This
846 * method is used to remove a single Element from a jQuery object.
848 * @example $("p").not( document.getElementById("selected") )
849 * @before <p>Hello</p><p id="selected">Hello Again</p>
850 * @result [ <p>Hello</p> ]
854 * @param Element el An element to remove from the set
855 * @cat DOM/Traversing
859 * Removes elements matching the specified expression from the set
860 * of matched elements. This method is used to remove one or more
861 * elements from a jQuery object.
863 * @example $("p").not("#selected")
864 * @before <p>Hello</p><p id="selected">Hello Again</p>
865 * @result [ <p>Hello</p> ]
866 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
870 * @param String expr An expression with which to remove matching elements
871 * @cat DOM/Traversing
874 return this.pushStack( t.constructor == String ?
875 jQuery.filter(t,this,false).r :
876 jQuery.grep(this,function(a){ return a != t; }), arguments );
880 * Adds the elements matched by the expression to the jQuery object. This
881 * can be used to concatenate the result sets of two expressions.
883 * @example $("p").add("span")
884 * @before <p>Hello</p><p><span>Hello Again</span></p>
885 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
889 * @param String expr An expression whose matched elements are added
890 * @cat DOM/Traversing
894 * Adds each of the Elements in the array to the set of matched elements.
895 * This is used to add a set of Elements to a jQuery object.
897 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
898 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
899 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
903 * @param Array<Element> els An array of Elements to add
904 * @cat DOM/Traversing
908 * Adds a single Element to the set of matched elements. This is used to
909 * add a single Element to a jQuery object.
911 * @example $("p").add( document.getElementById("a") )
912 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
913 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
917 * @param Element el An Element to add
918 * @cat DOM/Traversing
921 return this.pushStack( jQuery.merge( this, t.constructor == String ?
922 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
926 * A wrapper function for each() to be used by append and prepend.
927 * Handles cases where you're trying to modify the inner contents of
928 * a table, when you actually need to work with the tbody.
931 * @param {String} expr The expression with which to filter
933 * @cat DOM/Traversing
936 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
945 * @param Boolean table
947 * @param Function fn The function doing the DOM manipulation.
951 domManip: function(args, table, dir, fn){
952 var clone = this.size() > 1;
953 var a = jQuery.clean(args);
955 return this.each(function(){
958 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
959 var tbody = this.getElementsByTagName("tbody");
961 if ( !tbody.length ) {
962 obj = document.createElement("tbody");
963 this.appendChild( obj );
968 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
969 i != ( dir < 0 ? dir : a.length ); i += dir ) {
970 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
985 pushStack: function(a,args) {
986 var fn = args && args[args.length-1];
988 if ( !fn || fn.constructor != Function ) {
989 if ( !this.stack ) this.stack = [];
990 this.stack.push( this.get() );
993 var old = this.get();
995 if ( fn.constructor == Function )
1015 * Extend one object with another, returning the original,
1016 * modified, object. This is a great utility for simple inheritance.
1019 * @param Object obj The object to extend
1020 * @param Object prop The object that will be merged into the first.
1024 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1025 if ( !prop ) { prop = obj; obj = this; }
1026 for ( var i in prop ) obj[i] = prop[i];
1038 jQuery.initDone = true;
1040 jQuery.each( jQuery.macros.axis, function(i,n){
1041 jQuery.fn[ i ] = function(a) {
1042 var ret = jQuery.map(this,n);
1043 if ( a && a.constructor == String )
1044 ret = jQuery.filter(a,ret).r;
1045 return this.pushStack( ret, arguments );
1049 jQuery.each( jQuery.macros.to, function(i,n){
1050 jQuery.fn[ i ] = function(){
1052 return this.each(function(){
1053 for ( var j = 0; j < a.length; j++ )
1054 jQuery(a[j])[n]( this );
1059 jQuery.each( jQuery.macros.each, function(i,n){
1060 jQuery.fn[ i ] = function() {
1061 return this.each( n, arguments );
1065 jQuery.each( jQuery.macros.filter, function(i,n){
1066 jQuery.fn[ n ] = function(num,fn) {
1067 return this.filter( ":" + n + "(" + num + ")", fn );
1071 jQuery.each( jQuery.macros.attr, function(i,n){
1073 jQuery.fn[ i ] = function(h) {
1074 return h == undefined ?
1075 this.length ? this[0][n] : null :
1080 jQuery.each( jQuery.macros.css, function(i,n){
1081 jQuery.fn[ n ] = function(h) {
1082 return h == undefined ?
1083 ( this.length ? jQuery.css( this[0], n ) : null ) :
1091 * A generic iterator function, which can be used to seemlessly
1092 * iterate over both objects and arrays.
1095 * @param Object obj The object, or array, to iterate over.
1096 * @param Object fn The function that will be executed on every object.
1100 each: function( obj, fn, args ) {
1101 if ( obj.length == undefined )
1102 for ( var i in obj )
1103 fn.apply( obj[i], args || [i, obj[i]] );
1105 for ( var i = 0; i < obj.length; i++ )
1106 fn.apply( obj[i], args || [i, obj[i]] );
1112 if (jQuery.className.has(o,c)) return;
1113 o.className += ( o.className ? " " : "" ) + c;
1115 remove: function(o,c){
1116 o.className = !c ? "" :
1117 o.className.replace(
1118 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
1120 has: function(e,a) {
1121 if ( e.className != undefined )
1123 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1128 * Swap in/out style options.
1131 swap: function(e,o,f) {
1132 for ( var i in o ) {
1133 e.style["old"+i] = e.style[i];
1138 e.style[i] = e.style["old"+i];
1141 css: function(e,p) {
1142 if ( p == "height" || p == "width" ) {
1143 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1145 for ( var i in d ) {
1146 old["padding" + d[i]] = 0;
1147 old["border" + d[i] + "Width"] = 0;
1150 jQuery.swap( e, old, function() {
1151 if (jQuery.css(e,"display") != "none") {
1152 oHeight = e.offsetHeight;
1153 oWidth = e.offsetWidth;
1155 e = jQuery(e.cloneNode(true)).css({
1156 visibility: "hidden", position: "absolute", display: "block"
1157 }).appendTo(e.parentNode)[0];
1159 oHeight = e.clientHeight;
1160 oWidth = e.clientWidth;
1162 e.parentNode.removeChild(e);
1166 return p == "height" ? oHeight : oWidth;
1167 } else if ( p == "opacity" && jQuery.browser.msie )
1168 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1170 return jQuery.curCSS( e, p );
1173 curCSS: function(elem, prop, force) {
1176 if (!force && elem.style[prop]) {
1178 ret = elem.style[prop];
1180 } else if (elem.currentStyle) {
1182 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
1183 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1185 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1187 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1188 var cur = document.defaultView.getComputedStyle(elem, null);
1191 ret = cur.getPropertyValue(prop);
1192 else if ( prop == 'display' )
1195 jQuery.swap(elem, { display: 'block' }, function() {
1196 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1204 clean: function(a) {
1206 for ( var i = 0; i < a.length; i++ ) {
1207 if ( a[i].constructor == String ) {
1211 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1213 a[i] = "<table>" + a[i] + "</table>";
1214 } else if ( !a[i].indexOf("<tr") ) {
1216 a[i] = "<table>" + a[i] + "</table>";
1217 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1219 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1222 var div = document.createElement("div");
1223 div.innerHTML = a[i];
1226 div = div.firstChild;
1227 if ( table != "thead" ) div = div.firstChild;
1228 if ( table == "td" ) div = div.firstChild;
1231 for ( var j = 0; j < div.childNodes.length; j++ )
1232 r.push( div.childNodes[j] );
1233 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1234 for ( var k = 0; k < a[i].length; k++ )
1236 else if ( a[i] !== null )
1237 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1243 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1244 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1252 last: "i==r.length-1",
1257 "nth-child": "jQuery.sibling(a,m[3]).cur",
1258 "first-child": "jQuery.sibling(a,0).cur",
1259 "last-child": "jQuery.sibling(a,0).last",
1260 "only-child": "jQuery.sibling(a).length==1",
1263 parent: "a.childNodes.length",
1264 empty: "!a.childNodes.length",
1267 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1270 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1271 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1274 enabled: "!a.disabled",
1275 disabled: "a.disabled",
1276 checked: "a.checked",
1277 selected: "a.selected"
1279 ".": "jQuery.className.has(a,m[2])",
1283 "^=": "!z.indexOf(m[4])",
1284 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1285 "*=": "z.indexOf(m[4])>=0",
1288 "[": "jQuery.find(m[2],a).length"
1292 "\\.\\.|/\\.\\.", "a.parentNode",
1293 ">|/", "jQuery.sibling(a.firstChild)",
1294 "\\+", "jQuery.sibling(a).next",
1297 var s = jQuery.sibling(a);
1299 for ( var i = s.n; i < s.length; i++ )
1307 * @test t( "Element Selector", "div", ["main","foo"] );
1308 * @test t( "Element Selector", "body", ["body"] );
1309 * @test t( "Element Selector", "html", ["html"] );
1310 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1311 * @test t( "Parent Element", "div div", ["foo"] );
1313 * @test t( "ID Selector", "#body", ["body"] );
1314 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1315 * @test t( "ID Selector w/ Element", "ul#first", [] );
1317 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1318 * @test t( "Class Selector", ".blog.link", ["simon"] );
1319 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1320 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1322 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1323 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1324 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1325 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1327 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1328 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1329 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1330 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1331 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1332 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1333 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1334 * @test t( "Adjacent", "a + a", ["groups"] );
1335 * @test t( "Adjacent", "a +a", ["groups"] );
1336 * @test t( "Adjacent", "a+ a", ["groups"] );
1337 * @test t( "Adjacent", "a+a", ["groups"] );
1338 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1339 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1340 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1341 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1342 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1343 * @test t( "Attribute Exists", "[@title]", ["google"] );
1344 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1345 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1346 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1347 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1348 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1349 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1351 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1352 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1353 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1354 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1355 * @test t( "Last Child", "p:last-child", ["sap"] );
1356 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1357 * @test t( "Empty", "ul:empty", ["firstUL"] );
1358 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1359 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1360 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1361 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1362 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1363 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1364 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1366 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1367 * @test t( "All Div Elements", "//div", ["main","foo"] );
1368 * @test t( "Absolute Path", "/html/body", ["body"] );
1369 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1370 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1371 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1372 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1373 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1374 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1375 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1376 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1377 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1378 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1379 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1381 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1382 * @test t( "First Element", "p:first", ["firstp"] );
1383 * @test t( "Last Element", "p:last", ["first"] );
1384 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1385 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1386 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1387 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1388 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1389 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1390 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1391 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1394 * @type Array<Element>
1398 find: function( t, context ) {
1399 // Make sure that the context is a DOM Element
1400 if ( context && context.nodeType == undefined )
1403 // Set the correct context (if none is provided)
1404 context = context || jQuery.context || document;
1406 if ( t.constructor != String ) return [t];
1408 if ( !t.indexOf("//") ) {
1409 context = context.documentElement;
1410 t = t.substr(2,t.length);
1411 } else if ( !t.indexOf("/") ) {
1412 context = context.documentElement;
1413 t = t.substr(1,t.length);
1414 // FIX Assume the root element is right :(
1415 if ( t.indexOf("/") >= 1 )
1416 t = t.substr(t.indexOf("/"),t.length);
1419 var ret = [context];
1423 while ( t.length > 0 && last != t ) {
1427 t = jQuery.trim(t).replace( /^\/\//i, "" );
1429 var foundToken = false;
1431 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1432 if ( foundToken ) continue;
1434 var re = new RegExp("^(" + jQuery.token[i] + ")");
1438 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1439 t = jQuery.trim( t.replace( re, "" ) );
1444 if ( !foundToken ) {
1445 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1446 if ( ret[0] == context ) ret.shift();
1447 done = jQuery.merge( done, ret );
1448 r = ret = [context];
1449 t = " " + t.substr(1,t.length);
1451 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1452 var m = re2.exec(t);
1454 if ( m[1] == "#" ) {
1455 // Ummm, should make this work in all XML docs
1456 var oid = document.getElementById(m[2]);
1457 r = ret = oid ? [oid] : [];
1458 t = t.replace( re2, "" );
1460 if ( !m[2] || m[1] == "." ) m[2] = "*";
1462 for ( var i = 0; i < ret.length; i++ )
1463 r = jQuery.merge( r,
1465 jQuery.getAll(ret[i]) :
1466 ret[i].getElementsByTagName(m[2])
1474 var val = jQuery.filter(t,r);
1476 t = jQuery.trim(val.t);
1480 if ( ret && ret[0] == context ) ret.shift();
1481 done = jQuery.merge( done, ret );
1486 getAll: function(o,r) {
1488 var s = o.childNodes;
1489 for ( var i = 0; i < s.length; i++ )
1490 if ( s[i].nodeType == 1 ) {
1492 jQuery.getAll( s[i], r );
1497 attr: function(elem, name, value){
1500 "class": "className",
1501 "float": "cssFloat",
1502 innerHTML: "innerHTML",
1503 className: "className",
1505 disabled: "disabled"
1509 if ( value != undefined ) elem[fix[name]] = value;
1510 return elem[fix[name]];
1511 } else if ( elem.getAttribute ) {
1512 if ( value != undefined ) elem.setAttribute( name, value );
1513 return elem.getAttribute( name, 2 );
1515 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1516 if ( value != undefined ) elem[name] = value;
1521 // The regular expressions that power the parsing engine
1523 // Match: [@value='test'], [@foo]
1524 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1526 // Match: [div], [div p]
1529 // Match: :contains('foo')
1530 [ "(:)S\\(Q\\)", 0 ],
1532 // Match: :even, :last-chlid
1536 filter: function(t,r,not) {
1537 // Figure out if we're doing regular, or inverse, filtering
1538 var g = not !== false ? jQuery.grep :
1539 function(a,f) {return jQuery.grep(a,f,true);};
1541 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1543 var p = jQuery.parse;
1545 for ( var i = 0; i < p.length; i++ ) {
1546 var re = new RegExp( "^" + p[i][0]
1548 // Look for a string-like sequence
1549 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1551 // Look for something (optionally) enclosed with quotes
1552 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1554 var m = re.exec( t );
1557 // Re-organize the match
1559 m = ["", m[1], m[3], m[2], m[4]];
1561 // Remove what we just matched
1562 t = t.replace( re, "" );
1568 // :not() is a special case that can be optomized by
1569 // keeping it out of the expression list
1570 if ( m[1] == ":" && m[2] == "not" )
1571 r = jQuery.filter(m[3],r,false).r;
1573 // Otherwise, find the expression to execute
1575 var f = jQuery.expr[m[1]];
1576 if ( f.constructor != String )
1577 f = jQuery.expr[m[1]][m[2]];
1579 // Build a custom macro to enclose it
1580 eval("f = function(a,i){" +
1581 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1582 "return " + f + "}");
1584 // Execute it against the current filter
1589 // Return an array of filtered elements (r)
1590 // and the modified expression string (t)
1591 return { r: r, t: t };
1595 * Remove the whitespace from the beginning and end of a string.
1599 * @param String str The string to trim.
1603 return t.replace(/^\s+|\s+$/g, "");
1607 * All ancestors of a given element.
1611 * @type Array<Element>
1612 * @param Element elem The element to find the ancestors of.
1613 * @cat DOM/Traversing
1615 parents: function( elem ){
1617 var cur = elem.parentNode;
1618 while ( cur && cur != document ) {
1619 matched.push( cur );
1620 cur = cur.parentNode;
1626 * All elements on a specified axis.
1631 * @param Element elem The element to find all the siblings of (including itself).
1632 * @cat DOM/Traversing
1634 sibling: function(elem, pos, not) {
1637 var siblings = elem.parentNode.childNodes;
1638 for ( var i = 0; i < siblings.length; i++ ) {
1639 if ( not === true && siblings[i] == elem ) continue;
1641 if ( siblings[i].nodeType == 1 )
1642 elems.push( siblings[i] );
1643 if ( siblings[i] == elem )
1644 elems.n = elems.length - 1;
1647 return jQuery.extend( elems, {
1648 last: elems.n == elems.length - 1,
1649 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1650 prev: elems[elems.n - 1],
1651 next: elems[elems.n + 1]
1656 * Merge two arrays together, removing all duplicates.
1660 * @param Array a The first array to merge.
1661 * @param Array b The second array to merge.
1664 merge: function(first, second) {
1667 // Move b over to the new array (this helps to avoid
1668 // StaticNodeList instances)
1669 for ( var k = 0; k < first.length; k++ )
1670 result[k] = first[k];
1672 // Now check for duplicates between a and b and only
1673 // add the unique items
1674 for ( var i = 0; i < second.length; i++ ) {
1675 var noCollision = true;
1677 // The collision-checking process
1678 for ( var j = 0; j < first.length; j++ )
1679 if ( second[i] == first[j] )
1680 noCollision = false;
1682 // If the item is unique, add it
1684 result.push( second[i] );
1691 * Remove items that aren't matched in an array. The function passed
1692 * in to this method will be passed two arguments: 'a' (which is the
1693 * array item) and 'i' (which is the index of the item in the array).
1697 * @param Array array The Array to find items in.
1698 * @param Function fn The function to process each item against.
1699 * @param Boolean inv Invert the selection - select the opposite of the function.
1702 grep: function(elems, fn, inv) {
1703 // If a string is passed in for the function, make a function
1704 // for it (a handy shortcut)
1705 if ( fn.constructor == String )
1706 fn = new Function("a","i","return " + fn);
1710 // Go through the array, only saving the items
1711 // that pass the validator function
1712 for ( var i = 0; i < elems.length; i++ )
1713 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1714 result.push( elems[i] );
1720 * Translate all items in array to another array of items. The translation function
1721 * that is provided to this method is passed one argument: 'a' (the item to be
1722 * translated). If an array is returned, that array is mapped out and merged into
1723 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1724 * from the array. Both of these changes imply that the size of the array may not
1725 * be the same size upon completion, as it was when it started.
1729 * @param Array array The Array to translate.
1730 * @param Function fn The function to process each item against.
1733 map: function(elems, fn) {
1734 // If a string is passed in for the function, make a function
1735 // for it (a handy shortcut)
1736 if ( fn.constructor == String )
1737 fn = new Function("a","return " + fn);
1741 // Go through the array, translating each of the items to their
1742 // new value (or values).
1743 for ( var i = 0; i < elems.length; i++ ) {
1744 var val = fn(elems[i],i);
1746 if ( val !== null && val != undefined ) {
1747 if ( val.constructor != Array ) val = [val];
1748 result = jQuery.merge( result, val );
1756 * A number of helper functions used for managing events.
1757 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1761 // Bind an event to an element
1762 // Original by Dean Edwards
1763 add: function(element, type, handler) {
1764 // For whatever reason, IE has trouble passing the window object
1765 // around, causing it to be cloned in the process
1766 if ( jQuery.browser.msie && element.setInterval != undefined )
1769 // Make sure that the function being executed has a unique ID
1770 if ( !handler.guid )
1771 handler.guid = this.guid++;
1773 // Init the element's event structure
1774 if (!element.events)
1775 element.events = {};
1777 // Get the current list of functions bound to this event
1778 var handlers = element.events[type];
1780 // If it hasn't been initialized yet
1782 // Init the event handler queue
1783 handlers = element.events[type] = {};
1785 // Remember an existing handler, if it's already there
1786 if (element["on" + type])
1787 handlers[0] = element["on" + type];
1790 // Add the function to the element's handler list
1791 handlers[handler.guid] = handler;
1793 // And bind the global event handler to the element
1794 element["on" + type] = this.handle;
1796 // Remember the function in a global list (for triggering)
1797 if (!this.global[type])
1798 this.global[type] = [];
1799 this.global[type].push( element );
1805 // Detach an event or set of events from an element
1806 remove: function(element, type, handler) {
1808 if (type && element.events[type])
1810 delete element.events[type][handler.guid];
1812 for ( var i in element.events[type] )
1813 delete element.events[type][i];
1815 for ( var j in element.events )
1816 this.remove( element, j );
1819 trigger: function(type,data,element) {
1820 // Touch up the incoming data
1823 // Handle a global trigger
1825 var g = this.global[type];
1827 for ( var i = 0; i < g.length; i++ )
1828 this.trigger( type, data, g[i] );
1830 // Handle triggering a single element
1831 } else if ( element["on" + type] ) {
1832 // Pass along a fake event
1833 data.unshift( this.fix({ type: type, target: element }) );
1835 // Trigger the event
1836 element["on" + type].apply( element, data );
1840 handle: function(event) {
1841 if ( typeof jQuery == "undefined" ) return;
1843 event = event || jQuery.event.fix( window.event );
1845 // If no correct event was found, fail
1846 if ( !event ) return;
1848 var returnValue = true;
1850 var c = this.events[event.type];
1852 for ( var j in c ) {
1853 if ( c[j].apply( this, [event] ) === false ) {
1854 event.preventDefault();
1855 event.stopPropagation();
1856 returnValue = false;
1863 fix: function(event) {
1865 event.preventDefault = function() {
1866 this.returnValue = false;
1869 event.stopPropagation = function() {
1870 this.cancelBubble = true;
1881 var b = navigator.userAgent.toLowerCase();
1883 // Figure out what browser is being used
1885 safari: /webkit/.test(b),
1886 opera: /opera/.test(b),
1887 msie: /msie/.test(b) && !/opera/.test(b),
1888 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1891 // Check to see if the W3C box model is being used
1892 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1898 * Append all of the matched elements to another, specified, set of elements.
1899 * This operation is, essentially, the reverse of doing a regular
1900 * $(A).append(B), in that instead of appending B to A, you're appending
1903 * @example $("p").appendTo("#foo");
1904 * @before <p>I would like to say: </p><div id="foo"></div>
1905 * @result <div id="foo"><p>I would like to say: </p></div>
1909 * @param String expr A jQuery expression of elements to match.
1910 * @cat DOM/Manipulation
1915 * Prepend all of the matched elements to another, specified, set of elements.
1916 * This operation is, essentially, the reverse of doing a regular
1917 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1920 * @example $("p").prependTo("#foo");
1921 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1922 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1926 * @param String expr A jQuery expression of elements to match.
1927 * @cat DOM/Manipulation
1929 prependTo: "prepend",
1932 * Insert all of the matched elements before another, specified, set of elements.
1933 * This operation is, essentially, the reverse of doing a regular
1934 * $(A).before(B), in that instead of inserting B before A, you're inserting
1937 * @example $("p").insertBefore("#foo");
1938 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1939 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1941 * @name insertBefore
1943 * @param String expr A jQuery expression of elements to match.
1944 * @cat DOM/Manipulation
1946 insertBefore: "before",
1949 * Insert all of the matched elements after another, specified, set of elements.
1950 * This operation is, essentially, the reverse of doing a regular
1951 * $(A).after(B), in that instead of inserting B after A, you're inserting
1954 * @example $("p").insertAfter("#foo");
1955 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1956 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1960 * @param String expr A jQuery expression of elements to match.
1961 * @cat DOM/Manipulation
1963 insertAfter: "after"
1967 * Get the current CSS width of the first matched element.
1969 * @example $("p").width();
1970 * @before <p>This is just a test.</p>
1979 * Set the CSS width of every matched element. Be sure to include
1980 * the "px" (or other unit of measurement) after the number that you
1981 * specify, otherwise you might get strange results.
1983 * @example $("p").width("20px");
1984 * @before <p>This is just a test.</p>
1985 * @result <p style="width:20px;">This is just a test.</p>
1989 * @param String val Set the CSS property to the specified value.
1994 * Get the current CSS height of the first matched element.
1996 * @example $("p").height();
1997 * @before <p>This is just a test.</p>
2006 * Set the CSS height of every matched element. Be sure to include
2007 * the "px" (or other unit of measurement) after the number that you
2008 * specify, otherwise you might get strange results.
2010 * @example $("p").height("20px");
2011 * @before <p>This is just a test.</p>
2012 * @result <p style="height:20px;">This is just a test.</p>
2016 * @param String val Set the CSS property to the specified value.
2021 * Get the current CSS top of the first matched element.
2023 * @example $("p").top();
2024 * @before <p>This is just a test.</p>
2033 * Set the CSS top of every matched element. Be sure to include
2034 * the "px" (or other unit of measurement) after the number that you
2035 * specify, otherwise you might get strange results.
2037 * @example $("p").top("20px");
2038 * @before <p>This is just a test.</p>
2039 * @result <p style="top:20px;">This is just a test.</p>
2043 * @param String val Set the CSS property to the specified value.
2048 * Get the current CSS left of the first matched element.
2050 * @example $("p").left();
2051 * @before <p>This is just a test.</p>
2060 * Set the CSS left of every matched element. Be sure to include
2061 * the "px" (or other unit of measurement) after the number that you
2062 * specify, otherwise you might get strange results.
2064 * @example $("p").left("20px");
2065 * @before <p>This is just a test.</p>
2066 * @result <p style="left:20px;">This is just a test.</p>
2070 * @param String val Set the CSS property to the specified value.
2075 * Get the current CSS position of the first matched element.
2077 * @example $("p").position();
2078 * @before <p>This is just a test.</p>
2087 * Set the CSS position of every matched element.
2089 * @example $("p").position("relative");
2090 * @before <p>This is just a test.</p>
2091 * @result <p style="position:relative;">This is just a test.</p>
2095 * @param String val Set the CSS property to the specified value.
2100 * Get the current CSS float of the first matched element.
2102 * @example $("p").float();
2103 * @before <p>This is just a test.</p>
2112 * Set the CSS float of every matched element.
2114 * @example $("p").float("left");
2115 * @before <p>This is just a test.</p>
2116 * @result <p style="float:left;">This is just a test.</p>
2120 * @param String val Set the CSS property to the specified value.
2125 * Get the current CSS overflow of the first matched element.
2127 * @example $("p").overflow();
2128 * @before <p>This is just a test.</p>
2137 * Set the CSS overflow of every matched element.
2139 * @example $("p").overflow("auto");
2140 * @before <p>This is just a test.</p>
2141 * @result <p style="overflow:auto;">This is just a test.</p>
2145 * @param String val Set the CSS property to the specified value.
2150 * Get the current CSS color of the first matched element.
2152 * @example $("p").color();
2153 * @before <p>This is just a test.</p>
2162 * Set the CSS color of every matched element.
2164 * @example $("p").color("blue");
2165 * @before <p>This is just a test.</p>
2166 * @result <p style="color:blue;">This is just a test.</p>
2170 * @param String val Set the CSS property to the specified value.
2175 * Get the current CSS background of the first matched element.
2177 * @example $("p").background();
2178 * @before <p>This is just a test.</p>
2187 * Set the CSS background of every matched element.
2189 * @example $("p").background("blue");
2190 * @before <p>This is just a test.</p>
2191 * @result <p style="background:blue;">This is just a test.</p>
2195 * @param String val Set the CSS property to the specified value.
2199 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2201 filter: [ "eq", "lt", "gt", "contains" ],
2205 * Get the current value of the first matched element.
2207 * @example $("input").val();
2208 * @before <input type="text" value="some text"/>
2209 * @result "some text"
2213 * @cat DOM/Attributes
2217 * Set the value of every matched element.
2219 * @example $("input").value("test");
2220 * @before <input type="text" value="some text"/>
2221 * @result <input type="text" value="test"/>
2225 * @param String val Set the property to the specified value.
2226 * @cat DOM/Attributes
2231 * Get the html contents of the first matched element.
2233 * @example $("div").html();
2234 * @before <div><input/></div>
2239 * @cat DOM/Attributes
2243 * Set the html contents of every matched element.
2245 * @example $("div").html("<b>new stuff</b>");
2246 * @before <div><input/></div>
2247 * @result <div><b>new stuff</b></div>
2249 * @test var div = $("div");
2250 * div.html("<b>test</b>");
2252 * for ( var i = 0; i < div.size(); i++ ) {
2253 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2255 * ok( pass, "Set HTML" );
2259 * @param String val Set the html contents to the specified value.
2260 * @cat DOM/Attributes
2265 * Get the current id of the first matched element.
2267 * @example $("input").id();
2268 * @before <input type="text" id="test" value="some text"/>
2273 * @cat DOM/Attributes
2277 * Set the id of every matched element.
2279 * @example $("input").id("newid");
2280 * @before <input type="text" id="test" value="some text"/>
2281 * @result <input type="text" id="newid" value="some text"/>
2285 * @param String val Set the property to the specified value.
2286 * @cat DOM/Attributes
2291 * Get the current title of the first matched element.
2293 * @example $("img").title();
2294 * @before <img src="test.jpg" title="my image"/>
2295 * @result "my image"
2299 * @cat DOM/Attributes
2303 * Set the title of every matched element.
2305 * @example $("img").title("new title");
2306 * @before <img src="test.jpg" title="my image"/>
2307 * @result <img src="test.jpg" title="new image"/>
2311 * @param String val Set the property to the specified value.
2312 * @cat DOM/Attributes
2317 * Get the current name of the first matched element.
2319 * @example $("input").name();
2320 * @before <input type="text" name="username"/>
2321 * @result "username"
2325 * @cat DOM/Attributes
2329 * Set the name of every matched element.
2331 * @example $("input").name("user");
2332 * @before <input type="text" name="username"/>
2333 * @result <input type="text" name="user"/>
2337 * @param String val Set the property to the specified value.
2338 * @cat DOM/Attributes
2343 * Get the current href of the first matched element.
2345 * @example $("a").href();
2346 * @before <a href="test.html">my link</a>
2347 * @result "test.html"
2351 * @cat DOM/Attributes
2355 * Set the href of every matched element.
2357 * @example $("a").href("test2.html");
2358 * @before <a href="test.html">my link</a>
2359 * @result <a href="test2.html">my link</a>
2363 * @param String val Set the property to the specified value.
2364 * @cat DOM/Attributes
2369 * Get the current src of the first matched element.
2371 * @example $("img").src();
2372 * @before <img src="test.jpg" title="my image"/>
2373 * @result "test.jpg"
2377 * @cat DOM/Attributes
2381 * Set the src of every matched element.
2383 * @example $("img").src("test2.jpg");
2384 * @before <img src="test.jpg" title="my image"/>
2385 * @result <img src="test2.jpg" title="my image"/>
2389 * @param String val Set the property to the specified value.
2390 * @cat DOM/Attributes
2395 * Get the current rel of the first matched element.
2397 * @example $("a").rel();
2398 * @before <a href="test.html" rel="nofollow">my link</a>
2399 * @result "nofollow"
2403 * @cat DOM/Attributes
2407 * Set the rel of every matched element.
2409 * @example $("a").rel("nofollow");
2410 * @before <a href="test.html">my link</a>
2411 * @result <a href="test.html" rel="nofollow">my link</a>
2415 * @param String val Set the property to the specified value.
2416 * @cat DOM/Attributes
2423 * Get a set of elements containing the unique parents of the matched
2426 * @example $("p").parent()
2427 * @before <div><p>Hello</p><p>Hello</p></div>
2428 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2432 * @cat DOM/Traversing
2436 * Get a set of elements containing the unique parents of the matched
2437 * set of elements, and filtered by an expression.
2439 * @example $("p").parent(".selected")
2440 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2441 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2445 * @param String expr An expression to filter the parents with
2446 * @cat DOM/Traversing
2448 parent: "a.parentNode",
2451 * Get a set of elements containing the unique ancestors of the matched
2452 * set of elements (except for the root element).
2454 * @example $("span").ancestors()
2455 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2456 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2460 * @cat DOM/Traversing
2464 * Get a set of elements containing the unique ancestors of the matched
2465 * set of elements, and filtered by an expression.
2467 * @example $("span").ancestors("p")
2468 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2469 * @result [ <p><span>Hello</span></p> ]
2473 * @param String expr An expression to filter the ancestors with
2474 * @cat DOM/Traversing
2476 ancestors: jQuery.parents,
2479 * Get a set of elements containing the unique ancestors of the matched
2480 * set of elements (except for the root element).
2482 * @example $("span").ancestors()
2483 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2484 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2488 * @cat DOM/Traversing
2492 * Get a set of elements containing the unique ancestors of the matched
2493 * set of elements, and filtered by an expression.
2495 * @example $("span").ancestors("p")
2496 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2497 * @result [ <p><span>Hello</span></p> ]
2501 * @param String expr An expression to filter the ancestors with
2502 * @cat DOM/Traversing
2504 parents: jQuery.parents,
2507 * Get a set of elements containing the unique next siblings of each of the
2508 * matched set of elements.
2510 * It only returns the very next sibling, not all next siblings.
2512 * @example $("p").next()
2513 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2514 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2518 * @cat DOM/Traversing
2522 * Get a set of elements containing the unique next siblings of each of the
2523 * matched set of elements, and filtered by an expression.
2525 * It only returns the very next sibling, not all next siblings.
2527 * @example $("p").next(".selected")
2528 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2529 * @result [ <p class="selected">Hello Again</p> ]
2533 * @param String expr An expression to filter the next Elements with
2534 * @cat DOM/Traversing
2536 next: "jQuery.sibling(a).next",
2539 * Get a set of elements containing the unique previous siblings of each of the
2540 * matched set of elements.
2542 * It only returns the immediately previous sibling, not all previous siblings.
2544 * @example $("p").previous()
2545 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2546 * @result [ <div><span>Hello Again</span></div> ]
2550 * @cat DOM/Traversing
2554 * Get a set of elements containing the unique previous siblings of each of the
2555 * matched set of elements, and filtered by an expression.
2557 * It only returns the immediately previous sibling, not all previous siblings.
2559 * @example $("p").previous(".selected")
2560 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2561 * @result [ <div><span>Hello</span></div> ]
2565 * @param String expr An expression to filter the previous Elements with
2566 * @cat DOM/Traversing
2568 prev: "jQuery.sibling(a).prev",
2571 * Get a set of elements containing all of the unique siblings of each of the
2572 * matched set of elements.
2574 * @example $("div").siblings()
2575 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2576 * @result [ <p>Hello</p>, <p>And Again</p> ]
2580 * @cat DOM/Traversing
2584 * Get a set of elements containing all of the unique siblings of each of the
2585 * matched set of elements, and filtered by an expression.
2587 * @example $("div").siblings(".selected")
2588 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2589 * @result [ <p class="selected">Hello Again</p> ]
2593 * @param String expr An expression to filter the sibling Elements with
2594 * @cat DOM/Traversing
2596 siblings: jQuery.sibling,
2600 * Get a set of elements containing all of the unique children of each of the
2601 * matched set of elements.
2603 * @example $("div").children()
2604 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2605 * @result [ <span>Hello Again</span> ]
2609 * @cat DOM/Traversing
2613 * Get a set of elements containing all of the unique children of each of the
2614 * matched set of elements, and filtered by an expression.
2616 * @example $("div").children(".selected")
2617 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2618 * @result [ <p class="selected">Hello Again</p> ]
2622 * @param String expr An expression to filter the child Elements with
2623 * @cat DOM/Traversing
2625 children: "jQuery.sibling(a.firstChild)"
2630 removeAttr: function( key ) {
2631 this.removeAttribute( key );
2635 * Displays each of the set of matched elements if they are hidden.
2637 * @example $("p").show()
2638 * @before <p style="display: none">Hello</p>
2639 * @result [ <p style="display: block">Hello</p> ]
2641 * @test var pass = true, div = $("div");
2642 * div.show().each(function(){
2643 * if ( this.style.display == "none" ) pass = false;
2645 * ok( pass, "Show" );
2652 this.style.display = this.oldblock ? this.oldblock : "";
2653 if ( jQuery.css(this,"display") == "none" )
2654 this.style.display = "block";
2658 * Hides each of the set of matched elements if they are shown.
2660 * @example $("p").hide()
2661 * @before <p>Hello</p>
2662 * @result [ <p style="display: none">Hello</p> ]
2664 * var pass = true, div = $("div");
2665 * div.hide().each(function(){
2666 * if ( this.style.display != "none" ) pass = false;
2668 * ok( pass, "Hide" );
2675 this.oldblock = this.oldblock || jQuery.css(this,"display");
2676 if ( this.oldblock == "none" )
2677 this.oldblock = "block";
2678 this.style.display = "none";
2682 * Toggles each of the set of matched elements. If they are shown,
2683 * toggle makes them hidden. If they are hidden, toggle
2686 * @example $("p").toggle()
2687 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2688 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2695 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2699 * Adds the specified class to each of the set of matched elements.
2701 * @example $("p").addClass("selected")
2702 * @before <p>Hello</p>
2703 * @result [ <p class="selected">Hello</p> ]
2705 * @test var div = $("div");
2706 * div.addClass("test");
2708 * for ( var i = 0; i < div.size(); i++ ) {
2709 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2711 * ok( pass, "Add Class" );
2715 * @param String class A CSS class to add to the elements
2718 addClass: function(c){
2719 jQuery.className.add(this,c);
2723 * Removes the specified class from the set of matched elements.
2725 * @example $("p").removeClass("selected")
2726 * @before <p class="selected">Hello</p>
2727 * @result [ <p>Hello</p> ]
2729 * @test var div = $("div").addClass("test");
2730 * div.removeClass("test");
2732 * for ( var i = 0; i < div.size(); i++ ) {
2733 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2735 * ok( pass, "Remove Class" );
2739 * @param String class A CSS class to remove from the elements
2742 removeClass: function(c){
2743 jQuery.className.remove(this,c);
2747 * Adds the specified class if it is present, removes it if it is
2750 * @example $("p").toggleClass("selected")
2751 * @before <p>Hello</p><p class="selected">Hello Again</p>
2752 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2756 * @param String class A CSS class with which to toggle the elements
2759 toggleClass: function( c ){
2760 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2764 * Removes all matched elements from the DOM. This does NOT remove them from the
2765 * jQuery object, allowing you to use the matched elements further.
2767 * @example $("p").remove();
2768 * @before <p>Hello</p> how are <p>you?</p>
2773 * @cat DOM/Manipulation
2777 * Removes only elements (out of the list of matched elements) that match
2778 * the specified jQuery expression. This does NOT remove them from the
2779 * jQuery object, allowing you to use the matched elements further.
2781 * @example $("p").remove(".hello");
2782 * @before <p class="hello">Hello</p> how are <p>you?</p>
2783 * @result how are <p>you?</p>
2787 * @param String expr A jQuery expression to filter elements by.
2788 * @cat DOM/Manipulation
2790 remove: function(a){
2791 if ( !a || jQuery.filter( a, [this] ).r )
2792 this.parentNode.removeChild( this );
2796 * Removes all child nodes from the set of matched elements.
2798 * @example $("p").empty()
2799 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2800 * @result [ <p></p> ]
2804 * @cat DOM/Manipulation
2807 while ( this.firstChild )
2808 this.removeChild( this.firstChild );
2812 * Binds a particular event (like click) to a each of a set of match elements.
2814 * @example $("p").bind( "click", function() { alert("Hello"); } )
2815 * @before <p>Hello</p>
2816 * @result [ <p>Hello</p> ]
2818 * Cancel a default action and prevent it from bubbling by returning false
2819 * from your function.
2821 * @example $("form").bind( "submit", function() { return false; } )
2823 * Cancel a default action by using the preventDefault method.
2825 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2827 * Stop an event from bubbling by using the stopPropogation method.
2829 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2833 * @param String type An event type
2834 * @param Function fn A function to bind to the event on each of the set of matched elements
2837 bind: function( type, fn ) {
2838 if ( fn.constructor == String )
2839 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
2840 jQuery.event.add( this, type, fn );
2844 * The opposite of bind, removes a bound event from each of the matched
2845 * elements. You must pass the identical function that was used in the original
2848 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2849 * @before <p onclick="alert('Hello');">Hello</p>
2850 * @result [ <p>Hello</p> ]
2854 * @param String type An event type
2855 * @param Function fn A function to unbind from the event on each of the set of matched elements
2860 * Removes all bound events of a particular type from each of the matched
2863 * @example $("p").unbind( "click" )
2864 * @before <p onclick="alert('Hello');">Hello</p>
2865 * @result [ <p>Hello</p> ]
2869 * @param String type An event type
2874 * Removes all bound events from each of the matched elements.
2876 * @example $("p").unbind()
2877 * @before <p onclick="alert('Hello');">Hello</p>
2878 * @result [ <p>Hello</p> ]
2884 unbind: function( type, fn ) {
2885 jQuery.event.remove( this, type, fn );
2889 * Trigger a type of event on every matched element.
2891 * @example $("p").trigger("click")
2892 * @before <p click="alert('hello')">Hello</p>
2893 * @result alert('hello')
2897 * @param String type An event type to trigger.
2900 trigger: function( type, data ) {
2901 jQuery.event.trigger( type, data, this );