diff --git a/entries/ajaxComplete-shorthand.xml b/entries/ajaxComplete-shorthand.xml new file mode 100644 index 00000000..73d766d5 --- /dev/null +++ b/entries/ajaxComplete-shorthand.xml @@ -0,0 +1,19 @@ + + + .ajaxComplete() + Register a handler to be called when Ajax requests complete. This is an AjaxEvent. + + 1.0 + + The function to be invoked. + + + +
+

This API is deprecated. Use .on( "ajaxComplete", handler ) instead.

+
+
+ + + +
diff --git a/entries/ajaxComplete.xml b/entries/ajaxComplete.xml index f96dc4cf..168865e7 100644 --- a/entries/ajaxComplete.xml +++ b/entries/ajaxComplete.xml @@ -1,8 +1,12 @@ - - .ajaxComplete() + + ajaxComplete event + Register a handler to be called when Ajax requests complete. This is an AjaxEvent. - 1.0 + 1.7 + + The string "ajaxComplete". + @@ -10,9 +14,11 @@ The function to be invoked. - Register a handler to be called when Ajax requests complete. This is an AjaxEvent. -

Whenever an Ajax request completes, jQuery triggers the ajaxComplete event. Any and all handlers that have been registered with the .ajaxComplete() method are executed at this time.

+
+

This page describes the ajaxComplete event. For the deprecated .ajaxComplete() method, see .ajaxComplete().

+
+

Whenever an Ajax request completes, jQuery triggers the ajaxComplete event. Any and all registered ajaxComplete handlers are executed at this time.

To observe this method in action, set up a basic Ajax load request:


 <div class="trigger">Trigger</div>
@@ -21,38 +27,39 @@
     

Attach the event handler to the document:


-$( document ).ajaxComplete(function() {
+$( document ).on( "ajaxComplete", function() {
   $( ".log" ).text( "Triggered ajaxComplete handler." );
-});
+} );
     

Now, make an Ajax request using any jQuery method:


-$( ".trigger" ).click(function() {
+$( ".trigger)" ).on( "click", function() {
   $( ".result" ).load( "ajax/test.html" );
-});
+} );
     

When the user clicks the element with class trigger and the Ajax request completes, the log message is displayed.

All ajaxComplete handlers are invoked, regardless of what Ajax request was completed. If you must differentiate between the requests, use the parameters passed to the handler. Each time an ajaxComplete handler is executed, it is passed the event object, the XMLHttpRequest object, and the settings object that was used in the creation of the request. For example, you can restrict the callback to only handling events dealing with a particular URL:


-$( document ).ajaxComplete(function( event, xhr, settings ) {
+$( document ).on( "ajaxComplete", function( event, xhr, settings ) {
   if ( settings.url === "ajax/test.html" ) {
     $( ".log" ).text( "Triggered ajaxComplete handler. The result is " +
       xhr.responseText );
   }
-});
+} );
     

Note: You can get the returned Ajax contents by looking at xhr.responseText.

- - + + Show a message when an Ajax request completes. Request Complete." ); -}); +} ); ]]> +
diff --git a/entries/ajaxError-shorthand.xml b/entries/ajaxError-shorthand.xml new file mode 100644 index 00000000..c1a306bd --- /dev/null +++ b/entries/ajaxError-shorthand.xml @@ -0,0 +1,19 @@ + + + .ajaxError() + Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event. + + 1.0 + + The function to be invoked. + + + +
+

This API is deprecated. Use .on( "ajaxError", handler ) instead.

+
+
+ + + +
diff --git a/entries/ajaxError.xml b/entries/ajaxError.xml index 19abee09..d18cf977 100644 --- a/entries/ajaxError.xml +++ b/entries/ajaxError.xml @@ -1,8 +1,12 @@ - - .ajaxError() + + ajaxError event + Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event. - 1.0 + 1.7 + + The string "ajaxError". + The function to be invoked. @@ -11,9 +15,11 @@ - Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event. -

Whenever an Ajax request completes with an error, jQuery triggers the ajaxError event. Any and all handlers that have been registered with the .ajaxError() method are executed at this time. Note: This handler is not called for cross-domain script and cross-domain JSONP requests.

+
+

This page describes the ajaxError event. For the deprecated .ajaxError() method, see .ajaxError().

+
+

Whenever an Ajax request completes with an error, jQuery triggers the ajaxError event. Any and all registered ajaxError handlers are executed at this time. Note: This handler is not called for cross-domain script and cross-domain JSONP requests.

To observe this method in action, set up a basic Ajax load request.


 <button class="trigger">Trigger</button>
@@ -22,35 +28,37 @@
     

Attach the event handler to the document:


-$( document ).ajaxError(function() {
+$( document ).on( "ajaxError", function() {
   $( ".log" ).text( "Triggered ajaxError handler." );
-});
+} );
     

Now, make an Ajax request using any jQuery method:


 $( "button.trigger" ).on( "click", function() {
   $( "div.result" ).load( "ajax/missing.html" );
-});
+} );
     

When the user clicks the button and the Ajax request fails, because the requested file is missing, the log message is displayed.

All ajaxError handlers are invoked, regardless of what Ajax request was completed. To differentiate between the requests, use the parameters passed to the handler. Each time an ajaxError handler is executed, it is passed the event object, the jqXHR object (prior to jQuery 1.5, the XHR object), and the settings object that was used in the creation of the request. When an HTTP error occurs, the fourth argument (thrownError) receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." For example, to restrict the error callback to only handling events dealing with a particular URL:


-$( document ).ajaxError(function( event, jqxhr, settings, thrownError ) {
+$( document ).on( "ajaxError", function( event, jqxhr, settings, thrownError ) {
   if ( settings.url == "ajax/missing.html" ) {
     $( "div.log" ).text( "Triggered ajaxError handler." );
   }
-});
+} ); +
- - + + Show a message when an Ajax request fails. Error requesting page " + settings.url + "" ); -}); +} ); ]]> +
diff --git a/entries/ajaxSend-shorthand.xml b/entries/ajaxSend-shorthand.xml new file mode 100644 index 00000000..4c1dc9cc --- /dev/null +++ b/entries/ajaxSend-shorthand.xml @@ -0,0 +1,19 @@ + + + .ajaxSend() + Attach a function to be executed before an Ajax request is sent. This is an Ajax Event. + + 1.0 + + The function to be invoked. + + + +
+

This API is deprecated. Use .on( "ajaxSend", handler ) instead.

+
+
+ + + +
diff --git a/entries/ajaxSend.xml b/entries/ajaxSend.xml index db814fee..ad01194e 100644 --- a/entries/ajaxSend.xml +++ b/entries/ajaxSend.xml @@ -1,8 +1,12 @@ - - .ajaxSend() + + ajaxSend event + Attach a function to be executed before an Ajax request is sent. This is an Ajax Event. - 1.0 + 1.7 + + The string "ajaxSend". + The function to be invoked. @@ -10,9 +14,11 @@ - Attach a function to be executed before an Ajax request is sent. This is an Ajax Event. -

Whenever an Ajax request is about to be sent, jQuery triggers the ajaxSend event. Any and all handlers that have been registered with the .ajaxSend() method are executed at this time.

+
+

This page describes the ajaxSend event. For the deprecated .ajaxSend() method, see .ajaxSend().

+
+

Whenever an Ajax request is about to be sent, jQuery triggers the ajaxSend event. Any and all registerd ajaxSend handlers are executed at this time.

To observe this method in action, set up a basic Ajax load request:


 <div class="trigger">Trigger</div>
@@ -21,36 +27,37 @@
     

Attach the event handler to the document:


-$( document ).ajaxSend(function() {
+$( document ).on( "ajaxSend", function() {
   $( ".log" ).text( "Triggered ajaxSend handler." );
-});
+} );
     

Now, make an Ajax request using any jQuery method:


-$( ".trigger" ).click(function() {
+$( ".trigger)" ).on( "click", function() {
   $( ".result" ).load( "ajax/test.html" );
-});
+} );
     

When the user clicks the element with class trigger and the Ajax request is about to begin, the log message is displayed.

All ajaxSend handlers are invoked, regardless of what Ajax request is to be sent. If you must differentiate between the requests, use the parameters passed to the handler. Each time an ajaxSend handler is executed, it is passed the event object, the jqXHR object (in version 1.4, XMLHttpRequestobject), and the settings object that was used in the creation of the Ajax request. For example, you can restrict the callback to only handling events dealing with a particular URL:


-$( document ).ajaxSend(function( event, jqxhr, settings ) {
+$( document ).on( "ajaxSend", function( event, jqxhr, settings ) {
   if ( settings.url == "ajax/test.html" ) {
     $( ".log" ).text( "Triggered ajaxSend handler." );
   }
-});
+} );
     
- - + + Show a message before an Ajax request is sent. Starting request at " + settings.url + "" ); -}); +} ); ]]> +
diff --git a/entries/ajaxStart-shorthand.xml b/entries/ajaxStart-shorthand.xml new file mode 100644 index 00000000..41c7c71a --- /dev/null +++ b/entries/ajaxStart-shorthand.xml @@ -0,0 +1,19 @@ + + + .ajaxStart() + Register a handler to be called when the first Ajax request begins. This is an Ajax Event. + + 1.0 + + The function to be invoked. + + + +
+

This API is deprecated. Use .on( "ajaxStart", handler ) instead.

+
+
+ + + +
diff --git a/entries/ajaxStart.xml b/entries/ajaxStart.xml index bf7fc14a..3d8f4df4 100644 --- a/entries/ajaxStart.xml +++ b/entries/ajaxStart.xml @@ -1,15 +1,21 @@ - - .ajaxStart() + + ajaxStart event + Register a handler to be called when the first Ajax request begins. This is an Ajax Event. - 1.0 + 1.7 + + The string "ajaxStart". + The function to be invoked. - Register a handler to be called when the first Ajax request begins. This is an Ajax Event. -

Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the ajaxStart event. Any and all handlers that have been registered with the .ajaxStart() method are executed at this time.

+
+

This page describes the ajaxStart event. For the deprecated .ajaxStart() method, see .ajaxStart().

+
+

Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the ajaxStart event. Any and all handlers that have been registered with .on( "ajaxStart", ... ) are executed at this time.

To observe this method in action, set up a basic Ajax load request:


 <div class="trigger">Trigger</div>
@@ -18,28 +24,29 @@
     

Attach the event handler to any element:


-$( document ).ajaxStart(function() {
+$( document ).on( "ajaxStart", function() {
   $( ".log" ).text( "Triggered ajaxStart handler." );
-});
+} );
     

Now, make an Ajax request using any jQuery method:


-$( ".trigger" ).click(function() {
+$( ".trigger" ).on( "click", function() {
   $( ".result" ).load( "ajax/test.html" );
-});
+} );
     

When the user clicks the element with class trigger and the Ajax request is sent, the log message is displayed.

- - + + Show a loading message whenever an Ajax request starts (and none is already active). +
diff --git a/entries/ajaxStop-shorthand.xml b/entries/ajaxStop-shorthand.xml new file mode 100644 index 00000000..e4b5ab83 --- /dev/null +++ b/entries/ajaxStop-shorthand.xml @@ -0,0 +1,19 @@ + + + .ajaxStop() + Register a handler to be called when all Ajax requests have completed. This is an Ajax Event. + + 1.0 + + The function to be invoked. + + + +
+

This API is deprecated. Use .on( "ajaxStop", handler ) instead.

+
+
+ + + +
diff --git a/entries/ajaxStop.xml b/entries/ajaxStop.xml index 073dd208..f42c7444 100644 --- a/entries/ajaxStop.xml +++ b/entries/ajaxStop.xml @@ -1,15 +1,21 @@ - - .ajaxStop() + + ajaxStop event Register a handler to be called when all Ajax requests have completed. This is an Ajax Event. - 1.0 + 1.7 + + The string "ajaxStop". + The function to be invoked. -

Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the ajaxStop event. Any and all handlers that have been registered with the .ajaxStop() method are executed at this time. The ajaxStop event is also triggered if the last outstanding Ajax request is cancelled by returning false within the beforeSend callback function.

+
+

This page describes the ajaxStop event. For the deprecated .ajaxStop() method, see .ajaxStop().

+
+

Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the ajaxStop event. Any and all registered ajaxStop handlers are executed at this time. The ajaxStop event is also triggered if the last outstanding Ajax request is cancelled by returning false within the beforeSend callback function.

To observe this method in action, set up a basic Ajax load request:


 <div class="trigger">Trigger</div>
@@ -18,28 +24,29 @@
     

Attach the event handler to the document:


-$( document ).ajaxStop(function() {
+$( document ).on( "ajaxStop", function() {
   $( ".log" ).text( "Triggered ajaxStop handler." );
-});
+} );
     

Now, make an Ajax request using any jQuery method:


-$( ".trigger" ).click(function() {
+$( ".trigger" ).on( "click", function() {
   $( ".result" ).load( "ajax/test.html" );
-});
+} );
     

When the user clicks the element with class trigger and the Ajax request completes, the log message is displayed.

- - + + Hide a loading message after all the Ajax requests have stopped. +
diff --git a/entries/ajaxSuccess-shorthand.xml b/entries/ajaxSuccess-shorthand.xml new file mode 100644 index 00000000..358b5ff5 --- /dev/null +++ b/entries/ajaxSuccess-shorthand.xml @@ -0,0 +1,19 @@ + + + .ajaxSuccess() + Attach a function to be executed whenever an Ajax request completes successfully. This is an Ajax Event. + + 1.0 + + The function to be invoked. + + + +
+

This API is deprecated. Use .on( "ajaxSuccess", handler ) instead.

+
+
+ + + +
diff --git a/entries/ajaxSuccess.xml b/entries/ajaxSuccess.xml index 840ec028..e92a1269 100644 --- a/entries/ajaxSuccess.xml +++ b/entries/ajaxSuccess.xml @@ -1,8 +1,12 @@ - - .ajaxSuccess() + + ajaxSuccess event + Attach a function to be executed whenever an Ajax request completes successfully. This is an Ajax Event. - 1.0 + 1.7 + + The string "ajaxSuccess". + The function to be invoked. @@ -11,9 +15,11 @@ - Attach a function to be executed whenever an Ajax request completes successfully. This is an Ajax Event. -

Whenever an Ajax request completes successfully, jQuery triggers the ajaxSuccess event. Any and all handlers that have been registered with the .ajaxSuccess() method are executed at this time.

+
+

This page describes the ajaxSuccess event. For the deprecated .ajaxSuccess() method, see .ajaxSuccess().

+
+

Whenever an Ajax request completes successfully, jQuery triggers the ajaxSuccess event. Any and all registered ajaxSuccess handlers are executed at this time.

To observe this method in action, set up a basic Ajax load request:


 <div class="trigger">Trigger</div>
@@ -22,38 +28,39 @@
     

Attach the event handler to any element:


-$(document).ajaxSuccess(function() {
+$( document ).on( "ajaxSuccess", function() {
   $( ".log" ).text( "Triggered ajaxSuccess handler." );
-});
+} );
     

Now, make an Ajax request using any jQuery method:


 $( ".trigger" ).on( "click", function() {
   $( ".result" ).load( "ajax/test.html" );
-});
+} );
     

When the user clicks the element with class trigger and the Ajax request completes successfully, the log message is displayed.

All ajaxSuccess handlers are invoked, regardless of what Ajax request was completed. If you must differentiate between the requests, you can use the parameters passed to the handler. Each time an ajaxSuccess handler is executed, it is passed the event object, the XMLHttpRequest object, and the settings object that was used in the creation of the request. For example, you can restrict the callback to only handling events dealing with a particular URL:


-$( document ).ajaxSuccess(function( event, xhr, settings ) {
+$( document ).on( "ajaxSuccess", function( event, xhr, settings ) {
   if ( settings.url == "ajax/test.html" ) {
     $( ".log" ).text( "Triggered ajaxSuccess handler. The Ajax response was: " +
       xhr.responseText );
   }
-});
+} );
     

Note: You can get the returned Ajax contents by looking at xhr.responseXML or xhr.responseText for xml and html respectively.

