Detailed explanation of examples of js stopping bubbling
Jun 24, 2017 pm 02:04 PM
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8 ">
<title>qypt15</title>
<style>
div {
background-color: green;
border: 1px solid;
padding: 50px ;
}
</style>
</head>
<body>
<p>The example demonstrates bubbling when adding different event listeners Different from captured. </p>
<div id="myDiv" onclick="myDiv()">
<p id="myP" onclick="myP()">Click on the paragraph, I am bubble. </p>
</div><br>
<div id="myDiv2" onclick="myDiva()">
<p id="myP2" onclick= "myPa()">Click on the paragraph, I am capturing. </p>
</div>
<script>
function myP(e) {
alert("You clicked on the P element!");
window.event ? window.event.cancelBubble = true : e.stopPropagation();
}
function myDiv() {
alert("You clicked the DIV element!");
}
function myPa() {
alert("You clicked on the P2 element!");
}
function myDiva() {
alert("You clicked on the DIV2 element!");
}
</script>
</body>
</html>
The above is the detailed content of Detailed explanation of examples of js stopping bubbling. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement an online speech recognition system using WebSocket and JavaScript

Recommended: Excellent JS open source face detection and recognition project

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

Simple JavaScript Tutorial: How to Get HTTP Status Code
