First, Preventdefault and stoppropagation
event. Preventdefault () and event. Stoppropagation () is not a method of jquery, it is the JS itself comes with
event. Introduction to Preventdefault () usage
This method notifies the Web browser not to perform the default action associated with the event (if such an action exists). For example, if the type attribute is "submit", any event handle can be called at any stage of event propagation, and by calling the method, you can prevent the form from being submitted. Note that if the Cancelable property of the Event object is Fasle, there is no default action, or the default action cannot be blocked. In either case, calling the method has no effect.
event. Introduction to Stoppropagation () usage
This method stops the propagation of the event and prevents it from being dispatched to other Document nodes. It can be called at any stage of event propagation. Note that although this method does not prevent other event handles on the same Document node from being called, it can prevent events from being dispatched to other nodes
Ii. some of the less common events of jquery
One
The one () method attaches a single or more event handlers to the selected element and specifies the function to run when the event occurs.
When using the one () method, the event handler function can only be run once per element.
Live
Attaches one or more event handlers to the selected element, and specifies the function to run when these events occur.
The event handlers attached through the live () method apply to the current and future elements of the matching selector (such as new elements created by the script).
Die
Removes all one or more event handlers added to the specified element through the live () method.
Delegate
Adds one or more event handlers for the specified element, which belongs to the child element of the selected element, and specifies the function to run when these events occur.
Event handlers that use the delegate () method apply to current or future elements, such as new elements created by a script.
Triggerhandler
The specified event type that triggers the selected element. However, the browser default action is not performed and event bubbling does not occur.
The Triggerhandler () method is similar to the trigger () method. The difference is that it does not trigger the default behavior of events (such as form submissions), and only affects the first matching element.
Differences compared to the trigger () method
- It does not cause the default behavior of events (such as form submissions)
- . Trigger () will manipulate all the elements that the JQuery object matches, whereas. Triggerhandler () affects only the first matching element.
- Events created by. Triggerhandler () do not bubble in the DOM tree, and nothing happens if the target element does not process them directly.
- The method returns the return value of the event handler instead of the JQuery object, which has a chain of functionality. In addition, if no handlers are fired, this method returns undefined.
The "JAVASCRIPT" event object