From 03b1cac1f718fea085dc730394d3ff14868b0485 Mon Sep 17 00:00:00 2001
From: phistuck By default, most events bubble up from the original event target to the Similarly, a handler can call Returning When jQuery calls a handler, the If a By default, most events bubble up from the original event target to the Similarly, a handler can call Returning When jQuery calls a handler, the If a In other words, explicitly calling If the first argument contains more than one space-separated event types, the event handler is called once for each event type. The The event object is often unnecessary and the parameter omitted, as sufficient context is usually available when the handler is bound to know exactly what needs to be done when the handler is triggered. However, at times it becomes necessary to gather more information about the user's environment at the time the event was initiated. View the full Event Object. Returning Using the event object in a handler looks like this: Passing and handling event data works the same way as it does for 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 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 After this code executes, clicks on Trigger the handler will also display the message. In addition, the default The JavaScript After this code executes, clicks on Trigger the handler will also alert the message. The document element. At each element along the way, jQuery calls any matching event handlers that have been attached. A handler can prevent the event from bubbling further up the document tree (and thus prevent handlers on those elements from running) by calling event.stopPropagation(). Any other handlers attached on the current element will run however. To prevent that, call event.stopImmediatePropagation(). (Event handlers bound to an element are called in the same order that they were bound.)event.preventDefault() to cancel any default action that the browser may have for this event; for example, the default action on a click event is to follow the link. Not all browser events have default actions, and not all default actions can be canceled. See the W3C Events Specification for details.false from an event handler will automatically call event.stopPropagation() and event.preventDefault(). A false value can also be passed for the handler as a shorthand for function(){ return false; }. So, $( "a.disabled" ).on( "click", false ); attaches an event handler to all links with class "disabled" that prevents them from being followed when they are clicked and also stops the event from bubbling. false from an event handler in jQuery differ from returning false from a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault().this keyword is a reference to the element where the event is being delivered; for directly bound events this is the element where the event was attached and for delegated events this is an element matching selector. (Note that this may not be equal to event.target if the event has bubbled from a descendant element.) To create a jQuery object from the element so that it can be used with jQuery methods, use $( this ).Passing data to the handler
data argument is provided to .on() and is not null or undefined, it is passed to the handler in the event.data property each time an event is triggered. The data argument can be any type, but if a string is used the selector must either be provided or explicitly passed as null so that the data is not mistaken for a selector. Best practice is to use a plain object so that multiple values can be passed as properties.document element. At each element along the way, jQuery calls any matching event handlers that have been attached. A handler can prevent the event from bubbling further up the document tree (and thus prevent handlers on those elements from running) by calling event.stopPropagation(). Any other handlers attached on the current element will run however. To prevent that, call event.stopImmediatePropagation(). (Event handlers bound to an element are called in the same order that they were bound.)event.preventDefault() to cancel any default action that the browser may have for this event; for example, the default action on a click event is to follow the link. Not all browser events have default actions, and not all default actions can be canceled. See the W3C Events Specification for details.false from an event handler will automatically call event.stopPropagation() and event.preventDefault(). A false value can also be passed for the handler as a shorthand for function(){ return false; }. So, $( "a.disabled" ).on( "click", false ); attaches an event handler to all links with class "disabled" that prevents them from being followed when they are clicked and also stops the event from bubbling. false from an event handler in jQuery differ from returning false from a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault().false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault().this keyword is a reference to the element where the event is being delivered; for directly bound events this is the element where the event was attached and for delegated events this is an element matching selector. (Note that this may not be equal to event.target if the event has bubbled from a descendant element.) To create a jQuery object from the element so that it can be used with jQuery methods, use $( this ).Passing data to the handler
data argument is provided to .on() and is not null or undefined, it is passed to the handler in the event.data property each time an event is triggered. The data argument can be any type, but if a string is used the selector must either be provided or explicitly passed as null so that the data is not mistaken for a selector. Best practice is to use a plain object so that multiple values can be passed as properties..off() from within a regularly-bound handler has exactly the same effect.false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault()..live() method supports custom events as well as all JavaScript events that bubble. It also supports certain events that don't bubble, including change, submit, focus and blur.click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup.false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault().handler callback function can also take parameters. When the function is called, the event object will be passed to the first parameter.false from a handler is equivalent to calling both .preventDefault() and .stopPropagation() on the event object.false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault().
-
$( document ).ready(function() {
From 2914e3cf82e8338a7d2e5339789b24aa673a974c Mon Sep 17 00:00:00 2001
From: phistuck .on().false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault().As of jQuery 1.4 the .live() method supports custom events as well as all JavaScript events that bubble. It also supports certain events that don't bubble, including change, submit, focus and blur.
click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup.false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault()..live() method supports custom events as well as all JavaScript events that bubble. It also supports certain events that don't bubble, including change, submit, focus and blur.click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup.false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault()..preventDefault() on the event object or by returning false from our handler. We can trigger the event manually when another element is clicked:.preventDefault() on the event object or by returning false (which will additionally implicitly call .stopPropagation()) from our handler. We can trigger the event manually when another element is clicked:
$( "#other" ).click(function() {
$( "#target" ).submit();
@@ -52,6 +52,7 @@ $( "#other" ).click(function() {
submit action on the form will be fired, so the form will be submitted.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. false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault().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().false from an event handler in jQuery differ from returning false in a native event handler (element.addEventListener("click", function () { return false; })) in that jQuery calls event.preventDefault() and event.stopPropagation() and a native event handler only calls event.preventDefault().