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.merge( this, [] ) :
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 retrieve 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 retrieve a style property value
421 * from the first matched element.
423 * @example $("p").css("color");
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 * Retrieve 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);
785 * Create cloned copies of all matched DOM Elements. This does
786 * not create a cloned copy of this particular jQuery object,
787 * instead it creates duplicate copies of all DOM Elements.
788 * This is useful for moving copies of the elements to another
789 * location in the DOM.
791 * @example $("b").clone().prependTo("p");
792 * @before <b>Hello</b><p>, how are you?</p>
793 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
797 * @cat DOM/Manipulation
799 clone: function(deep) {
800 return this.pushStack( jQuery.map( this, function(a){
801 return a.cloneNode( deep != undefined ? deep : true );
806 * Removes all elements from the set of matched elements that do not
807 * match the specified expression. This method is used to narrow down
808 * the results of a search.
810 * All searching is done using a jQuery expression. The expression
811 * can be written using CSS 1-3 Selector syntax, or basic XPath.
813 * @example $("p").filter(".selected")
814 * @before <p class="selected">Hello</p><p>How are you?</p>
815 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
819 * @param String expr An expression to search with.
820 * @cat DOM/Traversing
824 * Removes all elements from the set of matched elements that do not
825 * match at least one of the expressions passed to the function. This
826 * method is used when you want to filter the set of matched elements
827 * through more than one expression.
829 * Elements will be retained in the jQuery object if they match at
830 * least one of the expressions passed.
832 * @example $("p").filter([".selected", ":first"])
833 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
834 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
838 * @param Array<String> exprs A set of expressions to evaluate against
839 * @cat DOM/Traversing
841 filter: function(t) {
842 return this.pushStack(
843 t.constructor == Array &&
844 jQuery.map(this,function(a){
845 for ( var i = 0; i < t.length; i++ )
846 if ( jQuery.filter(t[i],[a]).r.length )
850 t.constructor == Boolean &&
851 ( t ? this.get() : [] ) ||
853 t.constructor == Function &&
854 jQuery.grep( this, t ) ||
856 jQuery.filter(t,this).r, arguments );
860 * Removes the specified Element from the set of matched elements. This
861 * method is used to remove a single Element from a jQuery object.
863 * @example $("p").not( document.getElementById("selected") )
864 * @before <p>Hello</p><p id="selected">Hello Again</p>
865 * @result [ <p>Hello</p> ]
869 * @param Element el An element to remove from the set
870 * @cat DOM/Traversing
874 * Removes elements matching the specified expression from the set
875 * of matched elements. This method is used to remove one or more
876 * elements from a jQuery object.
878 * @example $("p").not("#selected")
879 * @before <p>Hello</p><p id="selected">Hello Again</p>
880 * @result [ <p>Hello</p> ]
881 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
885 * @param String expr An expression with which to remove matching elements
886 * @cat DOM/Traversing
889 return this.pushStack( t.constructor == String ?
890 jQuery.filter(t,this,false).r :
891 jQuery.grep(this,function(a){ return a != t; }), arguments );
895 * Adds the elements matched by the expression to the jQuery object. This
896 * can be used to concatenate the result sets of two expressions.
898 * @example $("p").add("span")
899 * @before <p>Hello</p><p><span>Hello Again</span></p>
900 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
904 * @param String expr An expression whose matched elements are added
905 * @cat DOM/Traversing
909 * Adds each of the Elements in the array to the set of matched elements.
910 * This is used to add a set of Elements to a jQuery object.
912 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
913 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
914 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
918 * @param Array<Element> els An array of Elements to add
919 * @cat DOM/Traversing
923 * Adds a single Element to the set of matched elements. This is used to
924 * add a single Element to a jQuery object.
926 * @example $("p").add( document.getElementById("a") )
927 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
928 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
932 * @param Element el An Element to add
933 * @cat DOM/Traversing
936 return this.pushStack( jQuery.merge( this, t.constructor == String ?
937 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
941 * A wrapper function for each() to be used by append and prepend.
942 * Handles cases where you're trying to modify the inner contents of
943 * a table, when you actually need to work with the tbody.
946 * @param {String} expr The expression with which to filter
948 * @cat DOM/Traversing
951 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
960 * @param Boolean table
962 * @param Function fn The function doing the DOM manipulation.
966 domManip: function(args, table, dir, fn){
967 var clone = this.size() > 1;
968 var a = jQuery.clean(args);
970 return this.each(function(){
973 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
974 var tbody = this.getElementsByTagName("tbody");
976 if ( !tbody.length ) {
977 obj = document.createElement("tbody");
978 this.appendChild( obj );
983 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
984 i != ( dir < 0 ? dir : a.length ); i += dir ) {
985 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1000 pushStack: function(a,args) {
1001 var fn = args && args[args.length-1];
1003 if ( !fn || fn.constructor != Function ) {
1004 if ( !this.stack ) this.stack = [];
1005 this.stack.push( this.get() );
1008 var old = this.get();
1010 if ( fn.constructor == Function )
1030 * Extend one object with another, returning the original,
1031 * modified, object. This is a great utility for simple inheritance.
1034 * @param Object obj The object to extend
1035 * @param Object prop The object that will be merged into the first.
1039 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1040 if ( !prop ) { prop = obj; obj = this; }
1041 for ( var i in prop ) obj[i] = prop[i];
1053 jQuery.initDone = true;
1055 jQuery.each( jQuery.macros.axis, function(i,n){
1056 jQuery.fn[ i ] = function(a) {
1057 var ret = jQuery.map(this,n);
1058 if ( a && a.constructor == String )
1059 ret = jQuery.filter(a,ret).r;
1060 return this.pushStack( ret, arguments );
1064 jQuery.each( jQuery.macros.to, function(i,n){
1065 jQuery.fn[ i ] = function(){
1067 return this.each(function(){
1068 for ( var j = 0; j < a.length; j++ )
1069 jQuery(a[j])[n]( this );
1074 jQuery.each( jQuery.macros.each, function(i,n){
1075 jQuery.fn[ i ] = function() {
1076 return this.each( n, arguments );
1080 jQuery.each( jQuery.macros.filter, function(i,n){
1081 jQuery.fn[ n ] = function(num,fn) {
1082 return this.filter( ":" + n + "(" + num + ")", fn );
1086 jQuery.each( jQuery.macros.attr, function(i,n){
1088 jQuery.fn[ i ] = function(h) {
1089 return h == undefined ?
1090 this.length ? this[0][n] : null :
1095 jQuery.each( jQuery.macros.css, function(i,n){
1096 jQuery.fn[ n ] = function(h) {
1097 return h == undefined ?
1098 ( this.length ? jQuery.css( this[0], n ) : null ) :
1106 * A generic iterator function, which can be used to seemlessly
1107 * iterate over both objects and arrays.
1110 * @param Object obj The object, or array, to iterate over.
1111 * @param Object fn The function that will be executed on every object.
1115 each: function( obj, fn, args ) {
1116 if ( obj.length == undefined )
1117 for ( var i in obj )
1118 fn.apply( obj[i], args || [i, obj[i]] );
1120 for ( var i = 0; i < obj.length; i++ )
1121 fn.apply( obj[i], args || [i, obj[i]] );
1127 if (jQuery.className.has(o,c)) return;
1128 o.className += ( o.className ? " " : "" ) + c;
1130 remove: function(o,c){
1131 o.className = !c ? "" :
1132 o.className.replace(
1133 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
1135 has: function(e,a) {
1136 if ( e.className != undefined )
1138 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1143 * Swap in/out style options.
1146 swap: function(e,o,f) {
1147 for ( var i in o ) {
1148 e.style["old"+i] = e.style[i];
1153 e.style[i] = e.style["old"+i];
1156 css: function(e,p) {
1157 if ( p == "height" || p == "width" ) {
1158 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1160 for ( var i in d ) {
1161 old["padding" + d[i]] = 0;
1162 old["border" + d[i] + "Width"] = 0;
1165 jQuery.swap( e, old, function() {
1166 if (jQuery.css(e,"display") != "none") {
1167 oHeight = e.offsetHeight;
1168 oWidth = e.offsetWidth;
1170 e = jQuery(e.cloneNode(true)).css({
1171 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1172 }).appendTo(e.parentNode)[0];
1174 var parPos = jQuery.css(e.parentNode,"position");
1175 if ( parPos == "" || parPos == "static" )
1176 e.parentNode.style.position = "relative";
1178 oHeight = e.clientHeight;
1179 oWidth = e.clientWidth;
1181 if ( parPos == "" || parPos == "static" )
1182 e.parentNode.style.position = "static";
1184 e.parentNode.removeChild(e);
1188 return p == "height" ? oHeight : oWidth;
1189 } else if ( p == "opacity" && jQuery.browser.msie )
1190 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1192 return jQuery.curCSS( e, p );
1195 curCSS: function(elem, prop, force) {
1198 if (!force && elem.style[prop]) {
1200 ret = elem.style[prop];
1202 } else if (elem.currentStyle) {
1204 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1205 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1207 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1209 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1210 var cur = document.defaultView.getComputedStyle(elem, null);
1213 ret = cur.getPropertyValue(prop);
1214 else if ( prop == 'display' )
1217 jQuery.swap(elem, { display: 'block' }, function() {
1218 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1226 clean: function(a) {
1228 for ( var i = 0; i < a.length; i++ ) {
1229 if ( a[i].constructor == String ) {
1233 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1235 a[i] = "<table>" + a[i] + "</table>";
1236 } else if ( !a[i].indexOf("<tr") ) {
1238 a[i] = "<table>" + a[i] + "</table>";
1239 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1241 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1244 var div = document.createElement("div");
1245 div.innerHTML = a[i];
1248 div = div.firstChild;
1249 if ( table != "thead" ) div = div.firstChild;
1250 if ( table == "td" ) div = div.firstChild;
1253 for ( var j = 0; j < div.childNodes.length; j++ )
1254 r.push( div.childNodes[j] );
1255 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1256 for ( var k = 0; k < a[i].length; k++ )
1258 else if ( a[i] !== null )
1259 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1265 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1266 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1274 last: "i==r.length-1",
1279 "nth-child": "jQuery.sibling(a,m[3]).cur",
1280 "first-child": "jQuery.sibling(a,0).cur",
1281 "last-child": "jQuery.sibling(a,0).last",
1282 "only-child": "jQuery.sibling(a).length==1",
1285 parent: "a.childNodes.length",
1286 empty: "!a.childNodes.length",
1289 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1292 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1293 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1296 enabled: "!a.disabled",
1297 disabled: "a.disabled",
1298 checked: "a.checked",
1299 selected: "a.selected"
1301 ".": "jQuery.className.has(a,m[2])",
1305 "^=": "!z.indexOf(m[4])",
1306 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1307 "*=": "z.indexOf(m[4])>=0",
1310 "[": "jQuery.find(m[2],a).length"
1314 "\\.\\.|/\\.\\.", "a.parentNode",
1315 ">|/", "jQuery.sibling(a.firstChild)",
1316 "\\+", "jQuery.sibling(a).next",
1319 var s = jQuery.sibling(a);
1321 for ( var i = s.n; i < s.length; i++ )
1329 * @test t( "Element Selector", "div", ["main","foo"] );
1330 * @test t( "Element Selector", "body", ["body"] );
1331 * @test t( "Element Selector", "html", ["html"] );
1332 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1333 * @test t( "Parent Element", "div div", ["foo"] );
1335 * @test t( "ID Selector", "#body", ["body"] );
1336 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1337 * @test t( "ID Selector w/ Element", "ul#first", [] );
1339 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1340 * @test t( "Class Selector", ".blog.link", ["simon"] );
1341 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1342 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1344 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1345 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1346 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1347 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1349 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1350 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1351 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1352 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1353 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1354 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1355 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1356 * @test t( "Adjacent", "a + a", ["groups"] );
1357 * @test t( "Adjacent", "a +a", ["groups"] );
1358 * @test t( "Adjacent", "a+ a", ["groups"] );
1359 * @test t( "Adjacent", "a+a", ["groups"] );
1360 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1361 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1362 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1363 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1364 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1365 * @test t( "Attribute Exists", "[@title]", ["google"] );
1366 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1367 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1368 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1369 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1370 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1371 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1373 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1374 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1375 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1376 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1377 * @test t( "Last Child", "p:last-child", ["sap"] );
1378 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1379 * @test t( "Empty", "ul:empty", ["firstUL"] );
1380 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1381 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1382 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1383 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1384 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1385 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1386 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1388 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1389 * @test t( "All Div Elements", "//div", ["main","foo"] );
1390 * @test t( "Absolute Path", "/html/body", ["body"] );
1391 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1392 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1393 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1394 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1395 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1396 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1397 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1398 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1399 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1400 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1401 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1403 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1404 * @test t( "First Element", "p:first", ["firstp"] );
1405 * @test t( "Last Element", "p:last", ["first"] );
1406 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1407 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1408 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1409 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1410 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1411 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1412 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1413 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1416 * @type Array<Element>
1420 find: function( t, context ) {
1421 // Make sure that the context is a DOM Element
1422 if ( context && context.nodeType == undefined )
1425 // Set the correct context (if none is provided)
1426 context = context || jQuery.context || document;
1428 if ( t.constructor != String ) return [t];
1430 if ( !t.indexOf("//") ) {
1431 context = context.documentElement;
1432 t = t.substr(2,t.length);
1433 } else if ( !t.indexOf("/") ) {
1434 context = context.documentElement;
1435 t = t.substr(1,t.length);
1436 // FIX Assume the root element is right :(
1437 if ( t.indexOf("/") >= 1 )
1438 t = t.substr(t.indexOf("/"),t.length);
1441 var ret = [context];
1445 while ( t.length > 0 && last != t ) {
1449 t = jQuery.trim(t).replace( /^\/\//i, "" );
1451 var foundToken = false;
1453 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1454 if ( foundToken ) continue;
1456 var re = new RegExp("^(" + jQuery.token[i] + ")");
1460 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1461 t = jQuery.trim( t.replace( re, "" ) );
1466 if ( !foundToken ) {
1467 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1468 if ( ret[0] == context ) ret.shift();
1469 done = jQuery.merge( done, ret );
1470 r = ret = [context];
1471 t = " " + t.substr(1,t.length);
1473 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1474 var m = re2.exec(t);
1476 if ( m[1] == "#" ) {
1477 // Ummm, should make this work in all XML docs
1478 var oid = document.getElementById(m[2]);
1479 r = ret = oid ? [oid] : [];
1480 t = t.replace( re2, "" );
1482 if ( !m[2] || m[1] == "." ) m[2] = "*";
1484 for ( var i = 0; i < ret.length; i++ )
1485 r = jQuery.merge( r,
1487 jQuery.getAll(ret[i]) :
1488 ret[i].getElementsByTagName(m[2])
1496 var val = jQuery.filter(t,r);
1498 t = jQuery.trim(val.t);
1502 if ( ret && ret[0] == context ) ret.shift();
1503 done = jQuery.merge( done, ret );
1508 getAll: function(o,r) {
1510 var s = o.childNodes;
1511 for ( var i = 0; i < s.length; i++ )
1512 if ( s[i].nodeType == 1 ) {
1514 jQuery.getAll( s[i], r );
1519 attr: function(elem, name, value){
1522 "class": "className",
1523 "float": "cssFloat",
1524 innerHTML: "innerHTML",
1525 className: "className",
1527 disabled: "disabled",
1532 if ( value != undefined ) elem[fix[name]] = value;
1533 return elem[fix[name]];
1534 } else if ( elem.getAttribute ) {
1535 if ( value != undefined ) elem.setAttribute( name, value );
1536 return elem.getAttribute( name, 2 );
1538 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1539 if ( value != undefined ) elem[name] = value;
1544 // The regular expressions that power the parsing engine
1546 // Match: [@value='test'], [@foo]
1547 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1549 // Match: [div], [div p]
1552 // Match: :contains('foo')
1553 [ "(:)S\\(Q\\)", 0 ],
1555 // Match: :even, :last-chlid
1559 filter: function(t,r,not) {
1560 // Figure out if we're doing regular, or inverse, filtering
1561 var g = not !== false ? jQuery.grep :
1562 function(a,f) {return jQuery.grep(a,f,true);};
1564 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1566 var p = jQuery.parse;
1568 for ( var i = 0; i < p.length; i++ ) {
1569 var re = new RegExp( "^" + p[i][0]
1571 // Look for a string-like sequence
1572 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1574 // Look for something (optionally) enclosed with quotes
1575 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1577 var m = re.exec( t );
1580 // Re-organize the match
1582 m = ["", m[1], m[3], m[2], m[4]];
1584 // Remove what we just matched
1585 t = t.replace( re, "" );
1591 // :not() is a special case that can be optomized by
1592 // keeping it out of the expression list
1593 if ( m[1] == ":" && m[2] == "not" )
1594 r = jQuery.filter(m[3],r,false).r;
1596 // Otherwise, find the expression to execute
1598 var f = jQuery.expr[m[1]];
1599 if ( f.constructor != String )
1600 f = jQuery.expr[m[1]][m[2]];
1602 // Build a custom macro to enclose it
1603 eval("f = function(a,i){" +
1604 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1605 "return " + f + "}");
1607 // Execute it against the current filter
1612 // Return an array of filtered elements (r)
1613 // and the modified expression string (t)
1614 return { r: r, t: t };
1618 * Remove the whitespace from the beginning and end of a string.
1622 * @param String str The string to trim.
1626 return t.replace(/^\s+|\s+$/g, "");
1630 * All ancestors of a given element.
1634 * @type Array<Element>
1635 * @param Element elem The element to find the ancestors of.
1636 * @cat DOM/Traversing
1638 parents: function( elem ){
1640 var cur = elem.parentNode;
1641 while ( cur && cur != document ) {
1642 matched.push( cur );
1643 cur = cur.parentNode;
1649 * All elements on a specified axis.
1654 * @param Element elem The element to find all the siblings of (including itself).
1655 * @cat DOM/Traversing
1657 sibling: function(elem, pos, not) {
1660 var siblings = elem.parentNode.childNodes;
1661 for ( var i = 0; i < siblings.length; i++ ) {
1662 if ( not === true && siblings[i] == elem ) continue;
1664 if ( siblings[i].nodeType == 1 )
1665 elems.push( siblings[i] );
1666 if ( siblings[i] == elem )
1667 elems.n = elems.length - 1;
1670 return jQuery.extend( elems, {
1671 last: elems.n == elems.length - 1,
1672 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1673 prev: elems[elems.n - 1],
1674 next: elems[elems.n + 1]
1679 * Merge two arrays together, removing all duplicates.
1683 * @param Array a The first array to merge.
1684 * @param Array b The second array to merge.
1687 merge: function(first, second) {
1690 // Move b over to the new array (this helps to avoid
1691 // StaticNodeList instances)
1692 for ( var k = 0; k < first.length; k++ )
1693 result[k] = first[k];
1695 // Now check for duplicates between a and b and only
1696 // add the unique items
1697 for ( var i = 0; i < second.length; i++ ) {
1698 var noCollision = true;
1700 // The collision-checking process
1701 for ( var j = 0; j < first.length; j++ )
1702 if ( second[i] == first[j] )
1703 noCollision = false;
1705 // If the item is unique, add it
1707 result.push( second[i] );
1714 * Remove items that aren't matched in an array. The function passed
1715 * in to this method will be passed two arguments: 'a' (which is the
1716 * array item) and 'i' (which is the index of the item in the array).
1720 * @param Array array The Array to find items in.
1721 * @param Function fn The function to process each item against.
1722 * @param Boolean inv Invert the selection - select the opposite of the function.
1725 grep: function(elems, fn, inv) {
1726 // If a string is passed in for the function, make a function
1727 // for it (a handy shortcut)
1728 if ( fn.constructor == String )
1729 fn = new Function("a","i","return " + fn);
1733 // Go through the array, only saving the items
1734 // that pass the validator function
1735 for ( var i = 0; i < elems.length; i++ )
1736 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1737 result.push( elems[i] );
1743 * Translate all items in array to another array of items. The translation function
1744 * that is provided to this method is passed one argument: 'a' (the item to be
1745 * translated). If an array is returned, that array is mapped out and merged into
1746 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1747 * from the array. Both of these changes imply that the size of the array may not
1748 * be the same size upon completion, as it was when it started.
1752 * @param Array array The Array to translate.
1753 * @param Function fn The function to process each item against.
1756 map: function(elems, fn) {
1757 // If a string is passed in for the function, make a function
1758 // for it (a handy shortcut)
1759 if ( fn.constructor == String )
1760 fn = new Function("a","return " + fn);
1764 // Go through the array, translating each of the items to their
1765 // new value (or values).
1766 for ( var i = 0; i < elems.length; i++ ) {
1767 var val = fn(elems[i],i);
1769 if ( val !== null && val != undefined ) {
1770 if ( val.constructor != Array ) val = [val];
1771 result = jQuery.merge( result, val );
1779 * A number of helper functions used for managing events.
1780 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1784 // Bind an event to an element
1785 // Original by Dean Edwards
1786 add: function(element, type, handler) {
1787 // For whatever reason, IE has trouble passing the window object
1788 // around, causing it to be cloned in the process
1789 if ( jQuery.browser.msie && element.setInterval != undefined )
1792 // Make sure that the function being executed has a unique ID
1793 if ( !handler.guid )
1794 handler.guid = this.guid++;
1796 // Init the element's event structure
1797 if (!element.events)
1798 element.events = {};
1800 // Get the current list of functions bound to this event
1801 var handlers = element.events[type];
1803 // If it hasn't been initialized yet
1805 // Init the event handler queue
1806 handlers = element.events[type] = {};
1808 // Remember an existing handler, if it's already there
1809 if (element["on" + type])
1810 handlers[0] = element["on" + type];
1813 // Add the function to the element's handler list
1814 handlers[handler.guid] = handler;
1816 // And bind the global event handler to the element
1817 element["on" + type] = this.handle;
1819 // Remember the function in a global list (for triggering)
1820 if (!this.global[type])
1821 this.global[type] = [];
1822 this.global[type].push( element );
1828 // Detach an event or set of events from an element
1829 remove: function(element, type, handler) {
1831 if (type && element.events[type])
1833 delete element.events[type][handler.guid];
1835 for ( var i in element.events[type] )
1836 delete element.events[type][i];
1838 for ( var j in element.events )
1839 this.remove( element, j );
1842 trigger: function(type,data,element) {
1843 // Touch up the incoming data
1846 // Handle a global trigger
1848 var g = this.global[type];
1850 for ( var i = 0; i < g.length; i++ )
1851 this.trigger( type, data, g[i] );
1853 // Handle triggering a single element
1854 } else if ( element["on" + type] ) {
1855 // Pass along a fake event
1856 data.unshift( this.fix({ type: type, target: element }) );
1858 // Trigger the event
1859 element["on" + type].apply( element, data );
1863 handle: function(event) {
1864 if ( typeof jQuery == "undefined" ) return;
1866 event = event || jQuery.event.fix( window.event );
1868 // If no correct event was found, fail
1869 if ( !event ) return;
1871 var returnValue = true;
1873 var c = this.events[event.type];
1875 for ( var j in c ) {
1876 if ( c[j].apply( this, [event] ) === false ) {
1877 event.preventDefault();
1878 event.stopPropagation();
1879 returnValue = false;
1886 fix: function(event) {
1888 event.preventDefault = function() {
1889 this.returnValue = false;
1892 event.stopPropagation = function() {
1893 this.cancelBubble = true;
1904 var b = navigator.userAgent.toLowerCase();
1906 // Figure out what browser is being used
1908 safari: /webkit/.test(b),
1909 opera: /opera/.test(b),
1910 msie: /msie/.test(b) && !/opera/.test(b),
1911 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1914 // Check to see if the W3C box model is being used
1915 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1921 * Append all of the matched elements to another, specified, set of elements.
1922 * This operation is, essentially, the reverse of doing a regular
1923 * $(A).append(B), in that instead of appending B to A, you're appending
1926 * @example $("p").appendTo("#foo");
1927 * @before <p>I would like to say: </p><div id="foo"></div>
1928 * @result <div id="foo"><p>I would like to say: </p></div>
1932 * @param String expr A jQuery expression of elements to match.
1933 * @cat DOM/Manipulation
1938 * Prepend all of the matched elements to another, specified, set of elements.
1939 * This operation is, essentially, the reverse of doing a regular
1940 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1943 * @example $("p").prependTo("#foo");
1944 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1945 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1949 * @param String expr A jQuery expression of elements to match.
1950 * @cat DOM/Manipulation
1952 prependTo: "prepend",
1955 * Insert all of the matched elements before another, specified, set of elements.
1956 * This operation is, essentially, the reverse of doing a regular
1957 * $(A).before(B), in that instead of inserting B before A, you're inserting
1960 * @example $("p").insertBefore("#foo");
1961 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1962 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1964 * @name insertBefore
1966 * @param String expr A jQuery expression of elements to match.
1967 * @cat DOM/Manipulation
1969 insertBefore: "before",
1972 * Insert all of the matched elements after another, specified, set of elements.
1973 * This operation is, essentially, the reverse of doing a regular
1974 * $(A).after(B), in that instead of inserting B after A, you're inserting
1977 * @example $("p").insertAfter("#foo");
1978 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1979 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1983 * @param String expr A jQuery expression of elements to match.
1984 * @cat DOM/Manipulation
1986 insertAfter: "after"
1990 * Get the current CSS width of the first matched element.
1992 * @example $("p").width();
1993 * @before <p>This is just a test.</p>
2002 * Set the CSS width of every matched element. Be sure to include
2003 * the "px" (or other unit of measurement) after the number that you
2004 * specify, otherwise you might get strange results.
2006 * @example $("p").width("20px");
2007 * @before <p>This is just a test.</p>
2008 * @result <p style="width:20px;">This is just a test.</p>
2012 * @param String val Set the CSS property to the specified value.
2017 * Get the current CSS height of the first matched element.
2019 * @example $("p").height();
2020 * @before <p>This is just a test.</p>
2029 * Set the CSS height of every matched element. Be sure to include
2030 * the "px" (or other unit of measurement) after the number that you
2031 * specify, otherwise you might get strange results.
2033 * @example $("p").height("20px");
2034 * @before <p>This is just a test.</p>
2035 * @result <p style="height:20px;">This is just a test.</p>
2039 * @param String val Set the CSS property to the specified value.
2044 * Get the current CSS top of the first matched element.
2046 * @example $("p").top();
2047 * @before <p>This is just a test.</p>
2056 * Set the CSS top of every matched element. Be sure to include
2057 * the "px" (or other unit of measurement) after the number that you
2058 * specify, otherwise you might get strange results.
2060 * @example $("p").top("20px");
2061 * @before <p>This is just a test.</p>
2062 * @result <p style="top:20px;">This is just a test.</p>
2066 * @param String val Set the CSS property to the specified value.
2071 * Get the current CSS left of the first matched element.
2073 * @example $("p").left();
2074 * @before <p>This is just a test.</p>
2083 * Set the CSS left of every matched element. Be sure to include
2084 * the "px" (or other unit of measurement) after the number that you
2085 * specify, otherwise you might get strange results.
2087 * @example $("p").left("20px");
2088 * @before <p>This is just a test.</p>
2089 * @result <p style="left:20px;">This is just a test.</p>
2093 * @param String val Set the CSS property to the specified value.
2098 * Get the current CSS position of the first matched element.
2100 * @example $("p").position();
2101 * @before <p>This is just a test.</p>
2110 * Set the CSS position of every matched element.
2112 * @example $("p").position("relative");
2113 * @before <p>This is just a test.</p>
2114 * @result <p style="position:relative;">This is just a test.</p>
2118 * @param String val Set the CSS property to the specified value.
2123 * Get the current CSS float of the first matched element.
2125 * @example $("p").float();
2126 * @before <p>This is just a test.</p>
2135 * Set the CSS float of every matched element.
2137 * @example $("p").float("left");
2138 * @before <p>This is just a test.</p>
2139 * @result <p style="float:left;">This is just a test.</p>
2143 * @param String val Set the CSS property to the specified value.
2148 * Get the current CSS overflow of the first matched element.
2150 * @example $("p").overflow();
2151 * @before <p>This is just a test.</p>
2160 * Set the CSS overflow of every matched element.
2162 * @example $("p").overflow("auto");
2163 * @before <p>This is just a test.</p>
2164 * @result <p style="overflow:auto;">This is just a test.</p>
2168 * @param String val Set the CSS property to the specified value.
2173 * Get the current CSS color of the first matched element.
2175 * @example $("p").color();
2176 * @before <p>This is just a test.</p>
2185 * Set the CSS color of every matched element.
2187 * @example $("p").color("blue");
2188 * @before <p>This is just a test.</p>
2189 * @result <p style="color:blue;">This is just a test.</p>
2193 * @param String val Set the CSS property to the specified value.
2198 * Get the current CSS background of the first matched element.
2200 * @example $("p").background();
2201 * @before <p style="background:blue;">This is just a test.</p>
2210 * Set the CSS background of every matched element.
2212 * @example $("p").background("blue");
2213 * @before <p>This is just a test.</p>
2214 * @result <p style="background:blue;">This is just a test.</p>
2218 * @param String val Set the CSS property to the specified value.
2222 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2225 * Reduce the set of matched elements to a single element.
2226 * The position of the element in the set of matched elements
2227 * starts at 0 and goes to length - 1.
2229 * @example $("p").eq(1)
2230 * @before <p>This is just a test.</p><p>So is this</p>
2231 * @result [ <p>So is this</p> ]
2235 * @param Number pos The index of the element that you wish to limit to.
2240 * Reduce the set of matched elements to all elements before a given position.
2241 * The position of the element in the set of matched elements
2242 * starts at 0 and goes to length - 1.
2244 * @example $("p").lt(1)
2245 * @before <p>This is just a test.</p><p>So is this</p>
2246 * @result [ <p>This is just a test.</p> ]
2250 * @param Number pos Reduce the set to all elements below this position.
2255 * Reduce the set of matched elements to all elements after a given position.
2256 * The position of the element in the set of matched elements
2257 * starts at 0 and goes to length - 1.
2259 * @example $("p").gt(0)
2260 * @before <p>This is just a test.</p><p>So is this</p>
2261 * @result [ <p>So is this</p> ]
2265 * @param Number pos Reduce the set to all elements after this position.
2270 * Filter the set of elements to those that contain the specified text.
2272 * @example $("p").contains("test")
2273 * @before <p>This is just a test.</p><p>So is this</p>
2274 * @result [ <p>This is just a test.</p> ]
2278 * @param String str The string that will be contained within the text of an element.
2279 * @cat DOM/Traversing
2282 filter: [ "eq", "lt", "gt", "contains" ],
2286 * Get the current value of the first matched element.
2288 * @example $("input").val();
2289 * @before <input type="text" value="some text"/>
2290 * @result "some text"
2294 * @cat DOM/Attributes
2298 * Set the value of every matched element.
2300 * @example $("input").value("test");
2301 * @before <input type="text" value="some text"/>
2302 * @result <input type="text" value="test"/>
2306 * @param String val Set the property to the specified value.
2307 * @cat DOM/Attributes
2312 * Get the html contents of the first matched element.
2314 * @example $("div").html();
2315 * @before <div><input/></div>
2320 * @cat DOM/Attributes
2324 * Set the html contents of every matched element.
2326 * @example $("div").html("<b>new stuff</b>");
2327 * @before <div><input/></div>
2328 * @result <div><b>new stuff</b></div>
2330 * @test var div = $("div");
2331 * div.html("<b>test</b>");
2333 * for ( var i = 0; i < div.size(); i++ ) {
2334 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2336 * ok( pass, "Set HTML" );
2340 * @param String val Set the html contents to the specified value.
2341 * @cat DOM/Attributes
2346 * Get the current id of the first matched element.
2348 * @example $("input").id();
2349 * @before <input type="text" id="test" value="some text"/>
2354 * @cat DOM/Attributes
2358 * Set the id of every matched element.
2360 * @example $("input").id("newid");
2361 * @before <input type="text" id="test" value="some text"/>
2362 * @result <input type="text" id="newid" value="some text"/>
2366 * @param String val Set the property to the specified value.
2367 * @cat DOM/Attributes
2372 * Get the current title of the first matched element.
2374 * @example $("img").title();
2375 * @before <img src="test.jpg" title="my image"/>
2376 * @result "my image"
2380 * @cat DOM/Attributes
2384 * Set the title of every matched element.
2386 * @example $("img").title("new title");
2387 * @before <img src="test.jpg" title="my image"/>
2388 * @result <img src="test.jpg" title="new image"/>
2392 * @param String val Set the property to the specified value.
2393 * @cat DOM/Attributes
2398 * Get the current name of the first matched element.
2400 * @example $("input").name();
2401 * @before <input type="text" name="username"/>
2402 * @result "username"
2406 * @cat DOM/Attributes
2410 * Set the name of every matched element.
2412 * @example $("input").name("user");
2413 * @before <input type="text" name="username"/>
2414 * @result <input type="text" name="user"/>
2418 * @param String val Set the property to the specified value.
2419 * @cat DOM/Attributes
2424 * Get the current href of the first matched element.
2426 * @example $("a").href();
2427 * @before <a href="test.html">my link</a>
2428 * @result "test.html"
2432 * @cat DOM/Attributes
2436 * Set the href of every matched element.
2438 * @example $("a").href("test2.html");
2439 * @before <a href="test.html">my link</a>
2440 * @result <a href="test2.html">my link</a>
2444 * @param String val Set the property to the specified value.
2445 * @cat DOM/Attributes
2450 * Get the current src of the first matched element.
2452 * @example $("img").src();
2453 * @before <img src="test.jpg" title="my image"/>
2454 * @result "test.jpg"
2458 * @cat DOM/Attributes
2462 * Set the src of every matched element.
2464 * @example $("img").src("test2.jpg");
2465 * @before <img src="test.jpg" title="my image"/>
2466 * @result <img src="test2.jpg" title="my image"/>
2470 * @param String val Set the property to the specified value.
2471 * @cat DOM/Attributes
2476 * Get the current rel of the first matched element.
2478 * @example $("a").rel();
2479 * @before <a href="test.html" rel="nofollow">my link</a>
2480 * @result "nofollow"
2484 * @cat DOM/Attributes
2488 * Set the rel of every matched element.
2490 * @example $("a").rel("nofollow");
2491 * @before <a href="test.html">my link</a>
2492 * @result <a href="test.html" rel="nofollow">my link</a>
2496 * @param String val Set the property to the specified value.
2497 * @cat DOM/Attributes
2504 * Get a set of elements containing the unique parents of the matched
2507 * @example $("p").parent()
2508 * @before <div><p>Hello</p><p>Hello</p></div>
2509 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2513 * @cat DOM/Traversing
2517 * Get a set of elements containing the unique parents of the matched
2518 * set of elements, and filtered by an expression.
2520 * @example $("p").parent(".selected")
2521 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2522 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2526 * @param String expr An expression to filter the parents with
2527 * @cat DOM/Traversing
2529 parent: "a.parentNode",
2532 * Get a set of elements containing the unique ancestors of the matched
2533 * set of elements (except for the root element).
2535 * @example $("span").ancestors()
2536 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2537 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2541 * @cat DOM/Traversing
2545 * Get a set of elements containing the unique ancestors of the matched
2546 * set of elements, and filtered by an expression.
2548 * @example $("span").ancestors("p")
2549 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2550 * @result [ <p><span>Hello</span></p> ]
2554 * @param String expr An expression to filter the ancestors with
2555 * @cat DOM/Traversing
2557 ancestors: jQuery.parents,
2560 * Get a set of elements containing the unique ancestors of the matched
2561 * set of elements (except for the root element).
2563 * @example $("span").ancestors()
2564 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2565 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2569 * @cat DOM/Traversing
2573 * Get a set of elements containing the unique ancestors of the matched
2574 * set of elements, and filtered by an expression.
2576 * @example $("span").ancestors("p")
2577 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2578 * @result [ <p><span>Hello</span></p> ]
2582 * @param String expr An expression to filter the ancestors with
2583 * @cat DOM/Traversing
2585 parents: jQuery.parents,
2588 * Get a set of elements containing the unique next siblings of each of the
2589 * matched set of elements.
2591 * It only returns the very next sibling, not all next siblings.
2593 * @example $("p").next()
2594 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2595 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2599 * @cat DOM/Traversing
2603 * Get a set of elements containing the unique next siblings of each of the
2604 * matched set of elements, and filtered by an expression.
2606 * It only returns the very next sibling, not all next siblings.
2608 * @example $("p").next(".selected")
2609 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2610 * @result [ <p class="selected">Hello Again</p> ]
2614 * @param String expr An expression to filter the next Elements with
2615 * @cat DOM/Traversing
2617 next: "jQuery.sibling(a).next",
2620 * Get a set of elements containing the unique previous siblings of each of the
2621 * matched set of elements.
2623 * It only returns the immediately previous sibling, not all previous siblings.
2625 * @example $("p").previous()
2626 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2627 * @result [ <div><span>Hello Again</span></div> ]
2631 * @cat DOM/Traversing
2635 * Get a set of elements containing the unique previous siblings of each of the
2636 * matched set of elements, and filtered by an expression.
2638 * It only returns the immediately previous sibling, not all previous siblings.
2640 * @example $("p").previous(".selected")
2641 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2642 * @result [ <div><span>Hello</span></div> ]
2646 * @param String expr An expression to filter the previous Elements with
2647 * @cat DOM/Traversing
2649 prev: "jQuery.sibling(a).prev",
2652 * Get a set of elements containing all of the unique siblings of each of the
2653 * matched set of elements.
2655 * @example $("div").siblings()
2656 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2657 * @result [ <p>Hello</p>, <p>And Again</p> ]
2661 * @cat DOM/Traversing
2665 * Get a set of elements containing all of the unique siblings of each of the
2666 * matched set of elements, and filtered by an expression.
2668 * @example $("div").siblings(".selected")
2669 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2670 * @result [ <p class="selected">Hello Again</p> ]
2674 * @param String expr An expression to filter the sibling Elements with
2675 * @cat DOM/Traversing
2677 siblings: jQuery.sibling,
2681 * Get a set of elements containing all of the unique children of each of the
2682 * matched set of elements.
2684 * @example $("div").children()
2685 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2686 * @result [ <span>Hello Again</span> ]
2690 * @cat DOM/Traversing
2694 * Get a set of elements containing all of the unique children of each of the
2695 * matched set of elements, and filtered by an expression.
2697 * @example $("div").children(".selected")
2698 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2699 * @result [ <p class="selected">Hello Again</p> ]
2703 * @param String expr An expression to filter the child Elements with
2704 * @cat DOM/Traversing
2706 children: "jQuery.sibling(a.firstChild)"
2712 * Remove an attribute from each of the matched elements.
2714 * @example $("input").removeAttr("disabled")
2715 * @before <input disabled="disabled"/>
2720 * @param String name The name of the attribute to remove.
2723 removeAttr: function( key ) {
2724 this.removeAttribute( key );
2728 * Displays each of the set of matched elements if they are hidden.
2730 * @example $("p").show()
2731 * @before <p style="display: none">Hello</p>
2732 * @result [ <p style="display: block">Hello</p> ]
2734 * @test var pass = true, div = $("div");
2735 * div.show().each(function(){
2736 * if ( this.style.display == "none" ) pass = false;
2738 * ok( pass, "Show" );
2745 this.style.display = this.oldblock ? this.oldblock : "";
2746 if ( jQuery.css(this,"display") == "none" )
2747 this.style.display = "block";
2751 * Hides each of the set of matched elements if they are shown.
2753 * @example $("p").hide()
2754 * @before <p>Hello</p>
2755 * @result [ <p style="display: none">Hello</p> ]
2757 * var pass = true, div = $("div");
2758 * div.hide().each(function(){
2759 * if ( this.style.display != "none" ) pass = false;
2761 * ok( pass, "Hide" );
2768 this.oldblock = this.oldblock || jQuery.css(this,"display");
2769 if ( this.oldblock == "none" )
2770 this.oldblock = "block";
2771 this.style.display = "none";
2775 * Toggles each of the set of matched elements. If they are shown,
2776 * toggle makes them hidden. If they are hidden, toggle
2779 * @example $("p").toggle()
2780 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2781 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2788 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2792 * Adds the specified class to each of the set of matched elements.
2794 * @example $("p").addClass("selected")
2795 * @before <p>Hello</p>
2796 * @result [ <p class="selected">Hello</p> ]
2798 * @test var div = $("div");
2799 * div.addClass("test");
2801 * for ( var i = 0; i < div.size(); i++ ) {
2802 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2804 * ok( pass, "Add Class" );
2808 * @param String class A CSS class to add to the elements
2811 addClass: function(c){
2812 jQuery.className.add(this,c);
2816 * Removes the specified class from the set of matched elements.
2818 * @example $("p").removeClass("selected")
2819 * @before <p class="selected">Hello</p>
2820 * @result [ <p>Hello</p> ]
2822 * @test var div = $("div").addClass("test");
2823 * div.removeClass("test");
2825 * for ( var i = 0; i < div.size(); i++ ) {
2826 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2828 * ok( pass, "Remove Class" );
2832 * @param String class A CSS class to remove from the elements
2835 removeClass: function(c){
2836 jQuery.className.remove(this,c);
2840 * Adds the specified class if it is present, removes it if it is
2843 * @example $("p").toggleClass("selected")
2844 * @before <p>Hello</p><p class="selected">Hello Again</p>
2845 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2849 * @param String class A CSS class with which to toggle the elements
2852 toggleClass: function( c ){
2853 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2857 * Removes all matched elements from the DOM. This does NOT remove them from the
2858 * jQuery object, allowing you to use the matched elements further.
2860 * @example $("p").remove();
2861 * @before <p>Hello</p> how are <p>you?</p>
2866 * @cat DOM/Manipulation
2870 * Removes only elements (out of the list of matched elements) that match
2871 * the specified jQuery expression. This does NOT remove them from the
2872 * jQuery object, allowing you to use the matched elements further.
2874 * @example $("p").remove(".hello");
2875 * @before <p class="hello">Hello</p> how are <p>you?</p>
2876 * @result how are <p>you?</p>
2880 * @param String expr A jQuery expression to filter elements by.
2881 * @cat DOM/Manipulation
2883 remove: function(a){
2884 if ( !a || jQuery.filter( a, [this] ).r )
2885 this.parentNode.removeChild( this );
2889 * Removes all child nodes from the set of matched elements.
2891 * @example $("p").empty()
2892 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2893 * @result [ <p></p> ]
2897 * @cat DOM/Manipulation
2900 while ( this.firstChild )
2901 this.removeChild( this.firstChild );
2905 * Binds a particular event (like click) to a each of a set of match elements.
2907 * @example $("p").bind( "click", function() { alert("Hello"); } )
2908 * @before <p>Hello</p>
2909 * @result [ <p>Hello</p> ]
2911 * Cancel a default action and prevent it from bubbling by returning false
2912 * from your function.
2914 * @example $("form").bind( "submit", function() { return false; } )
2916 * Cancel a default action by using the preventDefault method.
2918 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2920 * Stop an event from bubbling by using the stopPropogation method.
2922 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2926 * @param String type An event type
2927 * @param Function fn A function to bind to the event on each of the set of matched elements
2930 bind: function( type, fn ) {
2931 if ( fn.constructor == String )
2932 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
2933 jQuery.event.add( this, type, fn );
2937 * The opposite of bind, removes a bound event from each of the matched
2938 * elements. You must pass the identical function that was used in the original
2941 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2942 * @before <p onclick="alert('Hello');">Hello</p>
2943 * @result [ <p>Hello</p> ]
2947 * @param String type An event type
2948 * @param Function fn A function to unbind from the event on each of the set of matched elements
2953 * Removes all bound events of a particular type from each of the matched
2956 * @example $("p").unbind( "click" )
2957 * @before <p onclick="alert('Hello');">Hello</p>
2958 * @result [ <p>Hello</p> ]
2962 * @param String type An event type
2967 * Removes all bound events from each of the matched elements.
2969 * @example $("p").unbind()
2970 * @before <p onclick="alert('Hello');">Hello</p>
2971 * @result [ <p>Hello</p> ]
2977 unbind: function( type, fn ) {
2978 jQuery.event.remove( this, type, fn );
2982 * Trigger a type of event on every matched element.
2984 * @example $("p").trigger("click")
2985 * @before <p click="alert('hello')">Hello</p>
2986 * @result alert('hello')
2990 * @param String type An event type to trigger.
2993 trigger: function( type, data ) {
2994 jQuery.event.trigger( type, data, this );