Front End-"learning experience"-Event delegation method

Source: Internet
Author: User

The previous share proposed this event commissioned, today let me elaborate on the next.

Let's take a look at some examples:

<! doctype html> </script> </body> 

Here I give an unordered list, and we want to output a content after clicking on Li.

For most of us, it is possible to register the event directly on Li. But if this Li has thousands of words, that efficiency is conceivable.

The solution, then, is to use the events of the previous story to bubble up. Increase event monitoring on the top of Li's outermost ul. The event bubbles to the outermost layer as soon as you click inside Li.

And all we have to do is to determine which of the objects the object of the event is.

I use the method of judging nodes here, of course, students can also define the class name, with the JQ hasclass () method to determine the target object. In this way our events will be very efficient.

Front End-"learning experience"-Event delegation method

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.