JQuery event delegate instance analysis and jquery delegate instance analysis

Source: Internet
Author: User

JQuery event delegate instance analysis and jquery delegate instance analysis

Event delegation is mainly implemented by event bubbling. precise understanding of event delegation can help improve code execution efficiency. Let's take a look at a code example:

<! DOCTYPE html> 

In the above Code, the bind () method is used to bind a click event handler function for each td, so that when you click a cell, the text in the cell will be reset. Although this method achieves the desired effect and looks perfect, it is not. If there are many cells, traversing a cell and binding an event handler for each cell will greatly reduce the code performance. If the parent element of a cell listens to an event, you only need to determine whether the DOM element of the initial event is td.

The code is modified as follows:

<! DOCTYPE html> 

The above code implements the same functions, but the efficiency is greatly improved.

Conclusion: The event Delegate means that the event target does not process the event itself, but delegates the processing task to its parent element, ancestor element, or even root element.

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.