3 // We're overriding the old toggle function, so
4 // remember it for later
5 _toggle: jQuery.fn.toggle,
8 * Toggle between two function calls every other click.
9 * Whenever a matched element is clicked, the first specified function
10 * is fired, when clicked again, the second is fired. All subsequent
11 * clicks continue to rotate through the two functions.
13 * @example $("p").toggle(function(){
14 * $(this).addClass("selected");
16 * $(this).removeClass("selected");
21 * @param Function even The function to execute on every even click.
22 * @param Function odd The function to execute on every odd click.
25 toggle: function(a,b) {
26 // If two functions are passed in, we're
27 // toggling on a click
28 return a && b && a.constructor == Function && b.constructor == Function ? this.click(function(e){
29 // Figure out which function to execute
30 this.last = this.last == a ? b : a;
32 // Make sure that clicks stop
35 // and execute the function
36 return this.last.apply( this, [e] ) || false;
39 // Otherwise, execute the old toggle function
40 this._toggle.apply( this, arguments );
44 * A method for simulating hovering (moving the mouse on, and off,
45 * an object). This is a custom method which provides an 'in' to a
48 * Whenever the mouse cursor is moved over a matched
49 * element, the first specified function is fired. Whenever the mouse
50 * moves off of the element, the second specified function fires.
51 * Additionally, checks are in place to see if the mouse is still within
52 * the specified element itself (for example, an image inside of a div),
53 * and if it is, it will continue to 'hover', and not move out
54 * (a common error in using a mouseout event handler).
56 * @example $("p").hover(function(){
57 * $(this).addClass("over");
59 * $(this).addClass("out");
64 * @param Function over The function to fire whenever the mouse is moved over a matched element.
65 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
68 hover: function(f,g) {
70 // A private function for haandling mouse 'hovering'
71 function handleHover(e) {
72 // Check if mouse(over|out) are still within the same parent element
73 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
75 // Traverse up the tree
76 while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
78 // If we actually just moused on to a sub-element, ignore it
79 if ( p == this ) return false;
81 // Execute the right function
82 return (e.type == "mouseover" ? f : g).apply(this, [e]);
85 // Bind the function to the two event listeners
86 return this.mouseover(handleHover).mouseout(handleHover);
90 * Bind a function to be executed whenever the DOM is ready to be
91 * traversed and manipulated. This is probably the most important
92 * function included in the event module, as it can greatly improve
93 * the response times of your web applications.
95 * In a nutshell, this is a solid replacement for using window.onload,
96 * and attaching a function to that. By using this method, your bound Function
97 * will be called the instant the DOM is ready to be read and manipulated,
98 * which is exactly what 99.99% of all Javascript code needs to run.
100 * Please ensure you have no code in your <body> onload event handler,
101 * otherwise $(document).ready() may not fire.
103 * You can have as many $(document).ready events on your page as you like.
104 * The functions are then executed in the order they were added.
106 * @example $(document).ready(function(){ Your code here... });
110 * @param Function fn The function to be executed when the DOM is ready.
114 // If the DOM is already ready
115 if ( jQuery.isReady )
116 // Execute the function immediately
119 // Otherwise, remember the function for later
121 // Add the function to the wait list
122 jQuery.readyList.push( f );
131 * All the code that makes DOM Ready work nicely.
136 // Handle when the DOM is ready
138 // Make sure that the DOM is not already loaded
139 if ( !jQuery.isReady ) {
140 // Remember that the DOM is ready
141 jQuery.isReady = true;
143 // If there are functions bound, to execute
144 if ( jQuery.readyList ) {
145 // Execute all of them
146 for ( var i = 0; i < jQuery.readyList.length; i++ )
147 jQuery.readyList[i].apply( document );
149 // Reset the list of functions
150 jQuery.readyList = null;
152 // Remove event lisenter to avoid memory leak
153 if ( jQuery.browser.mozilla || jQuery.browser.opera )
154 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
162 * Bind a function to the scroll event of each matched element.
164 * @example $("p").scroll( function() { alert("Hello"); } );
165 * @before <p>Hello</p>
166 * @result <p onscroll="alert('Hello');">Hello</p>
170 * @param Function fn A function to bind to the scroll event on each of the matched elements.
171 * @cat Events/Browser
175 * Trigger the scroll event of each matched element. This causes all of the functions
176 * that have been bound to thet scroll event to be executed.
178 * @example $("p").scroll();
179 * @before <p onscroll="alert('Hello');">Hello</p>
180 * @result alert('Hello');
184 * @cat Events/Browser
188 * Bind a function to the scroll event of each matched element, which will only be executed once.
189 * Unlike a call to the normal .scroll() method, calling .onescroll() causes the bound function to be
190 * only executed the first time it is triggered, and never again (unless it is re-bound).
192 * @example $("p").onescroll( function() { alert("Hello"); } );
193 * @before <p onscroll="alert('Hello');">Hello</p>
194 * @result alert('Hello'); // Only executed for the first scroll
198 * @param Function fn A function to bind to the scroll event on each of the matched elements.
199 * @cat Events/Browser
203 * Removes a bound scroll event from each of the matched
204 * elements. You must pass the identical function that was used in the original
207 * @example $("p").unscroll( myFunction );
208 * @before <p onscroll="myFunction">Hello</p>
209 * @result <p>Hello</p>
213 * @param Function fn A function to unbind from the scroll event on each of the matched elements.
214 * @cat Events/Browser
218 * Removes all bound scroll events from each of the matched elements.
220 * @example $("p").unscroll();
221 * @before <p onscroll="alert('Hello');">Hello</p>
222 * @result <p>Hello</p>
226 * @cat Events/Browser
230 * Bind a function to the submit event of each matched element.
232 * @example $("#myform").submit( function() {
233 * return $("input", this).val().length > 0;
235 * @before <form id="myform"><input /></form>
236 * @desc Prevents the form submission when the input has no value entered.
240 * @param Function fn A function to bind to the submit event on each of the matched elements.
245 * Trigger the submit event of each matched element. This causes all of the functions
246 * that have been bound to thet submit event to be executed.
248 * Note: This does not execute the submit method of the form element! If you need to
249 * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
251 * @example $("form").submit();
252 * @desc Triggers all submit events registered for forms, but does not submit the form
260 * Bind a function to the submit event of each matched element, which will only be executed once.
261 * Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be
262 * only executed the first time it is triggered, and never again (unless it is re-bound).
264 * @example $("p").onesubmit( function() { alert("Hello"); } );
265 * @before <p onsubmit="alert('Hello');">Hello</p>
266 * @result alert('Hello'); // Only executed for the first submit
270 * @param Function fn A function to bind to the submit event on each of the matched elements.
275 * Removes a bound submit event from each of the matched
276 * elements. You must pass the identical function that was used in the original
279 * @example $("p").unsubmit( myFunction );
280 * @before <p onsubmit="myFunction">Hello</p>
281 * @result <p>Hello</p>
285 * @param Function fn A function to unbind from the submit event on each of the matched elements.
290 * Removes all bound submit events from each of the matched elements.
292 * @example $("p").unsubmit();
293 * @before <p onsubmit="alert('Hello');">Hello</p>
294 * @result <p>Hello</p>
302 * Bind a function to the focus event of each matched element.
304 * @example $("p").focus( function() { alert("Hello"); } );
305 * @before <p>Hello</p>
306 * @result <p onfocus="alert('Hello');">Hello</p>
310 * @param Function fn A function to bind to the focus event on each of the matched elements.
315 * Trigger the focus event of each matched element. This causes all of the functions
316 * that have been bound to thet focus event to be executed.
318 * @example $("p").focus();
319 * @before <p onfocus="alert('Hello');">Hello</p>
320 * @result alert('Hello');
328 * Bind a function to the focus event of each matched element, which will only be executed once.
329 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
330 * only executed the first time it is triggered, and never again (unless it is re-bound).
332 * @example $("p").onefocus( function() { alert("Hello"); } );
333 * @before <p onfocus="alert('Hello');">Hello</p>
334 * @result alert('Hello'); // Only executed for the first focus
338 * @param Function fn A function to bind to the focus event on each of the matched elements.
343 * Removes a bound focus event from each of the matched
344 * elements. You must pass the identical function that was used in the original
347 * @example $("p").unfocus( myFunction );
348 * @before <p onfocus="myFunction">Hello</p>
349 * @result <p>Hello</p>
353 * @param Function fn A function to unbind from the focus event on each of the matched elements.
358 * Removes all bound focus events from each of the matched elements.
360 * @example $("p").unfocus();
361 * @before <p onfocus="alert('Hello');">Hello</p>
362 * @result <p>Hello</p>
370 * Bind a function to the keydown event of each matched element.
372 * @example $("p").keydown( function() { alert("Hello"); } );
373 * @before <p>Hello</p>
374 * @result <p onkeydown="alert('Hello');">Hello</p>
378 * @param Function fn A function to bind to the keydown event on each of the matched elements.
379 * @cat Events/Keyboard
383 * Trigger the keydown event of each matched element. This causes all of the functions
384 * that have been bound to thet keydown event to be executed.
386 * @example $("p").keydown();
387 * @before <p onkeydown="alert('Hello');">Hello</p>
388 * @result alert('Hello');
392 * @cat Events/Keyboard
396 * Bind a function to the keydown event of each matched element, which will only be executed once.
397 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
398 * only executed the first time it is triggered, and never again (unless it is re-bound).
400 * @example $("p").onekeydown( function() { alert("Hello"); } );
401 * @before <p onkeydown="alert('Hello');">Hello</p>
402 * @result alert('Hello'); // Only executed for the first keydown
406 * @param Function fn A function to bind to the keydown event on each of the matched elements.
407 * @cat Events/Keyboard
411 * Removes a bound keydown event from each of the matched
412 * elements. You must pass the identical function that was used in the original
415 * @example $("p").unkeydown( myFunction );
416 * @before <p onkeydown="myFunction">Hello</p>
417 * @result <p>Hello</p>
421 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
422 * @cat Events/Keyboard
426 * Removes all bound keydown events from each of the matched elements.
428 * @example $("p").unkeydown();
429 * @before <p onkeydown="alert('Hello');">Hello</p>
430 * @result <p>Hello</p>
434 * @cat Events/Keyboard
438 * Bind a function to the dblclick event of each matched element.
440 * @example $("p").dblclick( function() { alert("Hello"); } );
441 * @before <p>Hello</p>
442 * @result <p ondblclick="alert('Hello');">Hello</p>
446 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
451 * Trigger the dblclick event of each matched element. This causes all of the functions
452 * that have been bound to thet dblclick event to be executed.
454 * @example $("p").dblclick();
455 * @before <p ondblclick="alert('Hello');">Hello</p>
456 * @result alert('Hello');
464 * Bind a function to the dblclick event of each matched element, which will only be executed once.
465 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
466 * only executed the first time it is triggered, and never again (unless it is re-bound).
468 * @example $("p").onedblclick( function() { alert("Hello"); } );
469 * @before <p ondblclick="alert('Hello');">Hello</p>
470 * @result alert('Hello'); // Only executed for the first dblclick
474 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
479 * Removes a bound dblclick event from each of the matched
480 * elements. You must pass the identical function that was used in the original
483 * @example $("p").undblclick( myFunction );
484 * @before <p ondblclick="myFunction">Hello</p>
485 * @result <p>Hello</p>
489 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
494 * Removes all bound dblclick events from each of the matched elements.
496 * @example $("p").undblclick();
497 * @before <p ondblclick="alert('Hello');">Hello</p>
498 * @result <p>Hello</p>
506 * Bind a function to the keypress event of each matched element.
508 * @example $("p").keypress( function() { alert("Hello"); } );
509 * @before <p>Hello</p>
510 * @result <p onkeypress="alert('Hello');">Hello</p>
514 * @param Function fn A function to bind to the keypress event on each of the matched elements.
515 * @cat Events/Keyboard
519 * Trigger the keypress event of each matched element. This causes all of the functions
520 * that have been bound to thet keypress event to be executed.
522 * @example $("p").keypress();
523 * @before <p onkeypress="alert('Hello');">Hello</p>
524 * @result alert('Hello');
528 * @cat Events/Keyboard
532 * Bind a function to the keypress event of each matched element, which will only be executed once.
533 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
534 * only executed the first time it is triggered, and never again (unless it is re-bound).
536 * @example $("p").onekeypress( function() { alert("Hello"); } );
537 * @before <p onkeypress="alert('Hello');">Hello</p>
538 * @result alert('Hello'); // Only executed for the first keypress
542 * @param Function fn A function to bind to the keypress event on each of the matched elements.
543 * @cat Events/Keyboard
547 * Removes a bound keypress event from each of the matched
548 * elements. You must pass the identical function that was used in the original
551 * @example $("p").unkeypress( myFunction );
552 * @before <p onkeypress="myFunction">Hello</p>
553 * @result <p>Hello</p>
557 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
558 * @cat Events/Keyboard
562 * Removes all bound keypress events from each of the matched elements.
564 * @example $("p").unkeypress();
565 * @before <p onkeypress="alert('Hello');">Hello</p>
566 * @result <p>Hello</p>
570 * @cat Events/Keyboard
574 * Bind a function to the error event of each matched element.
576 * @example $("p").error( function() { alert("Hello"); } );
577 * @before <p>Hello</p>
578 * @result <p onerror="alert('Hello');">Hello</p>
582 * @param Function fn A function to bind to the error event on each of the matched elements.
583 * @cat Events/Browser
587 * Trigger the error event of each matched element. This causes all of the functions
588 * that have been bound to thet error event to be executed.
590 * @example $("p").error();
591 * @before <p onerror="alert('Hello');">Hello</p>
592 * @result alert('Hello');
596 * @cat Events/Browser
600 * Bind a function to the error event of each matched element, which will only be executed once.
601 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
602 * only executed the first time it is triggered, and never again (unless it is re-bound).
604 * @example $("p").oneerror( function() { alert("Hello"); } );
605 * @before <p onerror="alert('Hello');">Hello</p>
606 * @result alert('Hello'); // Only executed for the first error
610 * @param Function fn A function to bind to the error event on each of the matched elements.
611 * @cat Events/Browser
615 * Removes a bound error event from each of the matched
616 * elements. You must pass the identical function that was used in the original
619 * @example $("p").unerror( myFunction );
620 * @before <p onerror="myFunction">Hello</p>
621 * @result <p>Hello</p>
625 * @param Function fn A function to unbind from the error event on each of the matched elements.
626 * @cat Events/Browser
630 * Removes all bound error events from each of the matched elements.
632 * @example $("p").unerror();
633 * @before <p onerror="alert('Hello');">Hello</p>
634 * @result <p>Hello</p>
638 * @cat Events/Browser
642 * Bind a function to the blur event of each matched element.
644 * @example $("p").blur( function() { alert("Hello"); } );
645 * @before <p>Hello</p>
646 * @result <p onblur="alert('Hello');">Hello</p>
650 * @param Function fn A function to bind to the blur event on each of the matched elements.
655 * Trigger the blur event of each matched element. This causes all of the functions
656 * that have been bound to thet blur event to be executed.
658 * @example $("p").blur();
659 * @before <p onblur="alert('Hello');">Hello</p>
660 * @result alert('Hello');
668 * Bind a function to the blur event of each matched element, which will only be executed once.
669 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
670 * only executed the first time it is triggered, and never again (unless it is re-bound).
672 * @example $("p").oneblur( function() { alert("Hello"); } );
673 * @before <p onblur="alert('Hello');">Hello</p>
674 * @result alert('Hello'); // Only executed for the first blur
678 * @param Function fn A function to bind to the blur event on each of the matched elements.
683 * Removes a bound blur event from each of the matched
684 * elements. You must pass the identical function that was used in the original
687 * @example $("p").unblur( myFunction );
688 * @before <p onblur="myFunction">Hello</p>
689 * @result <p>Hello</p>
693 * @param Function fn A function to unbind from the blur event on each of the matched elements.
698 * Removes all bound blur events from each of the matched elements.
700 * @example $("p").unblur();
701 * @before <p onblur="alert('Hello');">Hello</p>
702 * @result <p>Hello</p>
710 * Bind a function to the load event of each matched element.
712 * @example $("p").load( function() { alert("Hello"); } );
713 * @before <p>Hello</p>
714 * @result <p onload="alert('Hello');">Hello</p>
718 * @param Function fn A function to bind to the load event on each of the matched elements.
719 * @cat Events/Browser
723 * Trigger the load event of each matched element. This causes all of the functions
724 * that have been bound to thet load event to be executed.
726 * Marked as private: Calling load() without arguments throws exception because the ajax load
727 * does not handle it.
729 * @example $("p").load();
730 * @before <p onload="alert('Hello');">Hello</p>
731 * @result alert('Hello');
736 * @cat Events/Browser
740 * Bind a function to the load event of each matched element, which will only be executed once.
741 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
742 * only executed the first time it is triggered, and never again (unless it is re-bound).
744 * @example $("p").oneload( function() { alert("Hello"); } );
745 * @before <p onload="alert('Hello');">Hello</p>
746 * @result alert('Hello'); // Only executed for the first load
750 * @param Function fn A function to bind to the load event on each of the matched elements.
751 * @cat Events/Browser
755 * Removes a bound load event from each of the matched
756 * elements. You must pass the identical function that was used in the original
759 * @example $("p").unload( myFunction );
760 * @before <p onload="myFunction">Hello</p>
761 * @result <p>Hello</p>
765 * @param Function fn A function to unbind from the load event on each of the matched elements.
766 * @cat Events/Browser
770 * Removes all bound load events from each of the matched elements.
772 * @example $("p").unload();
773 * @before <p onload="alert('Hello');">Hello</p>
774 * @result <p>Hello</p>
778 * @cat Events/Browser
782 * Bind a function to the select event of each matched element.
784 * @example $("p").select( function() { alert("Hello"); } );
785 * @before <p>Hello</p>
786 * @result <p onselect="alert('Hello');">Hello</p>
790 * @param Function fn A function to bind to the select event on each of the matched elements.
795 * Trigger the select event of each matched element. This causes all of the functions
796 * that have been bound to thet select event to be executed.
798 * @example $("p").select();
799 * @before <p onselect="alert('Hello');">Hello</p>
800 * @result alert('Hello');
808 * Bind a function to the select event of each matched element, which will only be executed once.
809 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
810 * only executed the first time it is triggered, and never again (unless it is re-bound).
812 * @example $("p").oneselect( function() { alert("Hello"); } );
813 * @before <p onselect="alert('Hello');">Hello</p>
814 * @result alert('Hello'); // Only executed for the first select
818 * @param Function fn A function to bind to the select event on each of the matched elements.
823 * Removes a bound select event from each of the matched
824 * elements. You must pass the identical function that was used in the original
827 * @example $("p").unselect( myFunction );
828 * @before <p onselect="myFunction">Hello</p>
829 * @result <p>Hello</p>
833 * @param Function fn A function to unbind from the select event on each of the matched elements.
838 * Removes all bound select events from each of the matched elements.
840 * @example $("p").unselect();
841 * @before <p onselect="alert('Hello');">Hello</p>
842 * @result <p>Hello</p>
850 * Bind a function to the mouseup event of each matched element.
852 * @example $("p").mouseup( function() { alert("Hello"); } );
853 * @before <p>Hello</p>
854 * @result <p onmouseup="alert('Hello');">Hello</p>
858 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
863 * Trigger the mouseup event of each matched element. This causes all of the functions
864 * that have been bound to thet mouseup event to be executed.
866 * @example $("p").mouseup();
867 * @before <p onmouseup="alert('Hello');">Hello</p>
868 * @result alert('Hello');
876 * Bind a function to the mouseup event of each matched element, which will only be executed once.
877 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
878 * only executed the first time it is triggered, and never again (unless it is re-bound).
880 * @example $("p").onemouseup( function() { alert("Hello"); } );
881 * @before <p onmouseup="alert('Hello');">Hello</p>
882 * @result alert('Hello'); // Only executed for the first mouseup
886 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
891 * Removes a bound mouseup event from each of the matched
892 * elements. You must pass the identical function that was used in the original
895 * @example $("p").unmouseup( myFunction );
896 * @before <p onmouseup="myFunction">Hello</p>
897 * @result <p>Hello</p>
901 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
906 * Removes all bound mouseup events from each of the matched elements.
908 * @example $("p").unmouseup();
909 * @before <p onmouseup="alert('Hello');">Hello</p>
910 * @result <p>Hello</p>
918 * Bind a function to the unload event of each matched element.
920 * @example $("p").unload( function() { alert("Hello"); } );
921 * @before <p>Hello</p>
922 * @result <p onunload="alert('Hello');">Hello</p>
926 * @param Function fn A function to bind to the unload event on each of the matched elements.
927 * @cat Events/Browser
931 * Trigger the unload event of each matched element. This causes all of the functions
932 * that have been bound to thet unload event to be executed.
934 * @example $("p").unload();
935 * @before <p onunload="alert('Hello');">Hello</p>
936 * @result alert('Hello');
940 * @cat Events/Browser
944 * Bind a function to the unload event of each matched element, which will only be executed once.
945 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
946 * only executed the first time it is triggered, and never again (unless it is re-bound).
948 * @example $("p").oneunload( function() { alert("Hello"); } );
949 * @before <p onunload="alert('Hello');">Hello</p>
950 * @result alert('Hello'); // Only executed for the first unload
954 * @param Function fn A function to bind to the unload event on each of the matched elements.
955 * @cat Events/Browser
959 * Removes a bound unload event from each of the matched
960 * elements. You must pass the identical function that was used in the original
963 * @example $("p").ununload( myFunction );
964 * @before <p onunload="myFunction">Hello</p>
965 * @result <p>Hello</p>
969 * @param Function fn A function to unbind from the unload event on each of the matched elements.
970 * @cat Events/Browser
974 * Removes all bound unload events from each of the matched elements.
976 * @example $("p").ununload();
977 * @before <p onunload="alert('Hello');">Hello</p>
978 * @result <p>Hello</p>
982 * @cat Events/Browser
986 * Bind a function to the change event of each matched element.
988 * @example $("p").change( function() { alert("Hello"); } );
989 * @before <p>Hello</p>
990 * @result <p onchange="alert('Hello');">Hello</p>
994 * @param Function fn A function to bind to the change event on each of the matched elements.
999 * Trigger the change event of each matched element. This causes all of the functions
1000 * that have been bound to thet change event to be executed.
1002 * @example $("p").change();
1003 * @before <p onchange="alert('Hello');">Hello</p>
1004 * @result alert('Hello');
1012 * Bind a function to the change event of each matched element, which will only be executed once.
1013 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
1014 * only executed the first time it is triggered, and never again (unless it is re-bound).
1016 * @example $("p").onechange( function() { alert("Hello"); } );
1017 * @before <p onchange="alert('Hello');">Hello</p>
1018 * @result alert('Hello'); // Only executed for the first change
1022 * @param Function fn A function to bind to the change event on each of the matched elements.
1027 * Removes a bound change event from each of the matched
1028 * elements. You must pass the identical function that was used in the original
1031 * @example $("p").unchange( myFunction );
1032 * @before <p onchange="myFunction">Hello</p>
1033 * @result <p>Hello</p>
1037 * @param Function fn A function to unbind from the change event on each of the matched elements.
1042 * Removes all bound change events from each of the matched elements.
1044 * @example $("p").unchange();
1045 * @before <p onchange="alert('Hello');">Hello</p>
1046 * @result <p>Hello</p>
1054 * Bind a function to the mouseout event of each matched element.
1056 * @example $("p").mouseout( function() { alert("Hello"); } );
1057 * @before <p>Hello</p>
1058 * @result <p onmouseout="alert('Hello');">Hello</p>
1062 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1067 * Trigger the mouseout event of each matched element. This causes all of the functions
1068 * that have been bound to thet mouseout event to be executed.
1070 * @example $("p").mouseout();
1071 * @before <p onmouseout="alert('Hello');">Hello</p>
1072 * @result alert('Hello');
1080 * Bind a function to the mouseout event of each matched element, which will only be executed once.
1081 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
1082 * only executed the first time it is triggered, and never again (unless it is re-bound).
1084 * @example $("p").onemouseout( function() { alert("Hello"); } );
1085 * @before <p onmouseout="alert('Hello');">Hello</p>
1086 * @result alert('Hello'); // Only executed for the first mouseout
1090 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1095 * Removes a bound mouseout event from each of the matched
1096 * elements. You must pass the identical function that was used in the original
1099 * @example $("p").unmouseout( myFunction );
1100 * @before <p onmouseout="myFunction">Hello</p>
1101 * @result <p>Hello</p>
1105 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
1110 * Removes all bound mouseout events from each of the matched elements.
1112 * @example $("p").unmouseout();
1113 * @before <p onmouseout="alert('Hello');">Hello</p>
1114 * @result <p>Hello</p>
1122 * Bind a function to the keyup event of each matched element.
1124 * @example $("p").keyup( function() { alert("Hello"); } );
1125 * @before <p>Hello</p>
1126 * @result <p onkeyup="alert('Hello');">Hello</p>
1130 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1131 * @cat Events/Keyboard
1135 * Trigger the keyup event of each matched element. This causes all of the functions
1136 * that have been bound to thet keyup event to be executed.
1138 * @example $("p").keyup();
1139 * @before <p onkeyup="alert('Hello');">Hello</p>
1140 * @result alert('Hello');
1144 * @cat Events/Keyboard
1148 * Bind a function to the keyup event of each matched element, which will only be executed once.
1149 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1150 * only executed the first time it is triggered, and never again (unless it is re-bound).
1152 * @example $("p").onekeyup( function() { alert("Hello"); } );
1153 * @before <p onkeyup="alert('Hello');">Hello</p>
1154 * @result alert('Hello'); // Only executed for the first keyup
1158 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1159 * @cat Events/Keyboard
1163 * Removes a bound keyup event from each of the matched
1164 * elements. You must pass the identical function that was used in the original
1167 * @example $("p").unkeyup( myFunction );
1168 * @before <p onkeyup="myFunction">Hello</p>
1169 * @result <p>Hello</p>
1173 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1174 * @cat Events/Keyboard
1178 * Removes all bound keyup events from each of the matched elements.
1180 * @example $("p").unkeyup();
1181 * @before <p onkeyup="alert('Hello');">Hello</p>
1182 * @result <p>Hello</p>
1186 * @cat Events/Keyboard
1190 * Bind a function to the click event of each matched element.
1192 * @example $("p").click( function() { alert("Hello"); } );
1193 * @before <p>Hello</p>
1194 * @result <p onclick="alert('Hello');">Hello</p>
1198 * @param Function fn A function to bind to the click event on each of the matched elements.
1203 * Trigger the click event of each matched element. This causes all of the functions
1204 * that have been bound to thet click event to be executed.
1206 * @example $("p").click();
1207 * @before <p onclick="alert('Hello');">Hello</p>
1208 * @result alert('Hello');
1216 * Bind a function to the click event of each matched element, which will only be executed once.
1217 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
1218 * only executed the first time it is triggered, and never again (unless it is re-bound).
1220 * @example $("p").oneclick( function() { alert("Hello"); } );
1221 * @before <p onclick="alert('Hello');">Hello</p>
1222 * @result alert('Hello'); // Only executed for the first click
1226 * @param Function fn A function to bind to the click event on each of the matched elements.
1231 * Removes a bound click event from each of the matched
1232 * elements. You must pass the identical function that was used in the original
1235 * @example $("p").unclick( myFunction );
1236 * @before <p onclick="myFunction">Hello</p>
1237 * @result <p>Hello</p>
1241 * @param Function fn A function to unbind from the click event on each of the matched elements.
1246 * Removes all bound click events from each of the matched elements.
1248 * @example $("p").unclick();
1249 * @before <p onclick="alert('Hello');">Hello</p>
1250 * @result <p>Hello</p>
1258 * Bind a function to the resize event of each matched element.
1260 * @example $("p").resize( function() { alert("Hello"); } );
1261 * @before <p>Hello</p>
1262 * @result <p onresize="alert('Hello');">Hello</p>
1266 * @param Function fn A function to bind to the resize event on each of the matched elements.
1267 * @cat Events/Browser
1271 * Trigger the resize event of each matched element. This causes all of the functions
1272 * that have been bound to thet resize event to be executed.
1274 * @example $("p").resize();
1275 * @before <p onresize="alert('Hello');">Hello</p>
1276 * @result alert('Hello');
1280 * @cat Events/Browser
1284 * Bind a function to the resize event of each matched element, which will only be executed once.
1285 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
1286 * only executed the first time it is triggered, and never again (unless it is re-bound).
1288 * @example $("p").oneresize( function() { alert("Hello"); } );
1289 * @before <p onresize="alert('Hello');">Hello</p>
1290 * @result alert('Hello'); // Only executed for the first resize
1294 * @param Function fn A function to bind to the resize event on each of the matched elements.
1295 * @cat Events/Browser
1299 * Removes a bound resize event from each of the matched
1300 * elements. You must pass the identical function that was used in the original
1303 * @example $("p").unresize( myFunction );
1304 * @before <p onresize="myFunction">Hello</p>
1305 * @result <p>Hello</p>
1309 * @param Function fn A function to unbind from the resize event on each of the matched elements.
1310 * @cat Events/Browser
1314 * Removes all bound resize events from each of the matched elements.
1316 * @example $("p").unresize();
1317 * @before <p onresize="alert('Hello');">Hello</p>
1318 * @result <p>Hello</p>
1322 * @cat Events/Browser
1326 * Bind a function to the mousemove event of each matched element.
1328 * @example $("p").mousemove( function() { alert("Hello"); } );
1329 * @before <p>Hello</p>
1330 * @result <p onmousemove="alert('Hello');">Hello</p>
1334 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1339 * Trigger the mousemove event of each matched element. This causes all of the functions
1340 * that have been bound to thet mousemove event to be executed.
1342 * @example $("p").mousemove();
1343 * @before <p onmousemove="alert('Hello');">Hello</p>
1344 * @result alert('Hello');
1352 * Bind a function to the mousemove event of each matched element, which will only be executed once.
1353 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
1354 * only executed the first time it is triggered, and never again (unless it is re-bound).
1356 * @example $("p").onemousemove( function() { alert("Hello"); } );
1357 * @before <p onmousemove="alert('Hello');">Hello</p>
1358 * @result alert('Hello'); // Only executed for the first mousemove
1360 * @name onemousemove
1362 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1367 * Removes a bound mousemove event from each of the matched
1368 * elements. You must pass the identical function that was used in the original
1371 * @example $("p").unmousemove( myFunction );
1372 * @before <p onmousemove="myFunction">Hello</p>
1373 * @result <p>Hello</p>
1377 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
1382 * Removes all bound mousemove events from each of the matched elements.
1384 * @example $("p").unmousemove();
1385 * @before <p onmousemove="alert('Hello');">Hello</p>
1386 * @result <p>Hello</p>
1394 * Bind a function to the mousedown event of each matched element.
1396 * @example $("p").mousedown( function() { alert("Hello"); } );
1397 * @before <p>Hello</p>
1398 * @result <p onmousedown="alert('Hello');">Hello</p>
1402 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1407 * Trigger the mousedown event of each matched element. This causes all of the functions
1408 * that have been bound to thet mousedown event to be executed.
1410 * @example $("p").mousedown();
1411 * @before <p onmousedown="alert('Hello');">Hello</p>
1412 * @result alert('Hello');
1420 * Bind a function to the mousedown event of each matched element, which will only be executed once.
1421 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
1422 * only executed the first time it is triggered, and never again (unless it is re-bound).
1424 * @example $("p").onemousedown( function() { alert("Hello"); } );
1425 * @before <p onmousedown="alert('Hello');">Hello</p>
1426 * @result alert('Hello'); // Only executed for the first mousedown
1428 * @name onemousedown
1430 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1435 * Removes a bound mousedown event from each of the matched
1436 * elements. You must pass the identical function that was used in the original
1439 * @example $("p").unmousedown( myFunction );
1440 * @before <p onmousedown="myFunction">Hello</p>
1441 * @result <p>Hello</p>
1445 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
1450 * Removes all bound mousedown events from each of the matched elements.
1452 * @example $("p").unmousedown();
1453 * @before <p onmousedown="alert('Hello');">Hello</p>
1454 * @result <p>Hello</p>
1462 * Bind a function to the mouseover event of each matched element.
1464 * @example $("p").mouseover( function() { alert("Hello"); } );
1465 * @before <p>Hello</p>
1466 * @result <p onmouseover="alert('Hello');">Hello</p>
1470 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1475 * Trigger the mouseover event of each matched element. This causes all of the functions
1476 * that have been bound to thet mousedown event to be executed.
1478 * @example $("p").mouseover();
1479 * @before <p onmouseover="alert('Hello');">Hello</p>
1480 * @result alert('Hello');
1488 * Bind a function to the mouseover event of each matched element, which will only be executed once.
1489 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
1490 * only executed the first time it is triggered, and never again (unless it is re-bound).
1492 * @example $("p").onemouseover( function() { alert("Hello"); } );
1493 * @before <p onmouseover="alert('Hello');">Hello</p>
1494 * @result alert('Hello'); // Only executed for the first mouseover
1496 * @name onemouseover
1498 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
1503 * Removes a bound mouseover event from each of the matched
1504 * elements. You must pass the identical function that was used in the original
1507 * @example $("p").unmouseover( myFunction );
1508 * @before <p onmouseover="myFunction">Hello</p>
1509 * @result <p>Hello</p>
1513 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
1518 * Removes all bound mouseover events from each of the matched elements.
1520 * @example $("p").unmouseover();
1521 * @before <p onmouseover="alert('Hello');">Hello</p>
1522 * @result <p>Hello</p>
1529 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1530 "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
1531 "submit,keydown,keypress,keyup,error").split(",");
1533 // Go through all the event names, but make sure that
1534 // it is enclosed properly
1535 for ( var i = 0; i < e.length; i++ ) new function(){
1539 // Handle event binding
1540 jQuery.fn[o] = function(f){
1541 return f ? this.bind(o, f) : this.trigger(o);
1544 // Handle event unbinding
1545 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1547 // Finally, handle events that only fire once
1548 jQuery.fn["one"+o] = function(f){
1549 // save cloned reference to this
1550 var element = jQuery(this);
1551 var handler = function() {
1552 // unbind itself when executed
1553 element.unbind(o, handler);
1555 // apply original handler with the same arguments
1556 return f.apply(this, arguments);
1558 return this.bind(o, handler);
1563 // If Mozilla is used
1564 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1565 // Use the handy event callback
1566 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1568 // If IE is used, use the excellent hack by Matthias Miller
1569 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1570 } else if ( jQuery.browser.msie ) {
1572 // Only works if you document.write() it
1573 document.write("<scr" + "ipt id=__ie_init defer=true " +
1574 "src=//:><\/script>");
1576 // Use the defer script hack
1577 var script = document.getElementById("__ie_init");
1578 if (script) // script does not exist if jQuery is loaded dynamically
1579 script.onreadystatechange = function() {
1580 if ( this.readyState != "complete" ) return;
1581 this.parentNode.removeChild( this );
1585 // Clear from memory
1588 // If Safari is used
1589 } else if ( jQuery.browser.safari ) {
1590 // Continually check to see if the document.readyState is valid
1591 jQuery.safariTimer = setInterval(function(){
1592 // loaded and complete are both valid states
1593 if ( document.readyState == "loaded" ||
1594 document.readyState == "complete" ) {
1596 // If either one are found, remove the timer
1597 clearInterval( jQuery.safariTimer );
1598 jQuery.safariTimer = null;
1600 // and execute any waiting functions
1606 // A fallback to window.onload, that will always work
1607 jQuery.event.add( window, "load", jQuery.ready );
1611 // Clean up after IE to avoid memory leaks
1612 if (jQuery.browser.msie) jQuery(window).unload(function() {
1613 var event = jQuery.event, global = event.global;
1614 for (var type in global) {
1615 var els = global[type], i = els.length;
1616 if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i);