Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Stop Event Propagation Demo</title> <style type="text/css"> div, p, a{ padding: 15px 30px; display: block; border: 2px solid #000; background: #fff; } </style> </head> <body> <div id="wrap">DIV <p class="hint">P <a href="#">A</a> </p> </div> <script> function showAlert(event) { alert("You clicked: "+ this.tagName); event.stopPropagation(); } let elems = document.querySelectorAll("div, p, a"); for(let elem of elems) { elem.addEventListener("click", showAlert); } </script> </body> </html>