- - + + Show a message when an Ajax request completes successfully. Successful Request!" ); -}); +} ); ]]> +
diff --git a/entries/animate.xml b/entries/animate.xml index 57af4823..1ece251c 100644 --- a/entries/animate.xml +++ b/entries/animate.xml @@ -45,7 +45,7 @@

To animate the opacity, left offset, and height of the image simultaneously:


-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).animate({
     opacity: 0.25,
     left: "+=50",
@@ -101,7 +101,7 @@ $( "li" ).animate({
     

As of jQuery version 1.4, you can set per-property easing functions within a single .animate() call. In the first version of .animate(), each property can take an array as its value: The first member of the array is the CSS property and the second member is an easing function. If a per-property easing function is not defined for a particular property, it uses the value of the .animate() method's optional easing argument. If the easing argument is not defined, the default swing function is used.

For example, to simultaneously animate the width and height with the swing easing function and the opacity with the linear easing function:


-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).animate({
     width: [ "toggle", "swing" ],
     height: [ "toggle", "swing" ],
@@ -113,7 +113,7 @@ $( "#clickme" ).click(function() {
     

In the second version of .animate(), the options object can include the specialEasing property, which is itself an object of CSS properties and their corresponding easing functions. For example, to simultaneously animate the width using the linear easing function and the height using the easeOutBounce easing function:


-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).animate({
     width: "toggle",
     height: "toggle"
@@ -137,7 +137,7 @@ $( "#clickme" ).click(function() {
     
     Animates a div's left property with a relative value. Click several times on the buttons to see the relative animations queued up.
     
@@ -191,7 +191,7 @@ $( "#left" ).click(function(){
 
 The second button starts a traditional chained animation, where each animation will start once the previous animation on the element has completed.
     
     Animates the first div's left property and synchronizes the remaining divs, using the step function to set their left properties at each stage of the animation. 
     
     Change the color of any div that is animated.
     Display the checked attribute and property of a checkbox as it changes.
       " + $input.attr( "checked" ) + "
" + ".prop( 'checked' ): " + $input.prop( "checked" ) + "
" + ".is( ':checked' ): " + $input.is( ":checked" ) + "" ); - }) - .change(); + } ) + .trigger( "change" ); ]]>
As of jQuery 3.0, .bind() has been deprecated. It was superseded by the .on() method for attaching event handlers to a document since jQuery 1.7, so its use was already discouraged. For earlier versions, the .bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to .bind() occurs. For more flexible event binding, see the discussion of event delegation in .on().

Any string is legal for eventType; if the string is not the name of a native DOM event, then the handler is bound to a custom event. These events are never called by the browser, but may be triggered manually from other JavaScript code using .trigger() or .triggerHandler().

If the eventType string contains a period (.) character, then the event is namespaced. The period character separates the event from its namespace. For example, in the call .bind( "click.name", handler ), the string click is the event type, and the string name is the namespace. Namespacing allows us to unbind or trigger some events of a type without affecting others. See the discussion of .unbind() for more information.

-

There are shorthand methods for some standard browser events such as .click() that can be used to attach or trigger event handlers. For a complete list of shorthand methods, see the events category.

+

Some events have dedicated pages, describing specifics of their usage. For a complete list of those events, see the events category.

When an event reaches an element, all handlers bound to that event type for the element are fired. If there are multiple handlers registered, they will always execute in the order in which they were bound. After all handlers have executed, the event continues along the normal event propagation path.

A basic usage of .bind() is:


@@ -221,7 +221,7 @@ $( "p" ).bind( "myCustomEvent", function( e, myName, myValue ) {
     .fadeIn( 30 )
     .fadeOut( 1000 );
   });
-$( "button" ).click(function() {
+$( "button)" ).on( "click", function() {
   $( "p" ).trigger( "myCustomEvent", [ "John" ] );
 });
 ]]>
diff --git a/entries/blur-shorthand.xml b/entries/blur-shorthand.xml
new file mode 100644
index 00000000..589a1ceb
--- /dev/null
+++ b/entries/blur-shorthand.xml
@@ -0,0 +1,37 @@
+
+
+  .blur()
+  Bind an event handler to the "blur" event, or trigger that event on an element.
+  
+    1.0
+    
+      A function to execute each time the event is triggered.
+      
+    
+  
+  
+    1.4.3
+    
+      An object containing data that will be passed to the event handler.
+    
+    
+      A function to execute each time the event is triggered.
+      
+    
+  
+  
+    1.0
+  
+  
+    
+

This API is deprecated.

+

Instead of .blur( handler ) or .blur( eventData, handler ), use .on( "blur", handler ) or .on( "blur", eventData, handler ), respectively.

+

Instead of .blur(), use .trigger( "blur" ).

+
+
+ + + + + +
diff --git a/entries/blur.xml b/entries/blur.xml index 11afbd6a..d99003e9 100644 --- a/entries/blur.xml +++ b/entries/blur.xml @@ -1,16 +1,15 @@ - - .blur() - Bind an event handler to the "blur" JavaScript event, or trigger that event on an element. + + +Bind an event handler to the "blur" event, or trigger that event on an element. + + blur event + Bind an event handler to the "blur" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "blur". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

This method is a shortcut for .on( "blur", handler ) in the first two variations, and .trigger( "blur" ) in the third.

+
+

This page describes the blur event. For the deprecated .blur() method, see .blur().

+

The blur event is sent to an element when it loses focus. Originally, this event was only applicable to form elements, such as <input>. In recent browsers, the domain of the event has been extended to include all element types. An element can lose focus via keyboard commands, such as the Tab key, or by mouse clicks elsewhere on the page.

For example, consider the HTML:


@@ -34,33 +32,53 @@
 <div id="other">
   Trigger the handler
 </div>
-The event handler can be bound to the first input field:
-$( "#target" ).blur(function() {
-  alert( "Handler for .blur() called." );
-});
+    
+

The event handler can be bound to the first input field:

+

+$( "#target" ).on( "blur", function() {
+  alert( "Handler for `blur` called." );
+} );
     

Now if the first field has the focus, clicking elsewhere or tabbing away from it displays the alert:

- Handler for .blur() called. + Handler for `blur` called.

-

To trigger the event programmatically, apply .blur() without an argument:

+

To trigger the event programmatically, call .trigger( "blur" ):


-$( "#other" ).click(function() {
-  $( "#target" ).blur();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "blur" );
+} );
     

After this code executes, clicks on Trigger the handler will also alert the message.

-

The blur event does not bubble in Internet Explorer. Therefore, scripts that rely on event delegation with the blur event will not work consistently across browsers. As of version 1.4.2, however, jQuery works around this limitation by mapping blur to the focusout event in its event delegation methods, .live() and .delegate().

+

The blur event does not bubble. As of version 1.4.2, jQuery works around this limitation by mapping blur to the focusout event in its event delegation methods.

- To trigger the blur event on all paragraphs: - + +
+ + + blur event + Trigger the "blur" event on an element. + + 1.0 + + The string "blur". + + + +

See the description for .on( "blur", ... ).

+
+ + +
+ +
diff --git a/entries/button-selector.xml b/entries/button-selector.xml index 858522e5..12c8471c 100644 --- a/entries/button-selector.xml +++ b/entries/button-selector.xml @@ -16,9 +16,9 @@ var input = $( ":button" ).addClass( "marked" ); $( "div" ).text( "For this type jQuery found " + input.length + "." ); // Prevent the form from submitting -$( "form" ).submit(function( event ) { +$( "form" ).on( "submit", function( event ) { event.preventDefault(); -}); +} ); ]]>
+ + .change() + Bind an event handler to the "change" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .change( handler ) or .change( eventData, handler ), use .on( "change", handler ) or .on( "change", eventData, handler ), respectively.

+

Instead of .change(), use .trigger( "change" ).

+
+
+ + + + +
diff --git a/entries/change.xml b/entries/change.xml index 67d521d9..e179c506 100644 --- a/entries/change.xml +++ b/entries/change.xml @@ -1,16 +1,15 @@ - - .change() - Bind an event handler to the "change" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "change" event, or trigger that event on an element. + + + change event + Bind an event handler to the "change" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "change". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

This method is a shortcut for .on( "change", handler ) in the first two variations, and .trigger( "change" ) in the third.

+
+

This page describes the change event. For the deprecated .change() method, see .change().

+

The change event is sent to an element when its value changes. This event is limited to <input> elements, <textarea> boxes and <select> elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.

For example, consider the HTML:


@@ -40,35 +38,34 @@
     

The event handler can be bound to the text input and the select box:


-$( ".target" ).change(function() {
-  alert( "Handler for .change() called." );
-});
+$( ".target" ).on( "change", function() {
+  alert( "Handler for `change` called." );
+} );
     
-

Now when the second option is selected from the dropdown, the alert is displayed. It is also displayed if you change the text in the field and then click away. If the field loses focus without the contents having changed, though, the event is not triggered. To trigger the event manually, apply .change() without arguments:

+

Now when the second option is selected from the dropdown, the alert is displayed. It is also displayed if you change the text in the field and then click away. If the field loses focus without the contents having changed, though, the event is not triggered. To trigger the event manually, use .trigger( "change" ):


-$( "#other" ).click(function() {
-  $( ".target" ).change();
-});
+$( "#other" ).on( "click", function() {
+  $( ".target" ).trigger( "change" );
+} );
     

After this code executes, clicks on Trigger the handler will also alert the message. The message will display twice, because the handler has been bound to the change event on both of the form elements.

As of jQuery 1.4, the change event bubbles in Internet Explorer, behaving consistently with the event in other modern browsers.

-

Note: Changing the value of an input element using JavaScript, using .val() for example, won't fire the event.

+

Note: Changing the value of an input element using JavaScript, using .val() for example, won't fire the event.

- Attaches a change event to the select that gets the text for each selected option and writes them in the div. It then triggers the event for the initial text draw. To add a validity test to all text input elements: - + +
+ + + change event + Trigger the "change" event on an element. + + 1.0 + + The string "change". + + + +

See the description for .on( "change", ... ).

+
+ +
+ +
diff --git a/entries/checkbox-selector.xml b/entries/checkbox-selector.xml index 843cdaf7..ba0fd815 100644 --- a/entries/checkbox-selector.xml +++ b/entries/checkbox-selector.xml @@ -26,9 +26,9 @@ $( "div" ) .css( "color", "red" ); // Prevent the form from submitting -$( "form" ).submit(function( event ) { +$( "form" ).on( "submit", function( event ) { event.preventDefault(); -}); +} ); ]]>
Find all children of the clicked element. Empty the queue. + + .click() + Bind an event handler to the "click" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .click( handler ) or .click( eventData, handler ), use .on( "click", handler ) or .on( "click", eventData, handler ), respectively.

+

Instead of .click(), use .trigger( "click" ).

+
+
+ + + + +
diff --git a/entries/click.xml b/entries/click.xml index 56475da4..c5f9deb2 100644 --- a/entries/click.xml +++ b/entries/click.xml @@ -1,16 +1,15 @@ - - .click() - Bind an event handler to the "click" JavaScript event, or trigger that event on an element. + + +Bind an event handler to the "click" event, or trigger that event on an element. + + click event + Bind an event handler to the "click" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "click". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,12 +18,11 @@ - - 1.0 - -

This method is a shortcut for .on( "click", handler ) in the first two variations, and .trigger( "click" ) in the third. - The click event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed and released. Any HTML element can receive this event. +

+

This page describes the click event. For the deprecated .click() method, see .click().

+
+

The click event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed and released. Any HTML element can receive this event. For example, consider the HTML:


 <div id="target">
@@ -40,19 +38,19 @@
     
     

The event handler can be bound to any <div>:


-$( "#target" ).click(function() {
-  alert( "Handler for .click() called." );
-});
+$( "#target" ).on( "click", function() {
+  alert( "Handler for `click` called." );
+} );
     

Now if we click on this element, the alert is displayed:

- Handler for .click() called. + Handler for `click` called.

We can also trigger the event when a different element is clicked:


-$( "#other" ).click(function() {
-  $( "#target" ).click();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "click" );
+} );
     

After this code executes, clicking on Trigger the handler will also alert the message.

The click event is only triggered after this exact series of events:

@@ -62,13 +60,12 @@ $( "#other" ).click(function() {

This is usually the desired sequence before taking an action. If this is not required, the mousedown or mouseup event may be more suitable.

- Hide paragraphs on a page when they are clicked: - Trigger the click event on all of the paragraphs on the page: + Trigger the click event on all the paragraphs on the page: - + + + + + click event + Trigger the "click" event on an element. + + 1.0 + + The string "click". + + + +

See the description for .on( "click", ... ).

+
+ +
+ + diff --git a/entries/contextmenu-shorthand.xml b/entries/contextmenu-shorthand.xml new file mode 100644 index 00000000..9b1f4873 --- /dev/null +++ b/entries/contextmenu-shorthand.xml @@ -0,0 +1,36 @@ + + + .contextmenu() + Bind an event handler to the "contextmenu" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .contextmenu( handler ) or .contextmenu( eventData, handler ), use .on( "contextmenu", handler ) or .on( "contextmenu", eventData, handler ), respectively.

+

Instead of .contextmenu(), use .trigger( "contextmenu" ).

+
+
+ + + + +
diff --git a/entries/contextmenu.xml b/entries/contextmenu.xml index 9849f7e9..63d9c179 100644 --- a/entries/contextmenu.xml +++ b/entries/contextmenu.xml @@ -1,7 +1,10 @@ - - .contextmenu() - Bind an event handler to the "contextmenu" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "contextmenu" event, or trigger that event on an element. + + + contextmenu event + Bind an event handler to the "contextmenu" event. 1.0 @@ -19,12 +22,11 @@ - - 1.0 - -

This method is a shortcut for .on( "contextmenu", handler ) in the first two variations, and .trigger( "contextmenu" ) in the third. - The contextmenu event is sent to an element when the right button of the mouse is clicked on it, but before the context menu is displayed. In case the context menu key is pressed, the event is triggered on the html element or the currently focused element. Any HTML element can receive this event. +

+

This page describes the contextmenu event. For the deprecated .contextmenu() method, see .contextmenu().

+
+

The contextmenu event is sent to an element when the right button of the mouse is clicked on it, but before the context menu is displayed. In case the context menu key is pressed, the event is triggered on the html element or the currently focused element. Any HTML element can receive this event. For example, consider the HTML:


 <div id="target">
@@ -33,35 +35,34 @@
     

The event handler can be bound to the <div> as follows:


-$( "#target" ).contextmenu(function() {
-  alert( "Handler for .contextmenu() called." );
-});
+$( "#target" ).on( "contextmenu", function() {
+  alert( "Handler for `contextmenu` called." );
+} );
     

Now right-clicking on this element displays the alert:

- Handler for .contextmenu() called. + Handler for `contextmenu` called.

-

To trigger the event manually, call .contextmenu() without an argument:

+

To trigger the event manually, use .trigger( "contextmenu" ):


-$( "#target" ).contextmenu();
+$( "#target" ).trigger( "contextmenu" );
     
- To show a "Hello World!" alert box when the contextmenu event is triggered on a paragraph on the page: Right click to toggle background color. - + +
+ + + contextmenu event + Trigger the "contextmenu" event on an element. + + 1.0 + + The string "contextmenu". + + + +

See the description for .on( "contextmenu", ... ).

+
+ +
+ +
diff --git a/entries/css.xml b/entries/css.xml index 896cd4ca..0ffce808 100644 --- a/entries/css.xml +++ b/entries/css.xml @@ -28,7 +28,7 @@ Get the background color of a clicked div. " + color + "." ); @@ -54,7 +54,7 @@ $( "div" ).click(function() { Get the width, height, text color, and background color of a clicked div. Get the data named "blah" stored at for an element. + + .dblclick() + Bind an event handler to the "dblclick" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .dblclick( handler ) or .dblclick( eventData, handler ), use .on( "dblclick", handler ) or .on( "dblclick", eventData, handler ), respectively.

+

Instead of .dblclick(), use .trigger( "dblclick" ).

+
+
+ + + + +
diff --git a/entries/dblclick.xml b/entries/dblclick.xml index 73833172..9c4cf59a 100644 --- a/entries/dblclick.xml +++ b/entries/dblclick.xml @@ -1,16 +1,15 @@ - - .dblclick() - Bind an event handler to the "dblclick" JavaScript event, or trigger that event on an element. + + +Bind an event handler to the "dblclick" event, or trigger that event on an element. + + dblclick event + Bind an event handler to the "dblclick" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "dblclick". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,12 +18,11 @@ - - 1.0 - -

This method is a shortcut for .on( "dblclick", handler ) in the first two variations, and .trigger( "dblclick" ) in the third. - The dblclick event is sent to an element when the element is double-clicked. Any HTML element can receive this event. +

+

This page describes the dblclick event. For the deprecated .dblclick() method, see .dblclick().

+
+

The dblclick event is sent to an element when the element is double-clicked. Any HTML element can receive this event. For example, consider the HTML:


 <div id="target">
@@ -40,19 +38,19 @@
     
     

The event handler can be bound to any <div>:


-$( "#target" ).dblclick(function() {
-  alert( "Handler for .dblclick() called." );
-});
+$( "#target" ).on( "dblclick", function() {
+  alert( "Handler for `dblclick` called." );
+} );
     

Now double-clicking on this element displays the alert:

- Handler for .dblclick() called. + Handler for `dblclick` called.

-

To trigger the event manually, call .dblclick() without an argument:

+

To trigger the event manually, call .trigger( "dblclick" ):


-$( "#other" ).click(function() {
-  $( "#target" ).dblclick();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "dblclick" );
+} );
     

After this code executes, (single) clicks on Trigger the handler will also alert the message.

The dblclick event is only triggered after this exact series of events:

@@ -65,22 +63,21 @@ $( "#other" ).click(function() {

It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events before the dblclick and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.

- To bind a "Hello World!" alert box to the dblclick event on every paragraph on the page: Double click to toggle background color. - + + + + + dblclick event + Trigger the "dblclick" event on an element. + + 1.0 + + The string "dblclick". + + + +

See the description for .on( "dblclick", ... ).

+
+ +
+ + diff --git a/entries/delay.xml b/entries/delay.xml index c94b2a0b..2f996d78 100644 --- a/entries/delay.xml +++ b/entries/delay.xml @@ -44,7 +44,7 @@ $( "#foo" ).slideUp( 300 ).delay( 800 ).fadeIn( 400 ); } ]]>
diff --git a/entries/dequeue.xml b/entries/dequeue.xml index 7caca4e3..24f89c3a 100644 --- a/entries/dequeue.xml +++ b/entries/dequeue.xml @@ -14,7 +14,7 @@ Use dequeue to end a custom queue function which allows the queue to keep going. Detach all paragraphs from the DOM Iterate over three divs and sets their color property. To access a jQuery object instead of the regular DOM element, use $( this ). For example: (click here to change) Use return false to break out of each() loops early. Removes all child nodes (including text nodes) from all paragraphs + + .error() + Bind an event handler to the "error" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API has been removed in jQuery 3.0.

+

Instead of .error( handler ) or .error( eventData, handler ), use .on( "error", handler ) or .on( "error", eventData, handler ), respectively.

+

Instead of .error(), use .trigger( "error" ).

+
+
+ + + + + +
diff --git a/entries/error.xml b/entries/error.xml index 47d9e0e9..d1f9493e 100644 --- a/entries/error.xml +++ b/entries/error.xml @@ -1,16 +1,15 @@ - - .error() - Bind an event handler to the "error" JavaScript event. + +Bind an event handler to the "error" event, or trigger that event on an element. + + + error event + Bind an event handler to the "error" event. - 1.0 - - A function to execute when the event is triggered. - + 1.7 + + The string "error". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -21,7 +20,7 @@
-

Note: This API has been removed in jQuery 3.0; please use .on( "error", handler ) instead of .error( handler ) and .trigger( "error" ) instead of .error().

+

This page describes the error event. For the .error() method removed in jQuery 3.0, see .error().

The error event is sent to elements, such as images, that are referenced by a document and loaded by the browser. It is called if the element was not loaded correctly.

For example, consider a page with a simple image element:

@@ -31,35 +30,50 @@

The event handler can be bound to the image:


 $( "#book" )
-  .error(function() {
-    alert( "Handler for .error() called." )
-  })
+  .on( "error", function() {
+    alert( "Handler for `error` called." )
+  } )
   .attr( "src", "missing.png" );
     

If the image cannot be loaded (for example, because it is not present at the supplied URL), the alert is displayed:

- Handler for .error() called. + Handler for `error` called.

The event handler must be attached before the browser fires the error event, which is why the example sets the src attribute after attaching the handler. Also, the error event may not be correctly fired when the page is served locally; error relies on HTTP status codes and will generally not be triggered if the URL uses the file: protocol.

Note: A jQuery error event handler should not be attached to the window object. The browser fires the window's error event when a script error occurs. However, the window error event receives different arguments and has different return value requirements than conventional event handlers. Use window.onerror instead.

- - To replace all the missing images with another, you can update the src attribute inside the callback passed to .error(). Be sure that the replacement image exists; otherwise the error event will be triggered indefinitely. + To replace all the missing images with another, you can update the src attribute inside the error handler. Be sure that the replacement image exists; otherwise the error event will be triggered indefinitely. - - - + +
+ + + error event + Trigger the "error" event on an element. + + 1.0 + + The string "error". + + + +

See the description for .on( "error", ... ).

+
+ +
+ +
diff --git a/entries/event.currentTarget.xml b/entries/event.currentTarget.xml index f70a8626..859cb8d4 100644 --- a/entries/event.currentTarget.xml +++ b/entries/event.currentTarget.xml @@ -14,11 +14,11 @@ Alert that currentTarget matches the `this` keyword. -
\ No newline at end of file + diff --git a/entries/event.isDefaultPrevented.xml b/entries/event.isDefaultPrevented.xml index 676b31f3..d9ada314 100644 --- a/entries/event.isDefaultPrevented.xml +++ b/entries/event.isDefaultPrevented.xml @@ -9,7 +9,7 @@ Checks whether event.preventDefault() was called. " + msg + "" ); } -$( "button" ).click(function( event ) { +$( "button" ).on( "click", function( event ) { immediatePropStopped( event ); event.stopImmediatePropagation(); immediatePropStopped( event ); diff --git a/entries/event.isPropagationStopped.xml b/entries/event.isPropagationStopped.xml index 26a85b76..c6c270b4 100644 --- a/entries/event.isPropagationStopped.xml +++ b/entries/event.isPropagationStopped.xml @@ -21,11 +21,11 @@ function propStopped( event ) { $( "#stop-log" ).append( "
" + msg + "
" ); } -$( "button" ).click(function(event) { +$( "button" ).on( "click", function( event ) { propStopped( event ); event.stopPropagation(); propStopped( event ); -}); +} ); ]]>
click me diff --git a/entries/event.metaKey.xml b/entries/event.metaKey.xml index f27b6e46..0c00d6b9 100644 --- a/entries/event.metaKey.xml +++ b/entries/event.metaKey.xml @@ -26,7 +26,7 @@
]]> diff --git a/entries/event.namespace.xml b/entries/event.namespace.xml index ed661c92..bbebcda4 100644 --- a/entries/event.namespace.xml +++ b/entries/event.namespace.xml @@ -14,7 +14,7 @@ $( "p" ).on( "test.something", function( event ) { alert( event.namespace ); }); -$( "button" ).click(function( event ) { +$( "button" ).on( "click", function( event ) { $( "p" ).trigger( "test.something" ); }); ]]>
diff --git a/entries/event.preventDefault.xml b/entries/event.preventDefault.xml index ac534fcb..82b4e104 100644 --- a/entries/event.preventDefault.xml +++ b/entries/event.preventDefault.xml @@ -11,7 +11,7 @@ Cancel the default action (navigation) of the click. " ) .append( "default " + event.type + " prevented" ) diff --git a/entries/event.relatedTarget.xml b/entries/event.relatedTarget.xml index 97908df7..e4ee9eaf 100644 --- a/entries/event.relatedTarget.xml +++ b/entries/event.relatedTarget.xml @@ -11,9 +11,9 @@ On mouseout of anchors, alert the element type being entered. diff --git a/entries/event.result.xml b/entries/event.result.xml index fa5cd9ad..40bd1872 100644 --- a/entries/event.result.xml +++ b/entries/event.result.xml @@ -11,10 +11,10 @@ Display previous handler's return value diff --git a/entries/event.stopImmediatePropagation.xml b/entries/event.stopImmediatePropagation.xml index e5b53eba..dd86bd7c 100644 --- a/entries/event.stopImmediatePropagation.xml +++ b/entries/event.stopImmediatePropagation.xml @@ -25,14 +25,14 @@ } ]]>
Kill the bubbling on the click event. Display the tag's name on click @@ -40,7 +40,7 @@ function handler( event ) { target.children().toggle(); } } -$( "ul" ).click( handler ).find( "ul" ).hide(); +$( "ul" ).on( "click", handler ).find( "ul" ).hide(); ]]> diff --git a/entries/event.timeStamp.xml b/entries/event.timeStamp.xml index f63b62ce..089997ba 100644 --- a/entries/event.timeStamp.xml +++ b/entries/event.timeStamp.xml @@ -22,7 +22,7 @@ ]]> " ); diff --git a/entries/event.type.xml b/entries/event.type.xml index 8bde7559..a51cc1c8 100644 --- a/entries/event.type.xml +++ b/entries/event.type.xml @@ -9,7 +9,7 @@ On all anchor clicks, alert the event type. diff --git a/entries/fadeIn.xml b/entries/fadeIn.xml index a73fdc06..4af0872f 100644 --- a/entries/fadeIn.xml +++ b/entries/fadeIn.xml @@ -29,7 +29,7 @@ <img id="book" src="book.png" alt="" width="100" height="123"> // With the element initially hidden, we can show it slowly: -$( "#clickme" ).click(function() { +$( "#clickme)" ).on( "click", function() { $( "#book" ).fadeIn( "slow", function() { // Animation complete }); @@ -52,9 +52,9 @@ $( "#clickme" ).click(function() { Animates hidden divs to fade in one by one, completing each animation within 600 milliseconds. Fades a red block in over the text. Once the animation is done, it quickly fades in more text on top.

With the element initially shown, we can hide it slowly:


-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).fadeOut( "slow", function() {
     // Animation complete.
   });
@@ -56,7 +56,7 @@ $( "#clickme" ).click(function() {
   
     Animates all paragraphs to fade out, completing the animation within 600 milliseconds.
     
@@ -76,7 +76,7 @@ $( "p" ).click(function() {
   
     Fades out spans in one section that you click on.
     
     Fades out two divs, one with a "linear" easing and one with the default, "swing," easing.
     " ).text( this.id ).appendTo( "#log" );
   }
@@ -121,7 +121,7 @@ $( "#btn1" ).click(function() {
   $( "#box2" ).fadeOut( 1600, complete );
 });
 
-$( "#btn2" ).click(function() {
+$( "#btn2)" ).on( "click", function() {
   $( "div" ).show();
   $( "#log" ).empty();
 });
diff --git a/entries/fadeTo.xml b/entries/fadeTo.xml
index bb72eed2..b21cda8a 100644
--- a/entries/fadeTo.xml
+++ b/entries/fadeTo.xml
@@ -44,7 +44,7 @@
 </div>
 <img id="book" src="book.png" alt="" width="100" height="123">
 // With the element initially shown, we can dim it slowly:
-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).fadeTo( "slow" , 0.5, function() {
     // Animation complete.
   });
@@ -63,9 +63,9 @@ $( "#clickme" ).click(function() {
   
     Animates first paragraph to fade to an opacity of 0.33 (33%, about one third visible), completing the animation within 600 milliseconds.
     
     
@@ -80,7 +80,7 @@ Compare to this one that won't fade.
   
     Fade div to a random opacity on each click, completing the animation within 200 milliseconds.
     
@@ -131,23 +131,23 @@ $( "p" ).each(function( n ) {
   $( this ).text( $( "p" ).eq( r ).text() );
   $( "p" ).eq( r ).text( tmp );
   $( this ).css( "left", getPos( n ) );
-});
+} );
 $( "div" )
   .each(function( n ) {
     $( this ).css( "left", getPos( n ) );
-  })
+  } )
   .css( "cursor", "pointer" )
-  .click( function() {
+  .on( "click", function() {
     $( this ).fadeTo( 250, 0.25, function() {
       $( this )
         .css( "cursor", "" )
         .prev()
-          .css({
+          .css( {
             "font-weight": "bolder",
             "font-style": "italic"
-          });
-    });
-  });
+          } );
+    } );
+  } );
 ]]>
     
     Fades first paragraph in or out, completing the animation within 600 milliseconds and using a linear easing. Fades last paragraph in or out for 200 milliseconds, inserting a "finished" message upon completion. 
     finished" );
-  });
-});
+  } );
+} );
 ]]>
     fadeToggle p1
