Specification and application of Eventtarget in JavaScript __java

Source: Internet
Author: User
Tags event listener
"Eventtarget is a DOM interface implemented by objects, can receive DOM events and have listeners for them."

A eventtarget is an object that can accept DOM events and bind event listeners. The most common eventtarget are DOM element objects, and other objects that are not DOM elements can also be eventtarget, such as document, Window,xmlhttprequest, wait. Method

Eventtarget.addeventlistener ()

Add an event listener for the specified event type on this eventtarget.

Eventtarget.removeeventlistener ()

Remove the event listener from this eventtarget.

Eventtarget.dispatchevent ()

Distributing events for this eventtarget.

Most eventtarget (element, document, and window) can add a time listener function by means of a property on+ event name. /** Please run the following program in the Chrome console (* *;(function () {/** JS deletes the people who are concerned about Sina Weibo by creating click events. * *      var o = document.getelementsbyclassname (' myfollow_list ');      var e = new MouseEvent (' click ', {' View ': window, ' Bubbles ': true});      Array.prototype.slice.call (o). Every (function (a, B, c) {          a.dispatchevent (e);          return true;     });      document.queryselector (' A.w_btn_d:nth-child (4) '). Dispatchevent (e); })(); Reference: 1 https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget
2 http://my.oschina.net/jackin/blog/176517

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.