Excerpted from jQuery 1.4.1 Chinese reference:
Event Delegate
The
.live() method works on an element that has not yet been added to the DOM due to the use of event delegation: event handlers bound to ancestor elements can respond to events triggered on descendants. The event handler passed to .live() will not be bound to the element, but will be treated as a special event handler and bound to the root node of the DOM tree. In our example, when a new element is clicked, the following steps occur:
- Generate a click event and pass it to
for processing
- Since there is no event handler directly bound to
, the event bubbles up the DOM tree
- Events continue to bubble up to the root node of the DOM tree, and this special event handler is bound to it by default.
- Execute the special click event handling function bound by .live().
- This event handling function first detects the target of the event object to determine whether it needs to continue. This test is implemented by checking whether $(event.target).closest('.clickme') can find a matching element.
- If a matching element is found, the original event handler is called.
Since the test in step 5 above is only done when the event occurs, elements added at any time can respond to this event
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31