diff --git a/entries/file-selector.xml b/entries/file-selector.xml
index db9c7b86..c5295eca 100644
--- a/entries/file-selector.xml
+++ b/entries/file-selector.xml
@@ -13,16 +13,16 @@
   
     Finds all file inputs.
     
     
+
+  .focus()
+  Bind an event handler to the "focus" event, or trigger that event on an element.
+  
+    1.0
+    
+      A function to execute each time the event is triggered.
+      
+    
+  
+  
+    1.4.3
+    
+      An object containing data that will be passed to the event handler.
+    
+    
+      A function to execute each time the event is triggered.
+      
+    
+  
+  
+    1.0
+  
+  
+    
+

This API is deprecated.

+

Instead of .focus( handler ) or .focus( eventData, handler ), use .on( "focus", handler ) or .on( "focus", eventData, handler ), respectively.

+

Instead of .focus(), use .trigger( "focus" ).

+
+
+ + + + + +
diff --git a/entries/focus.xml b/entries/focus.xml index 1db6b643..21d6b2c2 100644 --- a/entries/focus.xml +++ b/entries/focus.xml @@ -1,16 +1,15 @@ - - .focus() - Bind an event handler to the "focus" JavaScript event, or trigger that event on an element. + + +Bind an event handler to the "focus" event, or trigger that event on an element. + + focus event + Bind an event handler to the "focus" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "focus". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,17 +18,16 @@ - - 1.0 - +
+

This page describes the focus event. For the deprecated .focus() method, see .focus().

+
    -
  • This method is a shortcut for .on( "focus", handler ) in the first and second variations, and .trigger( "focus" ) in the third.
  • The focus event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements, such as form elements (<input>, <select>, etc.) and links (<a href>). In recent browser versions, the event can be extended to include all element types by explicitly setting the element's tabindex property. An element can gain focus via keyboard commands, such as the Tab key, or by mouse clicks on the element.
  • Elements with focus are usually highlighted in some way by the browser, for example with a dotted line surrounding the element. The focus is used to determine which element is the first to receive keyboard-related events.
-

Attempting to set focus to a hidden element causes an error in Internet Explorer. Take care to only use .focus() on elements that are visible. To run an element's focus event handlers without setting focus to the element, use .triggerHandler( "focus" ) instead of .focus().

+

Attempting to set focus to a hidden element causes an error in Internet Explorer. Take care to only use .trigger( "focus" ) on elements that are visible. To run an element's focus event handlers without setting focus to the element, use .triggerHandler( "focus" ) instead of .trigger( "focus" ).

For example, consider the HTML:


@@ -43,24 +41,23 @@
     

The event handler can be bound to the first input field:


-$( "#target" ).focus(function() {
-  alert( "Handler for .focus() called." );
-});
+$( "#target" ).on( "focus", function() {
+  alert( "Handler for `focus` called." );
+} );
     

Now clicking on the first field, or tabbing to it from another field, displays the alert:

- Handler for .focus() called. + Handler for `focus` called.

We can trigger the event when another element is clicked:


-$( "#other" ).click(function() {
-  $( "#target" ).focus();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "focus" );
+} );
     

After this code executes, clicks on Trigger the handler will also alert the message.

-

