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 * Note: This does not execute the focus method of the underlying elements! If you need to
319 * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
321 * @example $("p").focus();
322 * @before <p onfocus="alert('Hello');">Hello</p>
323 * @result alert('Hello');
331 * Bind a function to the focus event of each matched element, which will only be executed once.
332 * Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be
333 * only executed the first time it is triggered, and never again (unless it is re-bound).
335 * @example $("p").onefocus( function() { alert("Hello"); } );
336 * @before <p onfocus="alert('Hello');">Hello</p>
337 * @result alert('Hello'); // Only executed for the first focus
341 * @param Function fn A function to bind to the focus event on each of the matched elements.
346 * Removes a bound focus event from each of the matched
347 * elements. You must pass the identical function that was used in the original
350 * @example $("p").unfocus( myFunction );
351 * @before <p onfocus="myFunction">Hello</p>
352 * @result <p>Hello</p>
356 * @param Function fn A function to unbind from the focus event on each of the matched elements.
361 * Removes all bound focus events from each of the matched elements.
363 * @example $("p").unfocus();
364 * @before <p onfocus="alert('Hello');">Hello</p>
365 * @result <p>Hello</p>
373 * Bind a function to the keydown event of each matched element.
375 * @example $("p").keydown( function() { alert("Hello"); } );
376 * @before <p>Hello</p>
377 * @result <p onkeydown="alert('Hello');">Hello</p>
381 * @param Function fn A function to bind to the keydown event on each of the matched elements.
382 * @cat Events/Keyboard
386 * Trigger the keydown event of each matched element. This causes all of the functions
387 * that have been bound to thet keydown event to be executed.
389 * @example $("p").keydown();
390 * @before <p onkeydown="alert('Hello');">Hello</p>
391 * @result alert('Hello');
395 * @cat Events/Keyboard
399 * Bind a function to the keydown event of each matched element, which will only be executed once.
400 * Unlike a call to the normal .keydown() method, calling .onekeydown() causes the bound function to be
401 * only executed the first time it is triggered, and never again (unless it is re-bound).
403 * @example $("p").onekeydown( function() { alert("Hello"); } );
404 * @before <p onkeydown="alert('Hello');">Hello</p>
405 * @result alert('Hello'); // Only executed for the first keydown
409 * @param Function fn A function to bind to the keydown event on each of the matched elements.
410 * @cat Events/Keyboard
414 * Removes a bound keydown event from each of the matched
415 * elements. You must pass the identical function that was used in the original
418 * @example $("p").unkeydown( myFunction );
419 * @before <p onkeydown="myFunction">Hello</p>
420 * @result <p>Hello</p>
424 * @param Function fn A function to unbind from the keydown event on each of the matched elements.
425 * @cat Events/Keyboard
429 * Removes all bound keydown events from each of the matched elements.
431 * @example $("p").unkeydown();
432 * @before <p onkeydown="alert('Hello');">Hello</p>
433 * @result <p>Hello</p>
437 * @cat Events/Keyboard
441 * Bind a function to the dblclick event of each matched element.
443 * @example $("p").dblclick( function() { alert("Hello"); } );
444 * @before <p>Hello</p>
445 * @result <p ondblclick="alert('Hello');">Hello</p>
449 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
454 * Trigger the dblclick event of each matched element. This causes all of the functions
455 * that have been bound to thet dblclick event to be executed.
457 * @example $("p").dblclick();
458 * @before <p ondblclick="alert('Hello');">Hello</p>
459 * @result alert('Hello');
467 * Bind a function to the dblclick event of each matched element, which will only be executed once.
468 * Unlike a call to the normal .dblclick() method, calling .onedblclick() causes the bound function to be
469 * only executed the first time it is triggered, and never again (unless it is re-bound).
471 * @example $("p").onedblclick( function() { alert("Hello"); } );
472 * @before <p ondblclick="alert('Hello');">Hello</p>
473 * @result alert('Hello'); // Only executed for the first dblclick
477 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
482 * Removes a bound dblclick event from each of the matched
483 * elements. You must pass the identical function that was used in the original
486 * @example $("p").undblclick( myFunction );
487 * @before <p ondblclick="myFunction">Hello</p>
488 * @result <p>Hello</p>
492 * @param Function fn A function to unbind from the dblclick event on each of the matched elements.
497 * Removes all bound dblclick events from each of the matched elements.
499 * @example $("p").undblclick();
500 * @before <p ondblclick="alert('Hello');">Hello</p>
501 * @result <p>Hello</p>
509 * Bind a function to the keypress event of each matched element.
511 * @example $("p").keypress( function() { alert("Hello"); } );
512 * @before <p>Hello</p>
513 * @result <p onkeypress="alert('Hello');">Hello</p>
517 * @param Function fn A function to bind to the keypress event on each of the matched elements.
518 * @cat Events/Keyboard
522 * Trigger the keypress event of each matched element. This causes all of the functions
523 * that have been bound to thet keypress event to be executed.
525 * @example $("p").keypress();
526 * @before <p onkeypress="alert('Hello');">Hello</p>
527 * @result alert('Hello');
531 * @cat Events/Keyboard
535 * Bind a function to the keypress event of each matched element, which will only be executed once.
536 * Unlike a call to the normal .keypress() method, calling .onekeypress() causes the bound function to be
537 * only executed the first time it is triggered, and never again (unless it is re-bound).
539 * @example $("p").onekeypress( function() { alert("Hello"); } );
540 * @before <p onkeypress="alert('Hello');">Hello</p>
541 * @result alert('Hello'); // Only executed for the first keypress
545 * @param Function fn A function to bind to the keypress event on each of the matched elements.
546 * @cat Events/Keyboard
550 * Removes a bound keypress event from each of the matched
551 * elements. You must pass the identical function that was used in the original
554 * @example $("p").unkeypress( myFunction );
555 * @before <p onkeypress="myFunction">Hello</p>
556 * @result <p>Hello</p>
560 * @param Function fn A function to unbind from the keypress event on each of the matched elements.
561 * @cat Events/Keyboard
565 * Removes all bound keypress events from each of the matched elements.
567 * @example $("p").unkeypress();
568 * @before <p onkeypress="alert('Hello');">Hello</p>
569 * @result <p>Hello</p>
573 * @cat Events/Keyboard
577 * Bind a function to the error event of each matched element.
579 * @example $("p").error( function() { alert("Hello"); } );
580 * @before <p>Hello</p>
581 * @result <p onerror="alert('Hello');">Hello</p>
585 * @param Function fn A function to bind to the error event on each of the matched elements.
586 * @cat Events/Browser
590 * Trigger the error event of each matched element. This causes all of the functions
591 * that have been bound to thet error event to be executed.
593 * @example $("p").error();
594 * @before <p onerror="alert('Hello');">Hello</p>
595 * @result alert('Hello');
599 * @cat Events/Browser
603 * Bind a function to the error event of each matched element, which will only be executed once.
604 * Unlike a call to the normal .error() method, calling .oneerror() causes the bound function to be
605 * only executed the first time it is triggered, and never again (unless it is re-bound).
607 * @example $("p").oneerror( function() { alert("Hello"); } );
608 * @before <p onerror="alert('Hello');">Hello</p>
609 * @result alert('Hello'); // Only executed for the first error
613 * @param Function fn A function to bind to the error event on each of the matched elements.
614 * @cat Events/Browser
618 * Removes a bound error event from each of the matched
619 * elements. You must pass the identical function that was used in the original
622 * @example $("p").unerror( myFunction );
623 * @before <p onerror="myFunction">Hello</p>
624 * @result <p>Hello</p>
628 * @param Function fn A function to unbind from the error event on each of the matched elements.
629 * @cat Events/Browser
633 * Removes all bound error events from each of the matched elements.
635 * @example $("p").unerror();
636 * @before <p onerror="alert('Hello');">Hello</p>
637 * @result <p>Hello</p>
641 * @cat Events/Browser
645 * Bind a function to the blur event of each matched element.
647 * @example $("p").blur( function() { alert("Hello"); } );
648 * @before <p>Hello</p>
649 * @result <p onblur="alert('Hello');">Hello</p>
653 * @param Function fn A function to bind to the blur event on each of the matched elements.
658 * Trigger the blur event of each matched element. This causes all of the functions
659 * that have been bound to thet blur event to be executed.
661 * Note: This does not execute the blur method of the underlying elements! If you need to
662 * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
664 * @example $("p").blur();
665 * @before <p onblur="alert('Hello');">Hello</p>
666 * @result alert('Hello');
674 * Bind a function to the blur event of each matched element, which will only be executed once.
675 * Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be
676 * only executed the first time it is triggered, and never again (unless it is re-bound).
678 * @example $("p").oneblur( function() { alert("Hello"); } );
679 * @before <p onblur="alert('Hello');">Hello</p>
680 * @result alert('Hello'); // Only executed for the first blur
684 * @param Function fn A function to bind to the blur event on each of the matched elements.
689 * Removes a bound blur event from each of the matched
690 * elements. You must pass the identical function that was used in the original
693 * @example $("p").unblur( myFunction );
694 * @before <p onblur="myFunction">Hello</p>
695 * @result <p>Hello</p>
699 * @param Function fn A function to unbind from the blur event on each of the matched elements.
704 * Removes all bound blur events from each of the matched elements.
706 * @example $("p").unblur();
707 * @before <p onblur="alert('Hello');">Hello</p>
708 * @result <p>Hello</p>
716 * Bind a function to the load event of each matched element.
718 * @example $("p").load( function() { alert("Hello"); } );
719 * @before <p>Hello</p>
720 * @result <p onload="alert('Hello');">Hello</p>
724 * @param Function fn A function to bind to the load event on each of the matched elements.
725 * @cat Events/Browser
729 * Trigger the load event of each matched element. This causes all of the functions
730 * that have been bound to thet load event to be executed.
732 * Marked as private: Calling load() without arguments throws exception because the ajax load
733 * does not handle it.
735 * @example $("p").load();
736 * @before <p onload="alert('Hello');">Hello</p>
737 * @result alert('Hello');
742 * @cat Events/Browser
746 * Bind a function to the load event of each matched element, which will only be executed once.
747 * Unlike a call to the normal .load() method, calling .oneload() causes the bound function to be
748 * only executed the first time it is triggered, and never again (unless it is re-bound).
750 * @example $("p").oneload( function() { alert("Hello"); } );
751 * @before <p onload="alert('Hello');">Hello</p>
752 * @result alert('Hello'); // Only executed for the first load
756 * @param Function fn A function to bind to the load event on each of the matched elements.
757 * @cat Events/Browser
761 * Removes a bound load event from each of the matched
762 * elements. You must pass the identical function that was used in the original
765 * @example $("p").unload( myFunction );
766 * @before <p onload="myFunction">Hello</p>
767 * @result <p>Hello</p>
771 * @param Function fn A function to unbind from the load event on each of the matched elements.
772 * @cat Events/Browser
776 * Removes all bound load events from each of the matched elements.
778 * @example $("p").unload();
779 * @before <p onload="alert('Hello');">Hello</p>
780 * @result <p>Hello</p>
784 * @cat Events/Browser
788 * Bind a function to the select event of each matched element.
790 * @example $("p").select( function() { alert("Hello"); } );
791 * @before <p>Hello</p>
792 * @result <p onselect="alert('Hello');">Hello</p>
796 * @param Function fn A function to bind to the select event on each of the matched elements.
801 * Trigger the select event of each matched element. This causes all of the functions
802 * that have been bound to thet select event to be executed.
804 * @example $("p").select();
805 * @before <p onselect="alert('Hello');">Hello</p>
806 * @result alert('Hello');
814 * Bind a function to the select event of each matched element, which will only be executed once.
815 * Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be
816 * only executed the first time it is triggered, and never again (unless it is re-bound).
818 * @example $("p").oneselect( function() { alert("Hello"); } );
819 * @before <p onselect="alert('Hello');">Hello</p>
820 * @result alert('Hello'); // Only executed for the first select
824 * @param Function fn A function to bind to the select event on each of the matched elements.
829 * Removes a bound select event from each of the matched
830 * elements. You must pass the identical function that was used in the original
833 * @example $("p").unselect( myFunction );
834 * @before <p onselect="myFunction">Hello</p>
835 * @result <p>Hello</p>
839 * @param Function fn A function to unbind from the select event on each of the matched elements.
844 * Removes all bound select events from each of the matched elements.
846 * @example $("p").unselect();
847 * @before <p onselect="alert('Hello');">Hello</p>
848 * @result <p>Hello</p>
856 * Bind a function to the mouseup event of each matched element.
858 * @example $("p").mouseup( function() { alert("Hello"); } );
859 * @before <p>Hello</p>
860 * @result <p onmouseup="alert('Hello');">Hello</p>
864 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
869 * Trigger the mouseup event of each matched element. This causes all of the functions
870 * that have been bound to thet mouseup event to be executed.
872 * @example $("p").mouseup();
873 * @before <p onmouseup="alert('Hello');">Hello</p>
874 * @result alert('Hello');
882 * Bind a function to the mouseup event of each matched element, which will only be executed once.
883 * Unlike a call to the normal .mouseup() method, calling .onemouseup() causes the bound function to be
884 * only executed the first time it is triggered, and never again (unless it is re-bound).
886 * @example $("p").onemouseup( function() { alert("Hello"); } );
887 * @before <p onmouseup="alert('Hello');">Hello</p>
888 * @result alert('Hello'); // Only executed for the first mouseup
892 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
897 * Removes a bound mouseup event from each of the matched
898 * elements. You must pass the identical function that was used in the original
901 * @example $("p").unmouseup( myFunction );
902 * @before <p onmouseup="myFunction">Hello</p>
903 * @result <p>Hello</p>
907 * @param Function fn A function to unbind from the mouseup event on each of the matched elements.
912 * Removes all bound mouseup events from each of the matched elements.
914 * @example $("p").unmouseup();
915 * @before <p onmouseup="alert('Hello');">Hello</p>
916 * @result <p>Hello</p>
924 * Bind a function to the unload event of each matched element.
926 * @example $("p").unload( function() { alert("Hello"); } );
927 * @before <p>Hello</p>
928 * @result <p onunload="alert('Hello');">Hello</p>
932 * @param Function fn A function to bind to the unload event on each of the matched elements.
933 * @cat Events/Browser
937 * Trigger the unload event of each matched element. This causes all of the functions
938 * that have been bound to thet unload event to be executed.
940 * @example $("p").unload();
941 * @before <p onunload="alert('Hello');">Hello</p>
942 * @result alert('Hello');
946 * @cat Events/Browser
950 * Bind a function to the unload event of each matched element, which will only be executed once.
951 * Unlike a call to the normal .unload() method, calling .oneunload() causes the bound function to be
952 * only executed the first time it is triggered, and never again (unless it is re-bound).
954 * @example $("p").oneunload( function() { alert("Hello"); } );
955 * @before <p onunload="alert('Hello');">Hello</p>
956 * @result alert('Hello'); // Only executed for the first unload
960 * @param Function fn A function to bind to the unload event on each of the matched elements.
961 * @cat Events/Browser
965 * Removes a bound unload event from each of the matched
966 * elements. You must pass the identical function that was used in the original
969 * @example $("p").ununload( myFunction );
970 * @before <p onunload="myFunction">Hello</p>
971 * @result <p>Hello</p>
975 * @param Function fn A function to unbind from the unload event on each of the matched elements.
976 * @cat Events/Browser
980 * Removes all bound unload events from each of the matched elements.
982 * @example $("p").ununload();
983 * @before <p onunload="alert('Hello');">Hello</p>
984 * @result <p>Hello</p>
988 * @cat Events/Browser
992 * Bind a function to the change event of each matched element.
994 * @example $("p").change( function() { alert("Hello"); } );
995 * @before <p>Hello</p>
996 * @result <p onchange="alert('Hello');">Hello</p>
1000 * @param Function fn A function to bind to the change event on each of the matched elements.
1005 * Trigger the change event of each matched element. This causes all of the functions
1006 * that have been bound to thet change event to be executed.
1008 * @example $("p").change();
1009 * @before <p onchange="alert('Hello');">Hello</p>
1010 * @result alert('Hello');
1018 * Bind a function to the change event of each matched element, which will only be executed once.
1019 * Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be
1020 * only executed the first time it is triggered, and never again (unless it is re-bound).
1022 * @example $("p").onechange( function() { alert("Hello"); } );
1023 * @before <p onchange="alert('Hello');">Hello</p>
1024 * @result alert('Hello'); // Only executed for the first change
1028 * @param Function fn A function to bind to the change event on each of the matched elements.
1033 * Removes a bound change event from each of the matched
1034 * elements. You must pass the identical function that was used in the original
1037 * @example $("p").unchange( myFunction );
1038 * @before <p onchange="myFunction">Hello</p>
1039 * @result <p>Hello</p>
1043 * @param Function fn A function to unbind from the change event on each of the matched elements.
1048 * Removes all bound change events from each of the matched elements.
1050 * @example $("p").unchange();
1051 * @before <p onchange="alert('Hello');">Hello</p>
1052 * @result <p>Hello</p>
1060 * Bind a function to the mouseout event of each matched element.
1062 * @example $("p").mouseout( function() { alert("Hello"); } );
1063 * @before <p>Hello</p>
1064 * @result <p onmouseout="alert('Hello');">Hello</p>
1068 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1073 * Trigger the mouseout event of each matched element. This causes all of the functions
1074 * that have been bound to thet mouseout event to be executed.
1076 * @example $("p").mouseout();
1077 * @before <p onmouseout="alert('Hello');">Hello</p>
1078 * @result alert('Hello');
1086 * Bind a function to the mouseout event of each matched element, which will only be executed once.
1087 * Unlike a call to the normal .mouseout() method, calling .onemouseout() causes the bound function to be
1088 * only executed the first time it is triggered, and never again (unless it is re-bound).
1090 * @example $("p").onemouseout( function() { alert("Hello"); } );
1091 * @before <p onmouseout="alert('Hello');">Hello</p>
1092 * @result alert('Hello'); // Only executed for the first mouseout
1096 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
1101 * Removes a bound mouseout event from each of the matched
1102 * elements. You must pass the identical function that was used in the original
1105 * @example $("p").unmouseout( myFunction );
1106 * @before <p onmouseout="myFunction">Hello</p>
1107 * @result <p>Hello</p>
1111 * @param Function fn A function to unbind from the mouseout event on each of the matched elements.
1116 * Removes all bound mouseout events from each of the matched elements.
1118 * @example $("p").unmouseout();
1119 * @before <p onmouseout="alert('Hello');">Hello</p>
1120 * @result <p>Hello</p>
1128 * Bind a function to the keyup event of each matched element.
1130 * @example $("p").keyup( function() { alert("Hello"); } );
1131 * @before <p>Hello</p>
1132 * @result <p onkeyup="alert('Hello');">Hello</p>
1136 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1137 * @cat Events/Keyboard
1141 * Trigger the keyup event of each matched element. This causes all of the functions
1142 * that have been bound to thet keyup event to be executed.
1144 * @example $("p").keyup();
1145 * @before <p onkeyup="alert('Hello');">Hello</p>
1146 * @result alert('Hello');
1150 * @cat Events/Keyboard
1154 * Bind a function to the keyup event of each matched element, which will only be executed once.
1155 * Unlike a call to the normal .keyup() method, calling .onekeyup() causes the bound function to be
1156 * only executed the first time it is triggered, and never again (unless it is re-bound).
1158 * @example $("p").onekeyup( function() { alert("Hello"); } );
1159 * @before <p onkeyup="alert('Hello');">Hello</p>
1160 * @result alert('Hello'); // Only executed for the first keyup
1164 * @param Function fn A function to bind to the keyup event on each of the matched elements.
1165 * @cat Events/Keyboard
1169 * Removes a bound keyup event from each of the matched
1170 * elements. You must pass the identical function that was used in the original
1173 * @example $("p").unkeyup( myFunction );
1174 * @before <p onkeyup="myFunction">Hello</p>
1175 * @result <p>Hello</p>
1179 * @param Function fn A function to unbind from the keyup event on each of the matched elements.
1180 * @cat Events/Keyboard
1184 * Removes all bound keyup events from each of the matched elements.
1186 * @example $("p").unkeyup();
1187 * @before <p onkeyup="alert('Hello');">Hello</p>
1188 * @result <p>Hello</p>
1192 * @cat Events/Keyboard
1196 * Bind a function to the click event of each matched element.
1198 * @example $("p").click( function() { alert("Hello"); } );
1199 * @before <p>Hello</p>
1200 * @result <p onclick="alert('Hello');">Hello</p>
1204 * @param Function fn A function to bind to the click event on each of the matched elements.
1209 * Trigger the click event of each matched element. This causes all of the functions
1210 * that have been bound to thet click event to be executed.
1212 * @example $("p").click();
1213 * @before <p onclick="alert('Hello');">Hello</p>
1214 * @result alert('Hello');
1222 * Bind a function to the click event of each matched element, which will only be executed once.
1223 * Unlike a call to the normal .click() method, calling .oneclick() causes the bound function to be
1224 * only executed the first time it is triggered, and never again (unless it is re-bound).
1226 * @example $("p").oneclick( function() { alert("Hello"); } );
1227 * @before <p onclick="alert('Hello');">Hello</p>
1228 * @result alert('Hello'); // Only executed for the first click
1232 * @param Function fn A function to bind to the click event on each of the matched elements.
1237 * Removes a bound click event from each of the matched
1238 * elements. You must pass the identical function that was used in the original
1241 * @example $("p").unclick( myFunction );
1242 * @before <p onclick="myFunction">Hello</p>
1243 * @result <p>Hello</p>
1247 * @param Function fn A function to unbind from the click event on each of the matched elements.
1252 * Removes all bound click events from each of the matched elements.
1254 * @example $("p").unclick();
1255 * @before <p onclick="alert('Hello');">Hello</p>
1256 * @result <p>Hello</p>
1264 * Bind a function to the resize event of each matched element.
1266 * @example $("p").resize( function() { alert("Hello"); } );
1267 * @before <p>Hello</p>
1268 * @result <p onresize="alert('Hello');">Hello</p>
1272 * @param Function fn A function to bind to the resize event on each of the matched elements.
1273 * @cat Events/Browser
1277 * Trigger the resize event of each matched element. This causes all of the functions
1278 * that have been bound to thet resize event to be executed.
1280 * @example $("p").resize();
1281 * @before <p onresize="alert('Hello');">Hello</p>
1282 * @result alert('Hello');
1286 * @cat Events/Browser
1290 * Bind a function to the resize event of each matched element, which will only be executed once.
1291 * Unlike a call to the normal .resize() method, calling .oneresize() causes the bound function to be
1292 * only executed the first time it is triggered, and never again (unless it is re-bound).
1294 * @example $("p").oneresize( function() { alert("Hello"); } );
1295 * @before <p onresize="alert('Hello');">Hello</p>
1296 * @result alert('Hello'); // Only executed for the first resize
1300 * @param Function fn A function to bind to the resize event on each of the matched elements.
1301 * @cat Events/Browser
1305 * Removes a bound resize event from each of the matched
1306 * elements. You must pass the identical function that was used in the original
1309 * @example $("p").unresize( myFunction );
1310 * @before <p onresize="myFunction">Hello</p>
1311 * @result <p>Hello</p>
1315 * @param Function fn A function to unbind from the resize event on each of the matched elements.
1316 * @cat Events/Browser
1320 * Removes all bound resize events from each of the matched elements.
1322 * @example $("p").unresize();
1323 * @before <p onresize="alert('Hello');">Hello</p>
1324 * @result <p>Hello</p>
1328 * @cat Events/Browser
1332 * Bind a function to the mousemove event of each matched element.
1334 * @example $("p").mousemove( function() { alert("Hello"); } );
1335 * @before <p>Hello</p>
1336 * @result <p onmousemove="alert('Hello');">Hello</p>
1340 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1345 * Trigger the mousemove event of each matched element. This causes all of the functions
1346 * that have been bound to thet mousemove event to be executed.
1348 * @example $("p").mousemove();
1349 * @before <p onmousemove="alert('Hello');">Hello</p>
1350 * @result alert('Hello');
1358 * Bind a function to the mousemove event of each matched element, which will only be executed once.
1359 * Unlike a call to the normal .mousemove() method, calling .onemousemove() causes the bound function to be
1360 * only executed the first time it is triggered, and never again (unless it is re-bound).
1362 * @example $("p").onemousemove( function() { alert("Hello"); } );
1363 * @before <p onmousemove="alert('Hello');">Hello</p>
1364 * @result alert('Hello'); // Only executed for the first mousemove
1366 * @name onemousemove
1368 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
1373 * Removes a bound mousemove event from each of the matched
1374 * elements. You must pass the identical function that was used in the original
1377 * @example $("p").unmousemove( myFunction );
1378 * @before <p onmousemove="myFunction">Hello</p>
1379 * @result <p>Hello</p>
1383 * @param Function fn A function to unbind from the mousemove event on each of the matched elements.
1388 * Removes all bound mousemove events from each of the matched elements.
1390 * @example $("p").unmousemove();
1391 * @before <p onmousemove="alert('Hello');">Hello</p>
1392 * @result <p>Hello</p>
1400 * Bind a function to the mousedown event of each matched element.
1402 * @example $("p").mousedown( function() { alert("Hello"); } );
1403 * @before <p>Hello</p>
1404 * @result <p onmousedown="alert('Hello');">Hello</p>
1408 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1413 * Trigger the mousedown event of each matched element. This causes all of the functions
1414 * that have been bound to thet mousedown event to be executed.
1416 * @example $("p").mousedown();
1417 * @before <p onmousedown="alert('Hello');">Hello</p>
1418 * @result alert('Hello');
1426 * Bind a function to the mousedown event of each matched element, which will only be executed once.
1427 * Unlike a call to the normal .mousedown() method, calling .onemousedown() causes the bound function to be
1428 * only executed the first time it is triggered, and never again (unless it is re-bound).
1430 * @example $("p").onemousedown( function() { alert("Hello"); } );
1431 * @before <p onmousedown="alert('Hello');">Hello</p>
1432 * @result alert('Hello'); // Only executed for the first mousedown
1434 * @name onemousedown
1436 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1441 * Removes a bound mousedown event from each of the matched
1442 * elements. You must pass the identical function that was used in the original
1445 * @example $("p").unmousedown( myFunction );
1446 * @before <p onmousedown="myFunction">Hello</p>
1447 * @result <p>Hello</p>
1451 * @param Function fn A function to unbind from the mousedown event on each of the matched elements.
1456 * Removes all bound mousedown events from each of the matched elements.
1458 * @example $("p").unmousedown();
1459 * @before <p onmousedown="alert('Hello');">Hello</p>
1460 * @result <p>Hello</p>
1468 * Bind a function to the mouseover event of each matched element.
1470 * @example $("p").mouseover( function() { alert("Hello"); } );
1471 * @before <p>Hello</p>
1472 * @result <p onmouseover="alert('Hello');">Hello</p>
1476 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1481 * Trigger the mouseover event of each matched element. This causes all of the functions
1482 * that have been bound to thet mousedown event to be executed.
1484 * @example $("p").mouseover();
1485 * @before <p onmouseover="alert('Hello');">Hello</p>
1486 * @result alert('Hello');
1494 * Bind a function to the mouseover event of each matched element, which will only be executed once.
1495 * Unlike a call to the normal .mouseover() method, calling .onemouseover() causes the bound function to be
1496 * only executed the first time it is triggered, and never again (unless it is re-bound).
1498 * @example $("p").onemouseover( function() { alert("Hello"); } );
1499 * @before <p onmouseover="alert('Hello');">Hello</p>
1500 * @result alert('Hello'); // Only executed for the first mouseover
1502 * @name onemouseover
1504 * @param Function fn A function to bind to the mouseover event on each of the matched elements.
1509 * Removes a bound mouseover event from each of the matched
1510 * elements. You must pass the identical function that was used in the original
1513 * @example $("p").unmouseover( myFunction );
1514 * @before <p onmouseover="myFunction">Hello</p>
1515 * @result <p>Hello</p>
1519 * @param Function fn A function to unbind from the mouseover event on each of the matched elements.
1524 * Removes all bound mouseover events from each of the matched elements.
1526 * @example $("p").unmouseover();
1527 * @before <p onmouseover="alert('Hello');">Hello</p>
1528 * @result <p>Hello</p>
1535 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1536 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
1537 "submit,keydown,keypress,keyup,error").split(",");
1539 // Go through all the event names, but make sure that
1540 // it is enclosed properly
1541 for ( var i = 0; i < e.length; i++ ) new function(){
1545 // Handle event binding
1546 jQuery.fn[o] = function(f){
1547 return f ? this.bind(o, f) : this.trigger(o);
1550 // Handle event unbinding
1551 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
1553 // Finally, handle events that only fire once
1554 jQuery.fn["one"+o] = function(f){
1555 // save cloned reference to this
1556 var element = jQuery(this);
1557 var handler = function() {
1558 // unbind itself when executed
1559 element.unbind(o, handler);
1561 // apply original handler with the same arguments
1562 return f.apply(this, arguments);
1564 return this.bind(o, handler);
1569 // If Mozilla is used
1570 if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
1571 // Use the handy event callback
1572 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1574 // If IE is used, use the excellent hack by Matthias Miller
1575 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1576 } else if ( jQuery.browser.msie ) {
1578 // Only works if you document.write() it
1579 document.write("<scr" + "ipt id=__ie_init defer=true " +
1580 "src=//:><\/script>");
1582 // Use the defer script hack
1583 var script = document.getElementById("__ie_init");
1584 if (script) // script does not exist if jQuery is loaded dynamically
1585 script.onreadystatechange = function() {
1586 if ( this.readyState != "complete" ) return;
1587 this.parentNode.removeChild( this );
1591 // Clear from memory
1594 // If Safari is used
1595 } else if ( jQuery.browser.safari ) {
1596 // Continually check to see if the document.readyState is valid
1597 jQuery.safariTimer = setInterval(function(){
1598 // loaded and complete are both valid states
1599 if ( document.readyState == "loaded" ||
1600 document.readyState == "complete" ) {
1602 // If either one are found, remove the timer
1603 clearInterval( jQuery.safariTimer );
1604 jQuery.safariTimer = null;
1606 // and execute any waiting functions
1612 // A fallback to window.onload, that will always work
1613 jQuery.event.add( window, "load", jQuery.ready );
1617 // Clean up after IE to avoid memory leaks
1618 if (jQuery.browser.msie) jQuery(window).unload(function() {
1619 var event = jQuery.event, global = event.global;
1620 for (var type in global) {
1621 var els = global[type], i = els.length;
1622 if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i);