AddEventListener and Attchevent in JavaScript

Source: Internet
Author: User

1, AddEventListener

This method is used to add an event handle to the specified element

Browser support is chrome1.0, ie9+, fireFox1.0, opera7.0

The method contains three parameters event, function, Usecapture

Event is specified, no "on" prefix is required

Functions executed when the function is triggered by an event

USECAPTURE Specifies whether the event is executed in the capture or bubbling phase, true indicates that the event is executed during the capture phase, false means execution during the bubbling phase (when the target element defines the same event as the ancestor element, such as a click event, and if the event captures the click event of the ancestor element when the target element is clicked), Trigger the hit event of the target element, while event bubbling will trigger the target element event and then the ancestor element event.

2, Attachevent

Functionality is the same as the AddEventListener method, only available for IE8 and earlier browsers and opera7.0 and earlier versions

The method consists of two parameters event,function

Event is specified, and an "on" prefix is required

Functions executed when the function is triggered by an event

Since IE8 and earlier browsers only support bubbling events and do not support capture, there is no setting for the third parameter

AddEventListener and Attchevent in JavaScript

Related Article

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.