Advertisement
avr39ripe

jsEventObjectDemo

Apr 5th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Study</title>
  6.     <style>
  7.         body{
  8.             line-height: 25px;
  9.             font-size: 16px;
  10.         }
  11.  
  12.         form{
  13.             background-color: green;
  14.             width: 200px;
  15.             height: 200px;
  16.             position: relative;
  17.             text-align: center;
  18.         }
  19.  
  20.         div {
  21.             background-color: red;
  22.             top: 45px;
  23.             left: 45px;
  24.             width: 100px;
  25.             height: 100px;
  26.             position: absolute;
  27.         }
  28.  
  29.         p {
  30.             background-color: blue;
  31.             top: 25px;
  32.             left: 25px;
  33.             width: 50px;
  34.             height: 50px;
  35.             position: absolute;
  36.             line-height: 25px;
  37.             margin: 0;
  38.         }
  39.     </style>
  40. </head>
  41. <body>
  42.     <form id="form">
  43.         FORM
  44.         <div id="div">
  45.         DIV
  46.             <p id="p">P</p>
  47.         </div>
  48.     </form>
  49.  
  50.     <script>
  51.         'use strict'
  52.  
  53.         function onClick(event) {
  54.             event.who ? event.who += `${event.currentTarget.id} # ` : event.who = `${event.currentTarget.id} # `;
  55.             //event.who += `${event.currentTarget.id} # `;
  56.             console.log(`Who got event: ${event.who}`);
  57.         }
  58.  
  59.         const form = document.getElementById('form');
  60.         form.addEventListener('click', onClick);
  61.  
  62.         const div = document.getElementById('div');
  63.         div.addEventListener('click', (event) => { event.stopImmediatePropagation(); });
  64.         div.addEventListener('click', onClick);
  65.  
  66.  
  67.         const p = document.getElementById('p');
  68.         p.addEventListener('click', onClick);
  69.     </script>
  70. </body>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement