JS in the AddEventListener in the 3rd parameter

Source: Internet
Author: User

The third parameter in AddEventListener is usecapture, a bool type. When False for Bubbling gets (by the inward), true is the capture mode (by the outside).

    1. <div id="id1" style= "width:200px; height:200px; Position:absolute; top:100px; left:100px; Background-color:blue; Z-index:4 ">
    2. <div id="Id2" style= "width:200px; height:200px; Position:absolute; top:20px; left:70px; Background-color:green; Z-index:1 "></div>
    3. </Div>

      1. document.getelementbyid ( ' Id1 '). AddEventListener ( ' click ',  function ()  {  Console.log ( ' id1 ');}, false);   
      2.   
      3. document.getelementbyid ( ' Id2 '). AddEventListener ( ' click ',  function ()  { console.log ( Span class= "string" > ' Id2 ');}, false); 
      1. document.getElementById ('id1 '). AddEventListener (' click ', function () {Console.log (' id1 ');},   FALSE);
      2. document.getElementById ('id2 '). AddEventListener (' click ', function () {Console.log (' Id2 ');}, FALSE);

When you click a div, the corresponding event is run according to the usecapture parameter.

JS in the AddEventListener in the 3rd parameter

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.