The focus event does not bubble in Internet Explorer. Therefore, scripts that rely on event delegation with the focus event will not work consistently across browsers. As of version 1.4.2, however, jQuery works around this limitation by mapping focus to the focusin event in its event delegation methods, .live() and .delegate().

+

The focus event does not bubble. As of version 1.4.2, jQuery works around this limitation by mapping focus to the focusin event in its event delegation methods.

- Fire focus. focus fire

@@ -81,21 +78,40 @@ $( "input" ).focus(function() { To stop people from writing in text input boxes, try: To focus on a login input box with id 'login' on page startup, try: - + +
+ + + focus event + Trigger the "focus" event on an element. + + 1.0 + + The string "focus". + + + +

See the description for .on( "focus", ... ).

+
+ + +
+ +
diff --git a/entries/focusin-shorthand.xml b/entries/focusin-shorthand.xml new file mode 100644 index 00000000..ff8f548e --- /dev/null +++ b/entries/focusin-shorthand.xml @@ -0,0 +1,37 @@ + + + .focusin() + Bind an event handler to the "focusin" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .focusin( handler ) or .focusin( eventData, handler ), use .on( "focusin", handler ) or .on( "focusin", eventData, handler ), respectively.

+

Instead of .focusin(), use .trigger( "focusin" ).

+
+
+ + + + + +
diff --git a/entries/focusin.xml b/entries/focusin.xml index aaff429d..7b5288f6 100644 --- a/entries/focusin.xml +++ b/entries/focusin.xml @@ -1,16 +1,15 @@ - - .focusin() + + +Bind an event handler to the "focusin" event, or trigger that event on an element. + + focusin event Bind an event handler to the "focusin" event. - 1.4 - - A function to execute each time the event is triggered. - + 1.7 + + The string "focusin". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,15 +18,13 @@ - - 1.0 - -

This method is a shortcut for .on( "focusin", handler ) in the first two variations, and .trigger( "focusin" ) in the third.

+
+

This page describes the focusin event. For the deprecated .focusin() method, see .focusin().

+

The focusin event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the focus event in that it supports detecting the focus event on parent elements (in other words, it supports event bubbling).

This event will likely be used together with the focusout event.

- Watch for a focus to occur within the paragraphs on the page. focusin fire

@@ -47,6 +44,27 @@ $( "p" ).focusin(function() {
+ + + +
+ + + focusin event + Trigger the "focusin" event on an element. + + 1.0 + + The string "focusin". + + + +

See the description for .on( "focusin", ... ).

+
+ + + -
+ +
diff --git a/entries/focusout-shorthand.xml b/entries/focusout-shorthand.xml new file mode 100644 index 00000000..6114a08b --- /dev/null +++ b/entries/focusout-shorthand.xml @@ -0,0 +1,37 @@ + + + .focusout() + Bind an event handler to the "focusout" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .focusout( handler ) or .focusout( eventData, handler ), use .on( "focusout", handler ) or .on( "focusout", eventData, handler ), respectively.

+

Instead of .focusout(), use .trigger( "focusout" ).

+
+
+ + + + + +
diff --git a/entries/focusout.xml b/entries/focusout.xml index 6b633c89..7b90cb82 100644 --- a/entries/focusout.xml +++ b/entries/focusout.xml @@ -1,16 +1,15 @@ - - .focusout() - Bind an event handler to the "focusout" JavaScript event. + + +Bind an event handler to the "focusout" event, or trigger that event on an element. + + focusout event + Bind an event handler to the "focusout" event. - 1.4 - - A function to execute each time the event is triggered. - + 1.7 + + The string "focusout". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,15 +18,13 @@ - - 1.0 - -

This method is a shortcut for .on( "focusout", handler ) when passed arguments, and .trigger( "focusout" ) when no arguments are passed.

+
+

This page describes the focusout event. For the deprecated .focusout() method, see .focusout().

+

The focusout event is sent to an element when it, or any element inside of it, loses focus. This is distinct from the blur event in that it supports detecting the loss of focus on descendant elements (in other words, it supports event bubbling).

This event will likely be used together with the focusin event.

- Watch for a loss of focus to occur inside paragraphs and note the difference between the focusout count and the blur count. (The blur count does not change because those events do not bubble.) @@ -68,6 +65,27 @@ $( "p" ) + + + +
+ + + focusout event + Trigger the "focuout" event on an element. + + 1.0 + + The string "focusout". + + + +

See the description for .on( "focusout", ... ).

+
+ + + -
+ +
diff --git a/entries/get.xml b/entries/get.xml index 006d6de5..cb52eb2d 100644 --- a/entries/get.xml +++ b/entries/get.xml @@ -43,7 +43,7 @@ console.log( $( "li" ).get( -1 ) ); Display the tag name of the click element. diff --git a/entries/hide.xml b/entries/hide.xml index b90aed05..53aab56d 100644 --- a/entries/hide.xml +++ b/entries/hide.xml @@ -49,7 +49,7 @@ $( ".target" ).hide();

 // With the element initially shown, we can hide it slowly:
-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).hide( "slow", function() {
     alert( "Animation complete." );
   });
@@ -68,7 +68,7 @@ $( "#clickme" ).click(function() {
     Hides all paragraphs then the link on click.
     
     Animates all shown paragraphs to hide slowly, completing the animation within 600 milliseconds.
     
@@ -101,13 +101,13 @@ $( "button" ).click(function() {
   
     Animates all spans (words in this case) to hide fastly, completing each animation within 200 milliseconds. Once each animation is done, it starts the next one.
     
@@ -134,7 +134,7 @@ $( "#shower" ).click(function() {
 for ( var i = 0; i < 5; i++ ) {
   $( "
" ).appendTo( document.body ); } -$( "div" ).click(function() { +$( "div)" ).on( "click", function() { $( this ).hide( 2000, function() { $( this ).remove(); }); diff --git a/entries/hover.xml b/entries/hover.xml index 2ddab1fa..a924d368 100644 --- a/entries/hover.xml +++ b/entries/hover.xml @@ -1,7 +1,7 @@ Bind one or two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements. - + .hover() Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements. @@ -16,12 +16,15 @@ +
+

This API is deprecated. Use .on( "mouseenter", handlerIn ).on( "mouseleave", handlerOut ) instead.

+

The .hover() method binds handlers for both mouseenter and mouseleave events. You can use it to simply apply behavior to an element during the time the mouse is within the element.

Calling $( selector ).hover( handlerIn, handlerOut ) is shorthand for:


-$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );
+$( selector ).on( "mouseenter", handlerIn ).on( "mouseleave", handlerOut );
       
-

See the discussions for .mouseenter() and .mouseleave() for more details.

+

See the discussions for mouseenter and mouseleave for more details.

To add a special style to list items that are being hovered over, try: @@ -80,8 +83,10 @@ $( "td" ).off( "mouseenter mouseleave" ); +
- + + Bind a single handler to the matched elements, to be executed when the mouse pointer enters or leaves the elements. 1.4 @@ -91,12 +96,15 @@ $( "td" ).off( "mouseenter mouseleave" ); +
+

This API is deprecated. Use .on( "mouseenter mouseleave", handlerInOut ) instead.

+

The .hover() method, when passed a single function, will execute that handler for both mouseenter and mouseleave events. This allows the user to use jQuery's various toggle methods within the handler or to respond differently within the handler depending on the event.type.

Calling $(selector).hover(handlerInOut) is shorthand for:


 $( selector ).on( "mouseenter mouseleave", handlerInOut );
       
-

See the discussions for .mouseenter() and .mouseleave() for more details.

+

See the discussions for mouseenter and mouseleave for more details.

Slide the next sibling LI up or down on hover, and toggle a class. @@ -143,5 +151,6 @@ $( "li" ) +
diff --git a/entries/html.xml b/entries/html.xml index b830c566..4be065f3 100644 --- a/entries/html.xml +++ b/entries/html.xml @@ -29,7 +29,7 @@ $( "div.demo-container" ).html(); Click a paragraph to convert it from html to text. Finds all image inputs. On click, returns the index (zero-based) of that div in the page. *" ); $( "#messages" ).text( "Found " + allInputs.length + " inputs and the form has " + formChildren.length + " children." ); -$( "form" ).submit(function( event ) { +$( "form" ).on( "submit", function( event ) { event.preventDefault(); -}); +} ); ]]>

You can attach a click handler to the <ul> element, and then limit the code to be triggered only when a list item itself, not one of its children, is clicked:


-$( "ul" ).click(function( event ) {
+$( "ul" ).on( "click", function( event ) {
   var target = $( event.target );
   if ( target.is( "li" ) ) {
     target.css( "background-color", "red" );
@@ -63,7 +63,7 @@ $( "ul" ).click(function( event ) {
     

You can attach a click handler to every <li> that evaluates the number of <strong> elements within the clicked <li> at that time like so:


-$( "li" ).click(function() {
+$( "li)" ).on( "click", function() {
   var li = $( this ),
     isWithTwo = li.is(function() {
       return $( "strong", this ).length === 2;
@@ -177,7 +177,7 @@ $( "div" ).text( "isFormParent = " + isFormParent );
     Checks against an existing collection of alternating list elements. Blue, alternating list elements slide up while others turn red.
     An alternate way to achieve the above example using an element rather than a jQuery object. Checks against an existing collection of alternating list elements. Blue, alternating list elements slide up while others turn red.
     By default, Ajax requests are sent using the GET HTTP method. If the POST method is required, the method can be specified by setting a value for the type option. This option affects how the contents of the data option are sent to the server. POST data will always be transmitted to the server using UTF-8 charset, per the W3C XMLHTTPRequest standard.

The data option can contain either a query string of the form key1=value1&key2=value2, or an object of the form {key1: 'value1', key2: 'value2'}. If the latter form is used, the data is converted into a query string using jQuery.param() before it is sent. This processing can be circumvented by setting processData to false. The processing might be undesirable if you wish to send an XML object to the server; in this case, change the contentType option from application/x-www-form-urlencoded to a more appropriate MIME type.

Advanced Options

-

The global option prevents handlers registered using .ajaxSend(), .ajaxError(), and similar methods from firing when this request would trigger them. This can be useful to, for example, suppress a loading indicator that was implemented with .ajaxSend() if the requests are frequent and brief. With cross-domain script and JSONP requests, the global option is automatically set to false. See the descriptions of these methods below for more details.

+

The global option prevents handlers registered for the ajaxSend, ajaxError, and similar events from firing when this request would trigger them. This can be useful to, for example, suppress a loading indicator that was implemented with an ajaxSend handler if the requests are frequent and brief. With cross-domain script and JSONP requests, the global option is automatically set to false. See the descriptions of these methods below for more details.

If the server performs HTTP authentication before providing a response, the user name and password pair can be sent via the username and password options.

Ajax requests are time-limited, so errors can be caught and handled to provide a better user experience. Request timeouts are usually either left at their default or set as a global default using $.ajaxSetup() rather than being overridden for specific requests with the timeout option.

By default, requests are always issued, but the browser may serve results out of its cache. To disallow use of the cached results, set cache to false. To cause the request to report failure if the asset has not been modified since the last request, set ifModified to true.

diff --git a/entries/jQuery.ajaxSetup.xml b/entries/jQuery.ajaxSetup.xml index d175c54a..b0b54447 100644 --- a/entries/jQuery.ajaxSetup.xml +++ b/entries/jQuery.ajaxSetup.xml @@ -26,7 +26,7 @@ $.ajax({ });
-

Note: Global callback functions should be set with their respective global Ajax event handler methods—.ajaxStart(), .ajaxStop(), .ajaxComplete(), .ajaxError(), .ajaxSuccess(), .ajaxSend()—rather than within the options object for $.ajaxSetup().

+

Note: Global callback functions should be set via .on() with their respective global Ajax events—ajaxStart, ajaxStop, ajaxComplete, ajaxError, ajaxSuccess, ajaxSend—rather than within the options object for $.ajaxSetup().

diff --git a/entries/jQuery.data.xml b/entries/jQuery.data.xml index 8e275146..5207c8b8 100644 --- a/entries/jQuery.data.xml +++ b/entries/jQuery.data.xml @@ -92,7 +92,7 @@ alert( jQuery.data( document.body ) ); Get the data named "blah" stored at for an element. Use jQuery.dequeue() to end a custom queue function which allows the queue to keep going. Cause all animations to run with less frames. diff --git a/entries/jQuery.fx.off.xml b/entries/jQuery.fx.off.xml index 74bfd60a..3c93466d 100644 --- a/entries/jQuery.fx.off.xml +++ b/entries/jQuery.fx.off.xml @@ -20,10 +20,10 @@ var toggleFx = function() { $.fx.off = !$.fx.off; }; toggleFx(); -$( "button" ).click( toggleFx ); -$( "input" ).click(function() { +$( "button" ).on( "click", toggleFx ); +$( "input)" ).on( "click", function() { $( "div" ).toggle( "slow" ); -}); +} ); ]]>
-

Prior to jQuery 1.5, the global .ajaxError() callback event had to be used in order to handle $.getScript() errors:

+

Prior to jQuery 1.5, the global ajaxError callback event had to be used in order to handle $.getScript() errors:


-$( "div.log" ).ajaxError(function( e, jqxhr, settings, exception ) {
+$( "div.log" ).on( "ajaxError", function( e, jqxhr, settings, exception ) {
   if ( settings.dataType == "script" ) {
     $( this ).text( "Triggered ajaxError handler." );
   }
-});
+} );
     

Prior to jQuery 3.5.0, unsuccessful HTTP responses with a script Content-Type were still executed.

Caching Responses

@@ -94,7 +94,7 @@ $.cachedScript( "ajax/test.js" ).done(function( script, textStatus ) { Post a form using Ajax and put results in a div diff --git a/entries/jQuery.queue.xml b/entries/jQuery.queue.xml index b15912ab..8f3a093f 100644 --- a/entries/jQuery.queue.xml +++ b/entries/jQuery.queue.xml @@ -19,7 +19,7 @@ Show the length of the queue. Queue a custom function. Set a queue array to delete the queue. Selector Context

By default, selectors perform their searches within the DOM starting at the document root. However, an alternate context can be given for the search by using the optional second parameter to the $() function. For example, to do a search within an event handler, the search can be restricted like so:


-$( "div.foo" ).click(function() {
+$( "div.foo)" ).on( "click", function() {
   $( "span", this ).addClass( "bar" );
 });
       
@@ -62,7 +62,7 @@ $( "div.foo" ).click(function() {

Please note that although you can pass text nodes and comment nodes into a jQuery collection this way, most operations don't support them. The few that do will have an explicit note on their API documentation page.

A common use of single-DOM-element construction is to call jQuery methods on an element that has been passed to a callback function through the keyword this:


-$( "div.foo" ).click(function() {
+$( "div.foo)" ).on( "click", function() {
   $( this ).slideUp();
 });
       
diff --git a/entries/keydown-shorthand.xml b/entries/keydown-shorthand.xml new file mode 100644 index 00000000..98b125b3 --- /dev/null +++ b/entries/keydown-shorthand.xml @@ -0,0 +1,36 @@ + + + .keydown() + Bind an event handler to the "keydown" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .keydown( handler ) or .keydown( eventData, handler ), use .on( "keydown", handler ) or .on( "keydown", eventData, handler ), respectively.

+

Instead of .keydown(), use .trigger( "keydown" ).

+
+
+ + + + +
diff --git a/entries/keydown.xml b/entries/keydown.xml index f21ae4e0..576a1ad0 100644 --- a/entries/keydown.xml +++ b/entries/keydown.xml @@ -1,15 +1,15 @@ - - .keydown() + +Bind an event handler to the "keydown" event, or trigger that event on an element. + + + keydown event + Bind an event handler to the "keydown" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "keydown". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -18,12 +18,10 @@ - - 1.0 - - Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element. -

This method is a shortcut for .on( "keydown", handler ) in the first and second variations, and .trigger( "keydown" ) in the third.

+
+

This page describes the keydown event. For the deprecated .keydown() method, see .keydown().

+

The keydown event is sent to an element when the user presses a key on the keyboard. If the key is kept pressed, the event is sent every time the operating system repeats the key. It can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form elements can always get focus so are reasonable candidates for this event type.

For example, consider the HTML:


@@ -36,42 +34,41 @@
     

The event handler can be bound to the input field:


-$( "#target" ).keydown(function() {
-  alert( "Handler for .keydown() called." );
-});
+$( "#target" ).on( "keydown", function() {
+  alert( "Handler for `keydown` called." );
+} );
     

Now when the insertion point is inside the field, pressing a key displays the alert:

- Handler for .keydown() called. + Handler for `keydown` called.

-

To trigger the event manually, apply .keydown() without an argument:

+

To trigger the event manually, use .trigger( "keydown" ):


-$( "#other" ).click(function() {
-  $( "#target" ).keydown();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "keydown" );
+} );
     

After this code executes, clicks on Trigger the handler will also alert the message.

If key presses anywhere need to be caught (for example, to implement global shortcut keys on a page), it is useful to attach this behavior to the document object. Because of event bubbling, all key presses will make their way up the DOM to the document object unless explicitly stopped.

To determine which key was pressed, examine the event object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the .which property so you can reliably use it to retrieve the key code. This code corresponds to a key on the keyboard, including codes for special keys such as arrows. For catching actual text entry, .keypress() may be a better choice.

- Show the event object for the keydown handler when a key is pressed in the input. - +
+ + + keydown event + Trigger the "keydown" event on an element. + + 1.0 + + The string "keydown". + + + +

See the description for .on( "keydown", ... ).

+
+ + +
+ +
diff --git a/entries/keypress-shorthand.xml b/entries/keypress-shorthand.xml new file mode 100644 index 00000000..56a0d1d8 --- /dev/null +++ b/entries/keypress-shorthand.xml @@ -0,0 +1,36 @@ + + + .keypress() + Bind an event handler to the "keypress" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .keypress( handler ) or .keypress( eventData, handler ), use .on( "keypress", handler ) or .on( "keypress", eventData, handler ), respectively.

+

Instead of .keypress(), use .trigger( "keypress" ).

+
+
+ + + + +
diff --git a/entries/keypress.xml b/entries/keypress.xml index 0fd28cf3..16cf4303 100644 --- a/entries/keypress.xml +++ b/entries/keypress.xml @@ -1,16 +1,15 @@ - - .keypress() - Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "keypress" event, or trigger that event on an element. + + + keypress event + Bind an event handler to the "keypress" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "keyup". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,12 +18,11 @@ - - 1.0 - +
+

This page describes the keypress event. For the deprecated .keypress() method, see .keypress().

+

Note: as the keypress event isn't covered by any official specification, the actual behavior encountered when using it may differ across browsers, browser versions, and platforms.

-

This method is a shortcut for .on( "keypress", handler ) in the first two variations, and .trigger( "keypress" ) in the third.

The keypress event is sent to an element when the browser registers keyboard input. This is similar to the keydown event, except that modifier and non-printing keys such as Shift, Esc, and delete trigger keydown events but not keypress events. Other differences between the two events may arise depending on platform and browser.

A keypress event handler can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form controls can always get focus so are reasonable candidates for this event type.

For example, consider the HTML:

@@ -40,43 +38,42 @@

The event handler can be bound to the input field:


-$( "#target" ).keypress(function() {
-  console.log( "Handler for .keypress() called." );
-});
+$( "#target" ).on( "keypress", function() {
+  console.log( "Handler for `keypress` called." );
+} );
     

Now when the insertion point is inside the field, pressing a key displays the log:

- Handler for .keypress() called. + Handler for `keypress` called.

-

To trigger the event manually, apply .keypress() without an argument:

+

To trigger the event manually, use .trigger( "keypress" ):


-$( "#other" ).click(function() {
-  $( "#target" ).keypress();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "keypress" );
+} );
     

After this code executes, clicks on the Trigger the handler div will also log the message.

If key presses anywhere need to be caught (for example, to implement global shortcut keys on a page), it is useful to attach this behavior to the document object. Because of event bubbling, all key presses will make their way up the DOM to the document object unless explicitly stopped.

To determine which character was entered, examine the event object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the .which property so you can reliably use it to retrieve the character code.

Note that keydown and keyup provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup, but as 97 by keypress. An uppercase "A" is reported as 65 by all events. Because of this distinction, when catching special keystrokes such as arrow keys, .keydown() or .keyup() is a better choice.

- Show the event object when a key is pressed in the input. Note: This demo relies on a simple $.print() plugin (https://api.jquery.com/resources/events.js) for the event object's output. - + + + + keyup event + Trigger the "keyup" event on an element. + + 1.0 + + The string "keyup". + + + +

See the description for .on( "keyup", ... ).

+
+ + +
+ + diff --git a/entries/keyup-shorthand.xml b/entries/keyup-shorthand.xml new file mode 100644 index 00000000..965dbeb8 --- /dev/null +++ b/entries/keyup-shorthand.xml @@ -0,0 +1,36 @@ + + + .keyup() + Bind an event handler to the "keyup" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .keyup( handler ) or .keyup( eventData, handler ), use .on( "keyup", handler ) or .on( "keyup", eventData, handler ), respectively.

+

Instead of .keyup(), use .trigger( "keyup" ).

+
+
+ + + + +
diff --git a/entries/keyup.xml b/entries/keyup.xml index 91193b53..b0d6399f 100644 --- a/entries/keyup.xml +++ b/entries/keyup.xml @@ -1,16 +1,15 @@ - - .keyup() - Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "keyup" event, or trigger that event on an element. + + + keyup event + Bind an event handler to the "keyup" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "keyup". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

This method is a shortcut for .on( "keyup", handler ) in the first two variations, and .trigger( "keyup" ) in the third.

+
+

This page describes the keyup event. For the deprecated .keyup() method, see .keyup().

+

The keyup event is sent to an element when the user releases a key on the keyboard. It can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form elements can always get focus so are reasonable candidates for this event type.

For example, consider the HTML:


@@ -36,43 +34,42 @@
     

The event handler can be bound to the input field:


-$( "#target" ).keyup(function() {
-  alert( "Handler for .keyup() called." );
-});
+$( "#target" ).on( "keyup", function() {
+  alert( "Handler for `keyup` called." );
+} );
     

Now when the insertion point is inside the field and a key is pressed and released, the alert is displayed:

- Handler for .keyup() called. + Handler for `keyup` called.

-

To trigger the event manually, apply .keyup() without arguments:

+

To trigger the event manually, use .trigger( "keyup" ):


-$( "#other" ).click(function() {
-  $( "#target" ).keyup();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "keyup" );
+} );
     

After this code executes, clicks on Trigger the handler will also alert the message.

If key presses anywhere need to be caught (for example, to implement global shortcut keys on a page), it is useful to attach this behavior to the document object. Because of event bubbling, all key presses will make their way up the DOM to the document object unless explicitly stopped.

To determine which key was pressed, examine the event object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the .which property so you can reliably use it to retrieve the key code. This code corresponds to a key on the keyboard, including codes for special keys such as arrows. For catching actual text entry, .keypress() may be a better choice.

- Show the event object for the keyup handler (using a simple $.print plugin) when a key is released in the input. - +
+ + + keyup event + Trigger the "keyup" event on an element. + + 1.0 + + The string "keyup". + + + +

See the description for .on( "keyup", ... ).

+
+ + +
+ +
diff --git a/entries/length.xml b/entries/length.xml index 105f23d8..37a2d54c 100644 --- a/entries/length.xml +++ b/entries/length.xml @@ -12,12 +12,12 @@ Count the divs. Click to add more. " ) ); var n = $( "div" ).length; $( "span" ).text( "There are " + n + " divs." + "Click to add more."); - }) + } ) // Trigger the click to start .trigger( "click" ); ]]> diff --git a/entries/live.xml b/entries/live.xml index e88a67ce..26e7a563 100644 --- a/entries/live.xml +++ b/entries/live.xml @@ -104,7 +104,7 @@ $( "p" ).live( "myCustomEvent", function( event, myName, myValue ) { .fadeIn( 30 ) .fadeOut( 1000 ); }); -$( "button" ).click(function() { +$( "button)" ).on( "click", function() { $( "p" ).trigger( "myCustomEvent" ); }); ]]>
diff --git a/entries/load-event.xml b/entries/load-event.xml index b9669cc6..f7dbc65a 100644 --- a/entries/load-event.xml +++ b/entries/load-event.xml @@ -1,16 +1,15 @@ - - .load() - Bind an event handler to the "load" JavaScript event. + +Bind an event handler to the "load" event, or trigger that event on an element. + + + load event + Bind an event handler to the "load" event. - 1.0 - - A function to execute when the event is triggered. - + 1.7 + + The string "load". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -21,9 +20,8 @@
-

Note: This API has been removed in jQuery 3.0; please use .on( "load", handler ) instead of .load( handler ) and .trigger( "load" ) instead of .load().

+

This page describes the load event. For the .load() method removed in jQuery 3.0, see .load().

-

This method is a shortcut for .on( "load", handler ).

The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

For example, consider a page with a simple image:


@@ -31,20 +29,17 @@
     

The event handler can be bound to the image:


-$( "#book" ).load(function() {
-  // Handler for .load() called.
-});
+$( "#book" ).on( "load", function() {
+  // Handler for `load` called.
+} );
     

As soon as the image has been loaded, the handler is called.

In general, it is not necessary to wait for all images to be fully loaded. If code can be executed earlier, it is usually best to place it in a handler sent to the .ready() method.

-
-

The Ajax module also has a method named .load(). Which one is fired depends on the set of arguments passed.

-

Caveats of the load event when used with images -

A common challenge developers attempt to solve using the .load() shortcut is to execute a function when an image (or collection of images) have completely loaded. There are several known caveats with this that should be noted. These are:

+

A common challenge developers attempt to solve using the load shortcut is to execute a function when an image (or collection of images) have completely loaded. There are several known caveats with this that should be noted. These are:

  • It doesn't work consistently nor reliably cross-browser
  • It doesn't fire correctly in WebKit if the image src is set to the same src as before
  • @@ -60,24 +55,40 @@ $( "#book" ).load(function() { Run a function when the page is fully loaded including graphics. Add the class bigImg to all images with height greater than 100 upon each image load. 100) { $( this ).addClass( "bigImg" ); } -}); +} ); ]]> - - - + + + + + load event + Trigger the "load" event on an element. + + 1.0 + + The string "load". + + + +

    See the description for .on( "load", ... ).

    +
    + +
    + + diff --git a/entries/load-shorthand.xml b/entries/load-shorthand.xml new file mode 100644 index 00000000..1c5873cb --- /dev/null +++ b/entries/load-shorthand.xml @@ -0,0 +1,40 @@ + + + .load() + Bind an event handler to the "load" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
    +

    This API has been removed in jQuery 3.0.

    +

    Instead of .load( handler ) or .load( eventData, handler ), use .on( "load", handler ) or .on( "load", eventData, handler ), respectively.

    +

    Instead of .load(), use .trigger( "load" ).

    +
    +
    +

    The Ajax module also has a method named .load(). Which one is fired depends on the set of arguments passed.

    +
    +
    + + + + + +
    diff --git a/entries/map.xml b/entries/map.xml index c151e831..101fa001 100644 --- a/entries/map.xml +++ b/entries/map.xml @@ -135,9 +135,9 @@ $.fn.equalizeHeights = function() { return this.height( Math.max.apply( this, maxHeight ) ); }; -$( "input" ).click(function() { +$( "input" ).on( "click", function() { $( "div" ).equalizeHeights(); -}); +} ); ]]> + + .mousedown() + Bind an event handler to the "mousedown" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
    +

    This API is deprecated.

    +

    Instead of .mousedown( handler ) or .mousedown( eventData, handler ), use .on( "mousedown", handler ) or .on( "mousedown", eventData, handler ), respectively.

    +

    Instead of .mousedown(), use .trigger( "mousedown" ).

    +
    +
    + + + + +
    diff --git a/entries/mousedown.xml b/entries/mousedown.xml index ea8d9a0e..5ce0e273 100644 --- a/entries/mousedown.xml +++ b/entries/mousedown.xml @@ -1,16 +1,15 @@ - - .mousedown() - Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "mousedown" event, or trigger that event on an element. + + + mousedown event + Bind an event handler to the "mousedown" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "mousedown". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

    This method is a shortcut for .on( "mousedown", handler) in the first variation, and .trigger( "mousedown" ) in the second.

    +
    +

    This page describes the mousedown event. For the deprecated .mousedown() method, see .mousedown().

    +

    The mousedown event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed. Any HTML element can receive this event.

    For example, consider the HTML:

    <div id="target">
    @@ -39,36 +37,35 @@
         
         

    The event handler can be bound to any <div>:

    
    -$( "#target" ).mousedown(function() {
    -  alert( "Handler for .mousedown() called." );
    -});
    +$( "#target" ).on( "mousedown", function() {
    +  alert( "Handler for `mousedown` called." );
    +} );
         

    Now if we click on this element, the alert is displayed:

    - Handler for .mousedown() called. + Handler for `mousedown` called.

    We can also trigger the event when a different element is clicked:

    
    -$( "#other" ).click(function() {
    -  $( "#target" ).mousedown();
    -});
    +$( "#other" ).on( "click", function() {
    +  $( "#target" ).trigger( "mousedown" );
    +} );
         

    After this code executes, clicks on Trigger the handler will also alert the message.

    The mousedown event is sent when any mouse button is clicked. To act only on specific buttons, we can use the event object's which property. Not all browsers support this property (Internet Explorer uses button instead), but jQuery normalizes the property so that it is safe to use in any browser. The value of which will be 1 for the left button, 2 for the middle button, or 3 for the right button.

    This event is primarily useful for ensuring that the primary button was used to begin a drag operation; if ignored, strange results can occur when the user attempts to use a context menu. While the middle and right buttons can be detected with these properties, this is not reliable. In Opera and Safari, for example, right mouse button clicks are not detectable by default.

    If the user clicks on an element, drags away from it, and releases the button, this is still counted as a mousedown event. This sequence of actions is treated as a "canceling" of the button press in most user interfaces, so it is usually better to use the click event unless we know that the mousedown event is preferable for a particular situation.

    - Show texts when mouseup and mousedown event triggering. Mouse up." ); - }) - .mousedown(function() { + } ) + .on( "mousedown", function() { $( this ).append( "Mouse down." ); - }); + } ); ]]> Press mouse and release here.

    @@ -76,5 +73,23 @@ $( "p" )
    - + + + + + mousedown event + Trigger the "mousedown" event on an element. + + 1.0 + + The string "mousedown". + + + +

    See the description for .on( "mousedown", ... ).

    +
    + +
    + + diff --git a/entries/mouseenter-shorthand.xml b/entries/mouseenter-shorthand.xml new file mode 100644 index 00000000..49b2285a --- /dev/null +++ b/entries/mouseenter-shorthand.xml @@ -0,0 +1,36 @@ + + + .mouseenter() + Bind an event handler to the "mouseenter" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
    +

    This API is deprecated.

    +

    Instead of .mouseenter( handler ) or .mouseenter( eventData, handler ), use .on( "mouseenter", handler ) or .on( "mouseenter", eventData, handler ), respectively.

    +

    Instead of .mouseenter(), use .trigger( "mouseenter" ).

    +
    +
    + + + + +
    diff --git a/entries/mouseenter.xml b/entries/mouseenter.xml index 08bb0632..d2232926 100644 --- a/entries/mouseenter.xml +++ b/entries/mouseenter.xml @@ -1,16 +1,15 @@ - - .mouseenter() - Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element. + +Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element. + + + mouseenter event + Bind an event handler to be fired when the mouse enters an element. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "mouseenter". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

    This method is a shortcut for .on( "mouseenter", handler ) in the first two variations, and .trigger( "mouseenter" ) in the third.

    +
    +

    This page describes the mouseenter event. For the deprecated .mouseenter() method, see .mouseenter().

    +

    The mouseenter JavaScript event is proprietary to Internet Explorer. Because of the event's general utility, jQuery simulates this event so that it can be used regardless of browser. This event is sent to an element when the mouse pointer enters the element. Any HTML element can receive this event.

    For example, consider the HTML:

    
    @@ -43,20 +41,19 @@
         
         

    The event handler can be bound to any element:

    
    -$( "#outer" ).mouseenter(function() {
    -  $( "#log" ).append( "<div>Handler for .mouseenter() called.</div>" );
    -});
    +$( "#outer" ).on( "mouseenter", function() {
    +  $( "#log" ).append( "<div>Handler for `mouseenter` called.</div>" );
    +} );
         

    Now when the mouse pointer moves over the Outer <div>, the message is appended to <div id="log">. You can also trigger the event when another element is clicked:

    
    -$( "#other" ).click(function() {
    -  $( "#outer" ).mouseenter();
    -});
    +$( "#other" ).on( "click", function() {
    +  $( "#outer" ).trigger( "mouseenter" );
    +} );
         

    After this code executes, clicks on Trigger the handler will also append the message.

    The mouseenter event differs from mouseover in the way it handles event bubbling. If mouseover were used in this example, then when the mouse pointer moved over the Inner element, the handler would be triggered. This is usually undesirable behavior. The mouseenter event, on the other hand, only triggers its handler when the mouse enters the element it is bound to, not a descendant. So in this example, the handler is triggered when the mouse enters the Outer element, but not the Inner element.

    - Show texts when mouseenter and mouseout event triggering. mouseover fires when the pointer moves into the child element as well, while mouseenter fires only when the pointer moves into the bound element. @@ -83,23 +80,23 @@ $( "#other" ).click(function() { @@ -117,5 +114,23 @@ $( "div.enterleave" ) - + + + + mouseenter event + Trigger the "mouseenter" event on an element. + + 1.0 + + The string "mouseenter". + + + +

    See the description for .on( "mouseenter", ... ).

    +
    + + +
    + + diff --git a/entries/mouseleave-shorthand.xml b/entries/mouseleave-shorthand.xml new file mode 100644 index 00000000..9ff235eb --- /dev/null +++ b/entries/mouseleave-shorthand.xml @@ -0,0 +1,36 @@ + + + .mouseleave() + Bind an event handler to the "mouseleave" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
    +

    This API is deprecated.

    +

    Instead of .mouseleave( handler ) or .mouseleave( eventData, handler ), use .on( "mouseleave", handler ) or .on( "mouseleave", eventData, handler ), respectively.

    +

    Instead of .mouseleave(), use .trigger( "mouseleave" ).

    +
    +
    + + + + +
    diff --git a/entries/mouseleave.xml b/entries/mouseleave.xml index 45302078..98c1ff97 100644 --- a/entries/mouseleave.xml +++ b/entries/mouseleave.xml @@ -1,16 +1,15 @@ - - .mouseleave() - Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. + +Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. + + + mouseleave event + Bind an event handler to be fired when the mouse leaves an element. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "mouseleave". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

    This method is a shortcut for .on('mouseleave', handler) in the first two variations, and .trigger('mouseleave') in the third.

    +
    +

    This page describes the mouseleave event. For the deprecated .mouseleave() method, see .mouseleave().

    +

    The mouseleave JavaScript event is proprietary to Internet Explorer. Because of the event's general utility, jQuery simulates this event so that it can be used regardless of browser. This event is sent to an element when the mouse pointer leaves the element. Any HTML element can receive this event.

    For example, consider the HTML:

    
    @@ -43,20 +41,19 @@
         
         

    The event handler can be bound to any element:

    
    -$( "#outer" ).mouseleave(function() {
    -  $( "#log" ).append( "<div>Handler for .mouseleave() called.</div>" );
    -});
    +$( "#outer" ).on( "mouseleave", function() {
    +  $( "#log" ).append( "<div>Handler for `mouseleave` called.</div>" );
    +} );
         

    Now when the mouse pointer moves out of the Outer <div>, the message is appended to <div id="log">. You can also trigger the event when another element is clicked:

    
    -$( "#other" ).click(function() {
    -  $( "#outer" ).mouseleave();
    -});
    +$( "#other" ).on( "click", function() {
    +  $( "#outer" ).trigger( "mouseleave" );
    +} );
         

    After this code executes, clicks on Trigger the handler will also append the message.

    The mouseleave event differs from mouseout in the way it handles event bubbling. If mouseout were used in this example, then when the mouse pointer moved out of the Inner element, the handler would be triggered. This is usually undesirable behavior. The mouseleave event, on the other hand, only triggers its handler when the mouse leaves the element it is bound to, not a descendant. So in this example, the handler is triggered when the mouse leaves the Outer element, but not the Inner element.

    - Show number of times mouseout and mouseleave events are triggered. mouseout fires when the pointer moves out of child element as well, while mouseleave fires only when the pointer moves out of the bound element.
    @@ -115,5 +112,23 @@ $( "div.enterleave" ) - + + + + mouseleave event + Trigger the "mouseleave" event on an element. + + 1.0 + + The string "mouseleave". + + + +

    See the description for .on( "mouseleave", ... ).

    +
    + + +
    + + diff --git a/entries/mousemove-shorthand.xml b/entries/mousemove-shorthand.xml new file mode 100644 index 00000000..7b5e5c31 --- /dev/null +++ b/entries/mousemove-shorthand.xml @@ -0,0 +1,36 @@ + + + .mousemove() + Bind an event handler to the "mousemove" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
    +

    This API is deprecated.

    +

    Instead of .mousemove( handler ) or .mousemove( eventData, handler ), use .on( "mousemove", handler ) or .on( "mousemove", eventData, handler ), respectively.

    +

    Instead of .mousemove(), use .trigger( "mousemove" ).

    +
    +
    + + + + +
    diff --git a/entries/mousemove.xml b/entries/mousemove.xml index f6e33860..5aaeef0b 100644 --- a/entries/mousemove.xml +++ b/entries/mousemove.xml @@ -1,16 +1,15 @@ - - .mousemove() - Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "mousemove" event, or trigger that event on an element. + + + mousemove event + Bind an event handler to the "mousemove" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "mousemove". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

    This method is a shortcut for .on( "mousemove", handler ) in the first two variations, and .trigger( "mousemove" ) in the third.

    +
    +

    This page describes the mousemove event. For the deprecated .mousemove() method, see .mousemove().

    +

    The mousemove event is sent to an element when the mouse pointer moves inside the element. Any HTML element can receive this event.

    For example, consider the HTML:

    
    @@ -37,47 +35,46 @@
         

    The event handler can be bound to the target:

    
    -$( "#target" ).mousemove(function( event ) {
    -  var msg = "Handler for .mousemove() called at ";
    +$( "#target" ).on( "mousemove", function( event ) {
    +  var msg = "Handler for `mousemove` called at ";
       msg += event.pageX + ", " + event.pageY;
       $( "#log" ).append( "<div>" + msg + "</div>" );
    -});
    +} );
         

    Now when the mouse pointer moves within the target button, the messages are appended to <div id="log">:

    - Handler for .mousemove() called at (399, 48) + Handler for `mousemove` called at (399, 48)
    - Handler for .mousemove() called at (398, 46) + Handler for `mousemove` called at (398, 46)
    - Handler for .mousemove() called at (397, 44) + Handler for `mousemove` called at (397, 44)
    - Handler for .mousemove() called at (396, 42) + Handler for `mousemove` called at (396, 42)

    -

    To trigger the event manually, apply .mousemove() without an argument:

    +

    To trigger the event manually, use .trigger( "mousemove" ):

    
    -$( "#other" ).click(function() {
    -  $( "#target" ).mousemove();
    -});
    +$( "#other" ).on( "click", function() {
    +  $( "#target" ).trigger( "mousemove" );
    +} );
         

    After this code executes, clicks on the Trigger button will also append the message:

    - Handler for .mousemove() called at (undefined, undefined) + Handler for `mousemove` called at (undefined, undefined)

    When tracking mouse movement, you usually need to know the actual position of the mouse pointer. The event object that is passed to the handler contains some information about the mouse coordinates. Properties such as .clientX, .offsetX, and .pageX are available, but support for them differs between browsers. Fortunately, jQuery normalizes the .pageX and .pageY properties so that they can be used in all browsers. These properties provide the X and Y coordinates of the mouse pointer relative to the top-left corner of the document, as illustrated in the example output above.

    Keep in mind that the mousemove event is triggered whenever the mouse pointer moves, even for a pixel. This means that hundreds of events can be generated over a very small amount of time. If the handler has to do any significant processing, or if multiple handlers for the event exist, this can be a serious performance drain on the browser. It is important, therefore, to optimize mousemove handlers as much as possible, and to unbind them as soon as they are no longer needed.

    A common pattern is to bind the mousemove handler from within a mousedown handler, and to unbind it from a corresponding mouseup handler. If implementing this sequence of events, remember that the mouseup event might be sent to a different HTML element than the mousemove event was. To account for this, the mouseup handler should typically be bound to an element high up in the DOM tree, such as <body>.

    - Show the mouse coordinates when the mouse is moved over the yellow div. Coordinates are relative to the window, which in this case is the iframe. 300 - + +
    + + + mousemove event + Trigger the "mousemove" event on an element. + + 1.0 + + The string "mousemove". + + + +

    See the description for .on( "mousemove", ... ).

    +
    + +
    + +
    diff --git a/entries/mouseout-shorthand.xml b/entries/mouseout-shorthand.xml new file mode 100644 index 00000000..25761ce4 --- /dev/null +++ b/entries/mouseout-shorthand.xml @@ -0,0 +1,36 @@ + + + .mouseout() + Bind an event handler to the "mouseout" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
    +

    This API is deprecated.

    +

    Instead of .mouseout( handler ) or .mouseout( eventData, handler ), use .on( "mouseout", handler ) or .on( "mouseout", eventData, handler ), respectively.

    +

    Instead of .mouseout(), use .trigger( "mouseout" ).

    +
    +
    + + + + +
    diff --git a/entries/mouseout.xml b/entries/mouseout.xml index d95273c5..3b014828 100644 --- a/entries/mouseout.xml +++ b/entries/mouseout.xml @@ -1,16 +1,15 @@ - - .mouseout() - Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "mouseout" event, or trigger that event on an element. + + + mouseout event + Bind an event handler to the "mouseout" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "mouseout". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

    This method is a shortcut for .on( "mouseout", handler ) in the first two variation, and .trigger( "mouseout" ) in the third.

    +
    +

    This page describes the mouseout event. For the deprecated .mouseout() method, see .mouseout().

    +

    The mouseout event is sent to an element when the mouse pointer leaves the element. Any HTML element can receive this event.

    For example, consider the HTML:

    
    @@ -44,20 +42,19 @@
         
         

    The event handler can be bound to any element:

    
    -$( "#outer" ).mouseout(function() {
    -  $( "#log" ).append( "Handler for .mouseout() called." );
    -});
    +$( "#outer" ).on( "mouseout", function() {
    +  $( "#log" ).append( "Handler for `mouseout` called." );
    +} );
         
    -

    Now when the mouse pointer moves out of the Outer <div>, the message is appended to <div id="log">. To trigger the event manually, apply .mouseout() without an argument::

    +

    Now when the mouse pointer moves out of the Outer <div>, the message is appended to <div id="log">. To trigger the event manually, use .trigger( "mouseout" ):

    
    -$( "#other" ).click(function() {
    -  $( "#outer" ).mouseout();
    -});
    +$( "#other" ).on( "click", function() {
    +  $( "#outer" ).trigger( "mouseout" );
    +} );
         

    After this code executes, clicks on Trigger the handler will also append the message.

    This event type can cause many headaches due to event bubbling. For instance, when the mouse pointer moves out of the Inner element in this example, a mouseout event will be sent to that, then trickle up to Outer. This can trigger the bound mouseout handler at inopportune times. See the discussion for .mouseleave() for a useful alternative.

    - Show the number of times mouseout and mouseleave events are triggered. mouseout fires when the pointer moves out of the child element as well, while mouseleave fires only when the pointer moves out of the bound element. @@ -84,23 +81,23 @@ $( "#other" ).click(function() { @@ -118,5 +115,23 @@ $( "div.enterleave" ) - + + + + mouseout event + Trigger the "mouseout" event on an element. + + 1.0 + + The string "mouseout". + + + +

    See the description for .on( "mouseout", ... ).

    +
    + + +
    + + diff --git a/entries/mouseover-shorthand.xml b/entries/mouseover-shorthand.xml new file mode 100644 index 00000000..25bc4c01 --- /dev/null +++ b/entries/mouseover-shorthand.xml @@ -0,0 +1,36 @@ + + + .mouseover() + Bind an event handler to the "mouseover" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
    +

    This API is deprecated.

    +

    Instead of .mouseover( handler ) or .mouseover( eventData, handler ), use .on( "mouseover", handler ) or .on( "mouseover", eventData, handler ), respectively.

    +

    Instead of .mouseover(), use .trigger( "mouseover" ).

    +
    +
    + + + + +
    diff --git a/entries/mouseover.xml b/entries/mouseover.xml index 88ddb981..6897db06 100644 --- a/entries/mouseover.xml +++ b/entries/mouseover.xml @@ -1,16 +1,15 @@ - - .mouseover() - Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "mouseover" event, or trigger that event on an element. + + + mouseover event + Bind an event handler to the "mouseover" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "mouseover". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

    This method is a shortcut for .on( "mouseover", handler ) in the first two variations, and .trigger( "mouseover" ) in the third.

    +
    +

    This page describes the mouseover event. For the deprecated .mouseover() method, see .mouseover().

    +

    The mouseover event is sent to an element when the mouse pointer enters the element. Any HTML element can receive this event.

    For example, consider the HTML:

    
    @@ -44,20 +42,19 @@
         
         

    The event handler can be bound to any element:

    
    -$( "#outer" ).mouseover(function() {
    -  $( "#log" ).append( "<div>Handler for .mouseover() called.</div>" );
    -});
    +$( "#outer" ).on( "mouseover", function() {
    +  $( "#log" ).append( "<div>Handler for `mouseover` called.</div>" );
    +} );
         

    Now when the mouse pointer moves over the Outer <div>, the message is appended to <div id="log">. We can also trigger the event when another element is clicked:

    
    -$( "#other" ).click(function() {
    -  $( "#outer" ).mouseover();
    -});
    +$( "#other" ).on( "click", function() {
    +  $( "#outer" ).trigger( "mouseover" );
    +} );
         

    After this code executes, clicks on Trigger the handler will also append the message.

    This event type can cause many headaches due to event bubbling. For instance, when the mouse pointer moves over the Inner element in this example, a mouseover event will be sent to that, then trickle up to Outer. This can trigger our bound mouseover handler at inopportune times. See the discussion for .mouseenter() for a useful alternative.

    - Show the number of times mouseover and mouseenter events are triggered. mouseover fires when the pointer moves into the child element as well, while mouseenter fires only when the pointer moves into the bound element. @@ -84,23 +81,23 @@ $( "#other" ).click(function() { @@ -118,5 +115,23 @@ $( "div.enterleave" ) - + + + + + mouseover event + Trigger the "mouseover" event on an element. + + 1.0 + + The string "mouseover". + + + +

    See the description for .on( "mouseover", ... ).

    +
    + +
    + + diff --git a/entries/mouseup-shorthand.xml b/entries/mouseup-shorthand.xml new file mode 100644 index 00000000..edbf836c --- /dev/null +++ b/entries/mouseup-shorthand.xml @@ -0,0 +1,36 @@ + + + .mouseup() + Bind an event handler to the "mouseup" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
    +

    This API is deprecated.

    +

    Instead of .mouseup( handler ) or .mouseup( eventData, handler ), use .on( "mouseup", handler ) or .on( "mouseup", eventData, handler ), respectively.

    +

    Instead of .mouseup(), use .trigger( "mouseup" ).

    +
    +
    + + + + +
    diff --git a/entries/mouseup.xml b/entries/mouseup.xml index e18080a6..205c0794 100644 --- a/entries/mouseup.xml +++ b/entries/mouseup.xml @@ -1,16 +1,15 @@ - - .mouseup() - Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "mouseup" event, or trigger that event on an element. + + + mouseup event + Bind an event handler to the "mouseup" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "mouseup". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

    This method is a shortcut for .on('mouseup', handler) in the first variation, and .trigger('mouseup') in the second.

    +
    +

    This page describes the mouseup event. For the deprecated .mouseup() method, see .mouseup().

    +

    The mouseup event is sent to an element when the mouse pointer is over the element, and the mouse button is released. Any HTML element can receive this event.

    For example, consider the HTML:

    
    @@ -40,34 +38,33 @@
         
         

    The event handler can be bound to any <div>:

    
    -$( "#target" ).mouseup(function() {
    -  alert( "Handler for .mouseup() called." );
    -});
    +$( "#target" ).on( "mouseup", function() {
    +  alert( "Handler for `mouseup` called." );
    +} );
         

    Now if we click on this element, the alert is displayed:

    - Handler for .mouseup() called. + Handler for `mouseup` called.

    We can also trigger the event when a different element is clicked:

    
    -$( "#other" ).click(function() {
    -  $( "#target" ).mouseup();
    -});
    +$( "#other" ).on( "click", function() {
    +  $( "#target" ).trigger( "mouseup" );
    +} );
         

    After this code executes, clicks on Trigger the handler will also alert the message.

    If the user clicks outside an element, drags onto it, and releases the button, this is still counted as a mouseup event. This sequence of actions is not treated as a button press in most user interfaces, so it is usually better to use the click event unless we know that the mouseup event is preferable for a particular situation.

    - Show texts when mouseup and mousedown event triggering. Mouse up." ); - }) - .mousedown(function() { + } ) + .on( "mousedown", function() { $( this ).append( "Mouse down." ); - }); + } ); ]]> Press mouse and release here.

    @@ -75,5 +72,23 @@ $( "p" )
    - + + + + + mouseup event + Trigger the "mouseup" event on an element. + + 1.0 + + The string "mouseup". + + + +

    See the description for .on( "mouseup", ... ).

    +
    + +
    + + diff --git a/entries/nth-child-selector.xml b/entries/nth-child-selector.xml index 741052a1..e2994d7d 100644 --- a/entries/nth-child-selector.xml +++ b/entries/nth-child-selector.xml @@ -53,7 +53,7 @@ $( "ul li:nth-child(2)" ).append( " - 2nd!" ); This is a playground to see how the selector works with different strings. Notice that this is different from the even and odd which have no regard for parent and just filter the list of elements to every other one. The :nth-child, however, counts the index of the child to its particular parent. In any case, it's easier to see than explain so... - 2nd to last!" ); This is a playground to see how the selector works with different strings. - 2nd to last!" ); This is a playground to see how the selector works with different strings. Click to see the offset. Attaching many delegated event handlers near the top of the document tree can degrade performance. Each time the event occurs, jQuery must compare all selectors of all attached events of that type to every element in the path from the event target up to the top of the document. For best performance, attach delegated events at a document location as close as possible to the target elements. Avoid excessive use of document or document.body for delegated events on large documents.

    jQuery can process simple selectors of the form tag#id.class very quickly when they are used to filter delegated events. So, "#myForm", "a.external", and "button" are all fast selectors. Delegated events that use more complex selectors, particularly hierarchical ones, can be several times slower--although they are still fast enough for most applications. Hierarchical selectors can often be avoided simply by attaching the handler to a more appropriate point in the document. For example, instead of $( "body" ).on( "click", "#commentForm .addNew", addComment ) use $( "#commentForm" ).on( "click", ".addNew", addComment ).

    Additional notes

    -

    There are shorthand methods for some events such as .click() that can be used to attach or trigger event handlers. For a complete list of shorthand methods, see the events category.

    +

    Some events have dedicated pages, describing specifics of their usage. For a complete list of those events, see the events category.

    Deprecated in jQuery 1.8, removed in 1.9: The name "hover" used as a shorthand for the string "mouseenter mouseleave". It attaches a single event handler for those two events, and the handler must examine event.type to determine whether the event is mouseenter or mouseleave. Do not confuse the "hover" pseudo-event-name with the .hover() method, which accepts one or two functions.

    jQuery's event system requires that a DOM element allow attaching data via a property on the element, so that events can be tracked and delivered. The object, embed, and applet elements cannot attach data, and therefore cannot have jQuery events bound to them.

    The focus and blur events are specified by the W3C to not bubble, but jQuery defines cross-browser focusin and focusout events that do bubble. When focus and blur are used to attach delegated event handlers, jQuery maps the names and delivers them as focusin and focusout respectively. For consistency and clarity, use the bubbling event type names.

    diff --git a/entries/parents.xml b/entries/parents.xml index 403b2393..57b860b4 100644 --- a/entries/parents.xml +++ b/entries/parents.xml @@ -82,7 +82,7 @@ function showParents() { .length; $( "b" ).text( "Unique div parents: " + len ); } -$( "span" ).click(function() { +$( "span)" ).on( "click", function() { $( this ).toggleClass( "selected" ); showParents(); }); diff --git a/entries/password-selector.xml b/entries/password-selector.xml index 8d632b8f..053e0dc2 100644 --- a/entries/password-selector.xml +++ b/entries/password-selector.xml @@ -13,18 +13,18 @@ Finds all password inputs. Display the checked property and attribute of a checkbox as it changes. " + $input.attr( "checked" ) + "
    " + ".prop( \"checked\" ): " + $input.prop( "checked" ) + "
    " + ".is( \":checked\" ): " + $input.is( ":checked" ) + "" ); -}).change(); +} ).trigger( "change" ); ]]>
    Queue a custom function. Set a queue array to delete the queue. " ) .parent() - .css({ + .css( { background: "yellow", border: "3px red solid" - }); + } ); $( "div" ) .text( "For this type jQuery found " + input.length + "." ) .css( "color", "red" ); // Prevent form submission -$( "form" ).submit(function( event ) { +$( "form" ).on( "submit", function( event ) { event.preventDefault(); -}); +} ); ]]> Removes all paragraphs from the DOM Removes all paragraphs that contain "Hello" from the DOM. Analogous to doing $("p").filter(":contains('Hello')").remove(). diff --git a/entries/removeAttr.xml b/entries/removeAttr.xml index 92a92b22..46ce85b2 100644 --- a/entries/removeAttr.xml +++ b/entries/removeAttr.xml @@ -22,7 +22,7 @@ console.log( "onclick property: ", $element[ 0 ].onclick ); On click, replace the button with a div containing the same word. " + $( this ).text() + "
" ); }); ]]> @@ -108,7 +108,7 @@ $( "p" ).replaceWith( "Paragraph. " ); On click, replace each paragraph with a div that is already in the DOM and selected with the $() function. Notice it doesn't clone the object but rather moves it to replace the paragraph. diff --git a/entries/reset-selector.xml b/entries/reset-selector.xml index 301b0e5e..db558608 100644 --- a/entries/reset-selector.xml +++ b/entries/reset-selector.xml @@ -13,18 +13,18 @@ Finds all reset inputs. + + .resize() + Bind an event handler to the "resize" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .resize( handler ) or .resize( eventData, handler ), use .on( "resize", handler ) or .on( "resize", eventData, handler ), respectively.

+

Instead of .resize(), use .trigger( "resize" ).

+
+
+ + + + +
diff --git a/entries/resize.xml b/entries/resize.xml index 3c4f844d..74cc61fe 100644 --- a/entries/resize.xml +++ b/entries/resize.xml @@ -1,16 +1,15 @@ - - .resize() - Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. + + +Bind an event handler to the "resize" event, or trigger that event on an element. + + resize event + Bind an event handler to the "resize" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "resize". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,30 +18,46 @@ - - 1.0 - -

This method is a shortcut for .on('resize', handler) in the first and second variations, and .trigger( "resize" ) in the third.

+
+

This page describes the resize event. For the deprecated .resize() method, see .resize().

+

The resize event is sent to the window element when the size of the browser window changes:


-$( window ).resize(function() {
-  $( "#log" ).append( "<div>Handler for .resize() called.</div>" );
-});
+$( window ).on( "resize", function() {
+  $( "#log" ).append( "<div>Handler for `resize` called.</div>" );
+} );
     

Now whenever the browser window's size is changed, the message is appended to <div id="log"> one or more times, depending on the browser.

Code in a resize handler should never rely on the number of times the handler is called. Depending on implementation, resize events can be sent continuously as the resizing is in progress (the typical behavior in Internet Explorer and WebKit-based browsers such as Safari and Chrome), or only once at the end of the resize operation (the typical behavior in some other browsers such as Opera).

- To see the window width while (or after) it is resized, try: " + $( window ).width() + "" ); -}); +} ); ]]> - + +
+ + + resize event + Trigger the "resize" event on an element. + + 1.0 + + The string "resize". + + + +

See the description for .on( "resize", ... ).

+
+ +
+ +
diff --git a/entries/scroll-shorthand.xml b/entries/scroll-shorthand.xml new file mode 100644 index 00000000..67b7997e --- /dev/null +++ b/entries/scroll-shorthand.xml @@ -0,0 +1,36 @@ + + + .scroll() + Bind an event handler to the "scroll" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .scroll( handler ) or .scroll( eventData, handler ), use .on( "scroll", handler ) or .on( "scroll", eventData, handler ), respectively.

+

Instead of .scroll(), use .trigger( "scroll" ).

+
+
+ + + + +
diff --git a/entries/scroll.xml b/entries/scroll.xml index 8529cb0c..5f46ddfe 100644 --- a/entries/scroll.xml +++ b/entries/scroll.xml @@ -1,16 +1,15 @@ - - .scroll() - Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. + + +Bind an event handler to the "scroll" event, or trigger that event on an element. + + scroll event + Bind an event handler to the "scroll" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "scroll". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

This method is a shortcut for .on( "scroll", handler ) in the first and second variations, and .trigger( "scroll" ) in the third.

+
+

This page describes the scroll event. For the deprecated .scroll() method, see .scroll().

+

The scroll event is sent to an element when the user scrolls to a different place in the element. It applies to window objects, but also to scrollable frames and elements with the overflow CSS property set to scroll (or auto when the element's explicit height or width is less than the height or width of its contents).

For example, consider the HTML:


@@ -41,7 +39,7 @@
   Trigger the handler
 </div>
 <div id="log"></div>
-
+

The style definition is present to make the target element small enough to be scrollable:

@@ -49,33 +47,32 @@

The scroll event handler can be bound to this element:


-$( "#target" ).scroll(function() {
-  $( "#log" ).append( "<div>Handler for .scroll() called.</div>" );
-});
+$( "#target" ).on( "scroll", function() {
+  $( "#log" ).append( "<div>Handler for `scroll` called.</div>" );
+} );
     

Now when the user scrolls the text up or down, one or more messages are appended to <div id="log"></div>:

- Handler for .scroll() called. + Handler for `scroll` called.

-

To trigger the event manually, apply .scroll() without an argument:

+

To trigger the event manually, use .trigger( "scroll" ):


-$( "#other" ).click(function() {
-  $( "#target" ).scroll();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "scroll" );
+} );
     

After this code executes, clicks on Trigger the handler will also append the message.

A scroll event is sent whenever the element's scroll position changes, regardless of the cause. A mouse click or drag on the scroll bar, dragging inside the element, pressing the arrow keys, or using the mouse's scroll wheel could cause this event.

- To do something when your page is scrolled: - + + + + + scroll event + Trigger the "scroll" event on an element. + + 1.0 + + The string "scroll". + + + +

See the description for .on( "scroll", ... ).

+
+ +
+ + diff --git a/entries/select-shorthand.xml b/entries/select-shorthand.xml new file mode 100644 index 00000000..e3fb0227 --- /dev/null +++ b/entries/select-shorthand.xml @@ -0,0 +1,36 @@ + + + .select() + Bind an event handler to the "select" event, or trigger that event on an element. + + 1.0 + + A function to execute each time the event is triggered. + + + + + 1.4.3 + + An object containing data that will be passed to the event handler. + + + A function to execute each time the event is triggered. + + + + + 1.0 + + +
+

This API is deprecated.

+

Instead of .select( handler ) or .select( eventData, handler ), use .on( "select", handler ) or .on( "select", eventData, handler ), respectively.

+

Instead of .select(), use .trigger( "select" ).

+
+
+ + + + +
diff --git a/entries/select.xml b/entries/select.xml index 244cee7c..60573881 100644 --- a/entries/select.xml +++ b/entries/select.xml @@ -1,16 +1,15 @@ - - .select() - Bind an event handler to the "select" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "select" event, or trigger that event on an element. + + + select event + Bind an event handler to the "select" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "select". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

This method is a shortcut for .on( "select", handler ) in the first two variations, and .trigger( "select" ) in the third.

+
+

This page describes the select event. For the deprecated .select() method, see .select().

+

The select event is sent to an element when the user makes a text selection inside it. This event is limited to <input type="text"> fields and <textarea> boxes.

For example, consider the HTML:


@@ -35,32 +33,31 @@
 </div>

The event handler can be bound to the text input:


-$( "#target" ).select(function() {
-  alert( "Handler for .select() called." );
-});
+$( "#target" ).on( "select", function() {
+  alert( "Handler for `select` called." );
+} );
     
-

Now when any portion of the text is selected, the alert is displayed. Merely setting the location of the insertion point will not trigger the event. To trigger the event manually, apply .select() without an argument:

+

Now when any portion of the text is selected, the alert is displayed. Merely setting the location of the insertion point will not trigger the event. To trigger the event manually, use .trigger( "select" ):


-$( "#other").click(function() {
-  $( "#target" ).select();
-});
+$( "#other").on( "click", function() {
+  $( "#target" ).trigger( "select" );
+} );
     

After this code executes, clicks on the Trigger button will also alert the message:

- Handler for .select() called. + Handler for `select` called.

In addition, the default select action on the field will be fired, so the entire text field will be selected.

The method for retrieving the current selected text differs from one browser to another. A number of jQuery plug-ins offer cross-platform solutions.

- To do something when text in input boxes is selected: To trigger the select event on all input elements, try: - + +
+ + + select event + Trigger the "select" event on an element. + + 1.0 + + The string "select". + + + +

See the description for .on( "select", ... ).

+
+ +
+ +
diff --git a/entries/selected-selector.xml b/entries/selected-selector.xml index c96bf422..5eb6cef8 100644 --- a/entries/selected-selector.xml +++ b/entries/selected-selector.xml @@ -14,13 +14,13 @@ Attaches a change event to the select that gets the text for each selected option and writes them in the div. It then triggers the event for the initial text draw. The .serializeArray() method uses the standard W3C rules for successful controls to determine which elements it should include; in particular the element cannot be disabled and must contain a name attribute. No submit button value is serialized since the form was not submitted using a button. Data from file select elements is not serialized. Elements that do not contain a value attribute are represented with the empty string value.

This method can act on a jQuery object that has selected individual form controls, such as <input>, <textarea>, and <select>. However, it is typically easier to select the <form> element itself for serialization:


-$( "form" ).submit(function( event ) {
+$( "form" ).on( "submit", function( event ) {
   console.log( $( this ).serializeArray() );
   event.preventDefault();
-});
+} );
     

This produces the following data structure (provided that the browser supports console.log):


@@ -70,11 +70,11 @@ $( "form" ).submit(function( event ) {
     $( "#results" ).empty();
     jQuery.each( fields, function( i, field ) {
       $( "#results" ).append( field.value + " " );
-    });
+    } );
   }
 
-  $( ":checkbox, :radio" ).click( showValues );
-  $( "select" ).change( showValues );
+  $( ":checkbox, :radio" ).on( "click", showValues );
+  $( "select" ).on( "change", showValues );
   showValues();
 ]]>
     
     Animates all hidden paragraphs to show slowly, completing the animation within 600 milliseconds.
     
@@ -84,13 +84,13 @@ $( "button" ).click(function() {
   
     Show the first div, followed by each next adjacent sibling div in order, with a 200ms animation. Each animation starts when the previous sibling div's animation ends.
     
@@ -120,19 +120,19 @@ function doIt() {
   $( "span,div" ).show( "slow" );
 }
 // Can pass in function name
-$( "button" ).click( doIt );
+$( "button" ).on( "click", doIt );
 
-$( "form" ).submit(function( event ) {
+$( "form" ).on( "submit", function( event ) {
   if ( $( "input" ).val() === "yes" ) {
     $( "p" ).show( 4000, function() {
       $( this ).text( "Ok, DONE! (now showing)" );
-    });
+    } );
   }
   $( "span,div" ).hide( "fast" );
 
   // Prevent form submission
   event.preventDefault();
-});
+} );
 ]]>
     Count the divs.
     " ) );
     var n = $( "div" ).size();
     $( "span" ).text( "There are " + n + " divs. Click to add more." );
-  })
+  } )
 
   // Trigger the click to start
-  .click();
+  .trigger( "click" );
 ]]>
   
   
diff --git a/entries/slice.xml b/entries/slice.xml
index 81d76c98..8f94ce16 100644
--- a/entries/slice.xml
+++ b/entries/slice.xml
@@ -62,7 +62,7 @@ function colorEm() {
     ").css( 'background', 'yellow' );" );
 }
 
-$( "button" ).click( colorEm );
+$( "button" ).on( "click", colorEm );
 ]]>
     

With the element initially hidden, we can show it slowly:


-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).slideDown( "slow", function() {
     // Animation complete.
   });
@@ -54,13 +54,13 @@ $( "#clickme" ).click(function() {
   
     Animates all divs to slide down and show themselves over 600 milliseconds.
     
     
     Animates all inputs to slide down, completing the animation within 1000 milliseconds. Once the animation is done, the input look is changed especially if it is the middle input which gets the focus.
     
     

We will cause .slideToggle() to be called when another element is clicked:


-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).slideToggle( "slow", function() {
     // Animation complete.
   });
@@ -63,7 +63,7 @@ $( "#clickme" ).click(function() {
   
     Animates all paragraphs to slide up or down, completing the animation within 600 milliseconds.
     
@@ -84,7 +84,7 @@ $( "button" ).click(function() {
   
     Animates divs between dividers with a toggle that makes some appear and some disappear.
     

With the element initially shown, we can hide it slowly:


-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).slideUp( "slow", function() {
     // Animation complete.
   });
@@ -54,13 +54,13 @@ $( "#clickme" ).click(function() {
   
     Animates all divs to slide up, completing the animation within 400 milliseconds.
     
     
     Animates the parent paragraph to slide up, completing the animation within 200 milliseconds. Once the animation is done, it displays an alert.
     Click the Go button once to start the animation, then click the STOP button to stop it where it's currently positioned.  Another option is to click several buttons to queue them up and see that stop just kills the currently playing one.
     
diff --git a/entries/submit-selector.xml b/entries/submit-selector.xml
index a4c9aa01..f6c48b8f 100644
--- a/entries/submit-selector.xml
+++ b/entries/submit-selector.xml
@@ -15,25 +15,25 @@
     " + inputEl[ 0 ].nodeName + inputType + "" );
-})
+} );
 ]]>
     
+
+  .submit()
+  Bind an event handler to the "submit" event, or trigger that event on an element.
+  
+    1.0
+    
+      A function to execute each time the event is triggered.
+      
+    
+  
+  
+    1.4.3
+    
+      An object containing data that will be passed to the event handler.
+    
+    
+      A function to execute each time the event is triggered.
+      
+    
+  
+  
+    1.0
+  
+  
+    
+

This API is deprecated.

+

Instead of .submit( handler ) or .submit( eventData, handler ), use .on( "submit", handler ) or .on( "submit", eventData, handler ), respectively.

+

Instead of .submit(), use .trigger( "submit" ).

+
+
+ + + + +
diff --git a/entries/submit.xml b/entries/submit.xml index f4626f5b..42a32ea1 100644 --- a/entries/submit.xml +++ b/entries/submit.xml @@ -1,16 +1,15 @@ - - .submit() - Bind an event handler to the "submit" JavaScript event, or trigger that event on an element. + +Bind an event handler to the "submit" event, or trigger that event on an element. + + + submit event + Bind an event handler to the "submit" event. - 1.0 - - A function to execute each time the event is triggered. - + 1.7 + + The string "submit". - - - 1.4.3 An object containing data that will be passed to the event handler. @@ -19,11 +18,10 @@ - - 1.0 - -

This method is a shortcut for .on( "submit", handler ) in the first variation, and .trigger( "submit" ) in the third.

+
+

This page describes the submit event. For the deprecated .submit() method, see .submit().

+

The submit event is sent to an element when the user is attempting to submit a form. It can only be attached to <form> elements. Forms can be submitted either by clicking an explicit <input type="submit">, <input type="image">, or <button type="submit">, or by pressing Enter when certain form elements have focus.

Depending on the browser, the Enter key may only cause a form submission if the form has exactly one text field, or only when there is a submit button present. The interface should not rely on a particular behavior for this key unless the issue is forced by observing the keypress event for presses of the Enter key.

@@ -39,26 +37,25 @@ </div>

The event handler can be bound to the form:


-$( "#target" ).submit(function( event ) {
-  alert( "Handler for .submit() called." );
+$( "#target" ).on( "submit", function( event ) {
+  alert( "Handler for `submit` called." );
   event.preventDefault();
 });
     

Now when the form is submitted, the message is alerted. This happens prior to the actual submission, so we can cancel the submit action by calling .preventDefault() on the event object or by returning false from our handler. We can trigger the event manually when another element is clicked:


-$( "#other" ).click(function() {
-  $( "#target" ).submit();
-});
+$( "#other" ).on( "click", function() {
+  $( "#target" ).trigger( "submit" );
+} );
     

After this code executes, clicks on Trigger the handler will also display the message. In addition, the default submit action on the form will be fired, so the form will be submitted.

The JavaScript submit event does not bubble in Internet Explorer. However, scripts that rely on event delegation with the submit event will work consistently across browsers as of jQuery 1.4, which has normalized the event's behavior.

- If you'd like to prevent forms from being submitted unless a flag variable is set, try: If you'd like to prevent forms from being submitted unless a flag variable is set, try: To trigger the submit event on the first form on the page, try: - + + + + submit event + Trigger the "submit" event on an element. + + 1.0 + + The string "submit". + + + +

See the description for .on( "submit", ... ).

+
+ + +
+ + diff --git a/entries/text-selector.xml b/entries/text-selector.xml index 9af4dc44..4886c3a5 100644 --- a/entries/text-selector.xml +++ b/entries/text-selector.xml @@ -19,19 +19,19 @@ $( "<input>" ).is( ":text" ); // true Finds all text inputs.

We will cause .toggle() to be called when another element is clicked:


-$( "#clickme" ).click(function() {
+$( "#clickme)" ).on( "click", function() {
   $( "#book" ).toggle( "slow", function() {
     // Animation complete.
   });
@@ -92,9 +92,9 @@ if ( display === true ) {
   
     Toggles all paragraphs.
     
     Toggle
@@ -105,7 +105,7 @@ $( "button" ).click(function() {
   
     Animates all paragraphs to be shown if they are hidden and hidden if they are visible, completing the animation within 600 milliseconds.
     
@@ -126,7 +126,7 @@ $( "button" ).click(function() {
     Shows all paragraphs, then hides them all, back and forth.
     
diff --git a/entries/toggleClass.xml b/entries/toggleClass.xml
index 3ce8196c..fcb8da42 100644
--- a/entries/toggleClass.xml
+++ b/entries/toggleClass.xml
@@ -99,7 +99,7 @@ $( "div.foo" ).toggleClass(function() {
     
       Toggle the class 'highlight' when a paragraph is clicked.
       
@@ -128,15 +128,15 @@ $( "p" ).click(function() {
       Add the "highlight" class to the clicked paragraph on every third click of that paragraph, remove it every first and second click.
       
       
     Clicks to button #2 also trigger a click for button #1.
     To pass arbitrary data to an event:
     
   
diff --git a/entries/triggerHandler.xml b/entries/triggerHandler.xml
index d72516a8..fb2da985 100644
--- a/entries/triggerHandler.xml
+++ b/entries/triggerHandler.xml
@@ -37,15 +37,15 @@
   
     If you called .triggerHandler() on a focus event - the browser's default focus action would not be triggered, only the event handlers bound to the focus event.
     Focused!" ).appendTo( "body" ).fadeOut( 1000 );
-});
+} );
 ]]>
     .trigger( "focus" )
diff --git a/entries/unbind.xml b/entries/unbind.xml
index 8b91e66a..bbec1688 100644
--- a/entries/unbind.xml
+++ b/entries/unbind.xml
@@ -102,12 +102,12 @@ This example is also an illustration of a closure. Since the handler refers to t
 function aClick() {
   $( "div" ).show().fadeOut( "slow" );
 }
-$( "#bind" ).click(function() {
+$( "#bind)" ).on( "click", function() {
   $( "#theone" )
     .bind( "click", aClick )
     .text( "Can Click!" );
 });
-$( "#unbind" ).click(function() {
+$( "#unbind)" ).on( "click", function() {
   $( "#theone" )
     .unbind( "click", aClick )
     .text( "Does nothing..." );
diff --git a/entries/undelegate.xml b/entries/undelegate.xml
index f97e6b01..454e1ef3 100644
--- a/entries/undelegate.xml
+++ b/entries/undelegate.xml
@@ -52,12 +52,12 @@
 function aClick() {
   $( "div" ).show().fadeOut( "slow" );
 }
-$( "#bind" ).click(function() {
+$( "#bind)" ).on( "click", function() {
   $( "body" )
     .delegate( "#theone", "click", aClick )
     .find( "#theone" ).text( "Can Click!" );
 });
-$( "#unbind" ).click(function() {
+$( "#unbind)" ).on( "click", function() {
   $( "body" )
     .undelegate( "#theone", "click", aClick )
     .find( "#theone" ).text( "Does nothing..." );
diff --git a/entries/unload-shorthand.xml b/entries/unload-shorthand.xml
new file mode 100644
index 00000000..693768ec
--- /dev/null
+++ b/entries/unload-shorthand.xml
@@ -0,0 +1,37 @@
+
+
+  .unload()
+  Bind an event handler to the "unload" event, or trigger that event on an element.
+  
+    1.0
+    
+      A function to execute each time the event is triggered.
+      
+    
+  
+  
+    1.4.3
+    
+      An object containing data that will be passed to the event handler.
+    
+    
+      A function to execute each time the event is triggered.
+      
+    
+  
+  
+    1.0
+  
+  
+    
+

This API has been removed in jQuery 3.0.

+

Instead of .unload( handler ) or .unload( eventData, handler ), use .on( "unload", handler ) or .on( "unload", eventData, handler ), respectively.

+

Instead of .unload(), use .trigger( "unload" ).

+
+
+ + + + + +
diff --git a/entries/unload.xml b/entries/unload.xml index b57d14f4..05d1c27a 100644 --- a/entries/unload.xml +++ b/entries/unload.xml @@ -1,15 +1,15 @@ - - .unload() + +Bind an event handler to the "unload" event, or trigger that event on an element. + + + unload event + Bind an event handler to the "unload" event. - 1.0 - - A function to execute when the event is triggered. - + 1.7 + + The string "unload". - - - 1.4.3 A plain object of data that will be passed to the event handler. @@ -18,36 +18,49 @@ - Bind an event handler to the "unload" JavaScript event.
-

Note: This API has been removed in jQuery 3.0; please use .on( "unload", handler ) instead of .unload( handler ) and .trigger( "unload" ) instead of .unload().

+

This page describes the unload event. For the .unload() method removed in jQuery 3.0, see .unload().

-

This method is a shortcut for .on( "unload", handler ).

The unload event is sent to the window element when the user navigates away from the page. This could mean one of many things. The user could have clicked on a link to leave the page, or typed in a new URL in the address bar. The forward and back buttons will trigger the event. Closing the browser window will cause the event to be triggered. Even a page reload will first create an unload event.

The exact handling of the unload event has varied from version to version of browsers. For example, some versions of Firefox trigger the event when a link is followed, but not when the window is closed. In practical usage, behavior should be tested on all supported browsers and contrasted with the similar beforeunload event.

Any unload event handler should be bound to the window object:


-$( window ).unload(function() {
-  return "Handler for .unload() called.";
-});
+$( window ).on( "unload", function() {
+  return "Handler for `unload` called.";
+} );
     

This event is available so that scripts can perform cleanup when the user leaves the page. Most browsers will ignore calls to alert(), confirm() and prompt() inside the event handler. The string you return may be used in a confirmation dialog, but not all browsers support this. It is not possible to cancel the unload event with .preventDefault().

- To display an alert when a page is unloaded: - - - + +
+ + + unload event + Trigger the "unload" event on an element. + + 1.0 + + The string "unload". + + + +

See the description for .on( "unload", ... ).

+
+ +
+ +
diff --git a/entries/unwrap.xml b/entries/unwrap.xml index ff6d6100..1ba959aa 100644 --- a/entries/unwrap.xml +++ b/entries/unwrap.xml @@ -18,7 +18,7 @@ Wrap/unwrap a div around each of the paragraphs. Multiple: " + multipleValues.join( ", " ) ); } -$( "select" ).change( displayVals ); +$( "select" ).on( "change", displayVals ); displayVals(); ]]> Find the value of an input box. Set the value of an input box. Make all visible divs turn yellow on click. - If a request with returns an error code, it will fail silently unless the script has also called the global .ajaxError() method. Alternatively, as of jQuery 1.5, the .error() method of the jqXHR object returned by is also available for error handling. + If a request with returns an error code, it will fail silently unless the script has also called the global ajaxError event. Alternatively, as of jQuery 1.5, the .error() method of the jqXHR object returned by is also available for error handling. - If $.ajax() or $.ajaxSetup() is called with the global option set to false, the method will not fire. + If $.ajax() or $.ajaxSetup() is called with the global option set to false, the event will not fire. If is called on an unordered list (<ul>) and its <li> elements have position (relative, absolute, or fixed), the effect may not work properly in IE6 through at least IE9 unless the <ul> has "layout." To remedy the problem, add the position: relative; and zoom: 1; CSS declarations to the ul. @@ -64,11 +64,8 @@ Using this selector heavily can have performance implications, as it may force the browser to re-render the page before it can determine visibility. Tracking the visibility of elements via other methods, using a class for example, can provide better performance. - - As the .() method is just a shorthand for .on( "", handler ), detaching is possible using .off( "" ). - - As of jQuery 1.9, all the handlers for the jQuery global Ajax events, including those added with the method, must be attached to document. + As of jQuery 1.9, all the handlers for the jQuery global Ajax events, including those added with .on( "", ... ), must be attached to document. jQuery doesn't officially support SVG. Using jQuery methods on SVG documents, unless explicitly documented for that method, might cause unexpected behaviors. Examples of methods that support SVG as of jQuery 3.0 are addClass and removeClass. diff --git a/pages/Types.html b/pages/Types.html index ad8285ae..969d154a 100644 --- a/pages/Types.html +++ b/pages/Types.html @@ -459,7 +459,7 @@

Function

You see a lot of anonymous functions in jQuery code:

$( document ).ready(function() {});
-$( "a" ).click(function() {});
+$( "a)" ).on( "click", function() {});
 $.ajax({
   url: "someurl.php",
   success: function() {}
@@ -490,7 +490,7 @@ 

Context, Call and Apply

$( document ).ready(function() {
   // this refers to window.document
 });
-$( "a" ).click(function() {
+$( "a)" ).on( "click", function() {
   // this refers to an anchor DOM element
 });
 
@@ -554,7 +554,7 @@

Proxy Pattern

Callback

A callback is a plain JavaScript function passed to some method as an argument or option. Some callbacks are just events, called to give the user a chance to react when a certain state is triggered. jQuery's event system uses such callbacks everywhere:

-
$( "body" ).click(function( event ) {
+
$( "body" ).on( "click", function( event ) {
   console.log( "clicked: " + event.target );
 });
 
@@ -562,9 +562,9 @@

Callback

Some callbacks are required to return something, others make that return value optional. To prevent a form submission, a submit event handler can return false:

-
$( "#myform" ).submit(function() {
+
$( "#myform" ).on( "submit", function() {
   return false;
-});
+} );
 

Instead of always returning false, the callback could check fields of the form for validity, and return false only when the form is invalid.